From eef13235ad0188d5d20de81d89da10fd87751bc6 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 15 Feb 2026 23:05:15 +0000 Subject: [PATCH] fix(test): make sessions_spawn e2e harness ordering stable --- ...gents.sessions-spawn.allowlist.e2e.test.ts | 49 ++++++------- ...gents.sessions-spawn.lifecycle.e2e.test.ts | 49 ++++++------- ...subagents.sessions-spawn.model.e2e.test.ts | 70 ++++++++----------- 3 files changed, 75 insertions(+), 93 deletions(-) diff --git a/src/agents/openclaw-tools.subagents.sessions-spawn.allowlist.e2e.test.ts b/src/agents/openclaw-tools.subagents.sessions-spawn.allowlist.e2e.test.ts index a400fb3eac..2e568714b7 100644 --- a/src/agents/openclaw-tools.subagents.sessions-spawn.allowlist.e2e.test.ts +++ b/src/agents/openclaw-tools.subagents.sessions-spawn.allowlist.e2e.test.ts @@ -1,6 +1,5 @@ import { beforeEach, describe, expect, it } from "vitest"; import "./test-helpers/fast-core-tools.js"; -import { createOpenClawTools } from "./openclaw-tools.js"; import { getCallGatewayMock, resetSessionsSpawnConfigOverride, @@ -10,6 +9,19 @@ import { resetSubagentRegistryForTests } from "./subagent-registry.js"; const callGatewayMock = getCallGatewayMock(); +type CreateOpenClawTools = (typeof import("./openclaw-tools.js"))["createOpenClawTools"]; +type CreateOpenClawToolsOpts = Parameters[0]; + +async function getSessionsSpawnTool(opts: CreateOpenClawToolsOpts) { + // Dynamic import: ensure harness mocks are installed before tool modules load. + const { createOpenClawTools } = await import("./openclaw-tools.js"); + const tool = createOpenClawTools(opts).find((candidate) => candidate.name === "sessions_spawn"); + if (!tool) { + throw new Error("missing sessions_spawn tool"); + } + return tool; +} + describe("openclaw-tools: subagents (sessions_spawn allowlist)", () => { beforeEach(() => { resetSessionsSpawnConfigOverride(); @@ -19,13 +31,10 @@ describe("openclaw-tools: subagents (sessions_spawn allowlist)", () => { resetSubagentRegistryForTests(); callGatewayMock.mockReset(); - const tool = createOpenClawTools({ + const tool = await getSessionsSpawnTool({ agentSessionKey: "main", agentChannel: "whatsapp", - }).find((candidate) => candidate.name === "sessions_spawn"); - if (!tool) { - throw new Error("missing sessions_spawn tool"); - } + }); const result = await tool.execute("call6", { task: "do thing", @@ -57,13 +66,10 @@ describe("openclaw-tools: subagents (sessions_spawn allowlist)", () => { }, }); - const tool = createOpenClawTools({ + const tool = await getSessionsSpawnTool({ agentSessionKey: "main", agentChannel: "whatsapp", - }).find((candidate) => candidate.name === "sessions_spawn"); - if (!tool) { - throw new Error("missing sessions_spawn tool"); - } + }); const result = await tool.execute("call9", { task: "do thing", @@ -109,13 +115,10 @@ describe("openclaw-tools: subagents (sessions_spawn allowlist)", () => { return {}; }); - const tool = createOpenClawTools({ + const tool = await getSessionsSpawnTool({ agentSessionKey: "main", agentChannel: "whatsapp", - }).find((candidate) => candidate.name === "sessions_spawn"); - if (!tool) { - throw new Error("missing sessions_spawn tool"); - } + }); const result = await tool.execute("call7", { task: "do thing", @@ -163,13 +166,10 @@ describe("openclaw-tools: subagents (sessions_spawn allowlist)", () => { return {}; }); - const tool = createOpenClawTools({ + const tool = await getSessionsSpawnTool({ agentSessionKey: "main", agentChannel: "whatsapp", - }).find((candidate) => candidate.name === "sessions_spawn"); - if (!tool) { - throw new Error("missing sessions_spawn tool"); - } + }); const result = await tool.execute("call8", { task: "do thing", @@ -217,13 +217,10 @@ describe("openclaw-tools: subagents (sessions_spawn allowlist)", () => { return {}; }); - const tool = createOpenClawTools({ + const tool = await getSessionsSpawnTool({ agentSessionKey: "main", agentChannel: "whatsapp", - }).find((candidate) => candidate.name === "sessions_spawn"); - if (!tool) { - throw new Error("missing sessions_spawn tool"); - } + }); const result = await tool.execute("call10", { task: "do thing", diff --git a/src/agents/openclaw-tools.subagents.sessions-spawn.lifecycle.e2e.test.ts b/src/agents/openclaw-tools.subagents.sessions-spawn.lifecycle.e2e.test.ts index 6dbe106079..e82d4e2dc6 100644 --- a/src/agents/openclaw-tools.subagents.sessions-spawn.lifecycle.e2e.test.ts +++ b/src/agents/openclaw-tools.subagents.sessions-spawn.lifecycle.e2e.test.ts @@ -2,7 +2,6 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; import { emitAgentEvent } from "../infra/agent-events.js"; import "./test-helpers/fast-core-tools.js"; import { sleep } from "../utils.js"; -import { createOpenClawTools } from "./openclaw-tools.js"; import { getCallGatewayMock, resetSessionsSpawnConfigOverride, @@ -18,6 +17,19 @@ vi.mock("./pi-embedded.js", () => ({ const callGatewayMock = getCallGatewayMock(); +type CreateOpenClawTools = (typeof import("./openclaw-tools.js"))["createOpenClawTools"]; +type CreateOpenClawToolsOpts = Parameters[0]; + +async function getSessionsSpawnTool(opts: CreateOpenClawToolsOpts) { + // Dynamic import: ensure harness mocks are installed before tool modules load. + const { createOpenClawTools } = await import("./openclaw-tools.js"); + const tool = createOpenClawTools(opts).find((candidate) => candidate.name === "sessions_spawn"); + if (!tool) { + throw new Error("missing sessions_spawn tool"); + } + return tool; +} + type GatewayRequest = { method?: string; params?: unknown }; type AgentWaitCall = { runId?: string; timeoutMs?: number }; @@ -142,13 +154,10 @@ describe("openclaw-tools: subagents (sessions_spawn lifecycle)", () => { }, }); - const tool = createOpenClawTools({ + const tool = await getSessionsSpawnTool({ agentSessionKey: "main", agentChannel: "whatsapp", - }).find((candidate) => candidate.name === "sessions_spawn"); - if (!tool) { - throw new Error("missing sessions_spawn tool"); - } + }); const result = await tool.execute("call2", { task: "do thing", @@ -220,13 +229,10 @@ describe("openclaw-tools: subagents (sessions_spawn lifecycle)", () => { }, }); - const tool = createOpenClawTools({ + const tool = await getSessionsSpawnTool({ agentSessionKey: "discord:group:req", agentChannel: "discord", - }).find((candidate) => candidate.name === "sessions_spawn"); - if (!tool) { - throw new Error("missing sessions_spawn tool"); - } + }); const result = await tool.execute("call1", { task: "do thing", @@ -314,13 +320,10 @@ describe("openclaw-tools: subagents (sessions_spawn lifecycle)", () => { agentWaitResult: { status: "ok", startedAt: 3000, endedAt: 4000 }, }); - const tool = createOpenClawTools({ + const tool = await getSessionsSpawnTool({ agentSessionKey: "discord:group:req", agentChannel: "discord", - }).find((candidate) => candidate.name === "sessions_spawn"); - if (!tool) { - throw new Error("missing sessions_spawn tool"); - } + }); const result = await tool.execute("call1b", { task: "do thing", @@ -404,13 +407,10 @@ describe("openclaw-tools: subagents (sessions_spawn lifecycle)", () => { return {}; }); - const tool = createOpenClawTools({ + const tool = await getSessionsSpawnTool({ agentSessionKey: "discord:group:req", agentChannel: "discord", - }).find((candidate) => candidate.name === "sessions_spawn"); - if (!tool) { - throw new Error("missing sessions_spawn tool"); - } + }); const result = await tool.execute("call-timeout", { task: "do thing", @@ -474,14 +474,11 @@ describe("openclaw-tools: subagents (sessions_spawn lifecycle)", () => { return {}; }); - const tool = createOpenClawTools({ + const tool = await getSessionsSpawnTool({ agentSessionKey: "main", agentChannel: "whatsapp", agentAccountId: "kev", - }).find((candidate) => candidate.name === "sessions_spawn"); - if (!tool) { - throw new Error("missing sessions_spawn tool"); - } + }); const result = await tool.execute("call-announce-account", { task: "do thing", diff --git a/src/agents/openclaw-tools.subagents.sessions-spawn.model.e2e.test.ts b/src/agents/openclaw-tools.subagents.sessions-spawn.model.e2e.test.ts index 1bbc6d70e5..288f3b4461 100644 --- a/src/agents/openclaw-tools.subagents.sessions-spawn.model.e2e.test.ts +++ b/src/agents/openclaw-tools.subagents.sessions-spawn.model.e2e.test.ts @@ -1,7 +1,6 @@ import { beforeEach, describe, expect, it } from "vitest"; import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "./defaults.js"; import "./test-helpers/fast-core-tools.js"; -import { createOpenClawTools } from "./openclaw-tools.js"; import { getCallGatewayMock, resetSessionsSpawnConfigOverride, @@ -11,6 +10,19 @@ import { resetSubagentRegistryForTests } from "./subagent-registry.js"; const callGatewayMock = getCallGatewayMock(); +type CreateOpenClawTools = (typeof import("./openclaw-tools.js"))["createOpenClawTools"]; +type CreateOpenClawToolsOpts = Parameters[0]; + +async function getSessionsSpawnTool(opts: CreateOpenClawToolsOpts) { + // Dynamic import: ensure harness mocks are installed before tool modules load. + const { createOpenClawTools } = await import("./openclaw-tools.js"); + const tool = createOpenClawTools(opts).find((candidate) => candidate.name === "sessions_spawn"); + if (!tool) { + throw new Error("missing sessions_spawn tool"); + } + return tool; +} + describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => { beforeEach(() => { resetSessionsSpawnConfigOverride(); @@ -46,13 +58,10 @@ describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => { return {}; }); - const tool = createOpenClawTools({ + const tool = await getSessionsSpawnTool({ agentSessionKey: "discord:group:req", agentChannel: "discord", - }).find((candidate) => candidate.name === "sessions_spawn"); - if (!tool) { - throw new Error("missing sessions_spawn tool"); - } + }); const result = await tool.execute("call3", { task: "do thing", @@ -93,13 +102,10 @@ describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => { return {}; }); - const tool = createOpenClawTools({ + const tool = await getSessionsSpawnTool({ agentSessionKey: "discord:group:req", agentChannel: "discord", - }).find((candidate) => candidate.name === "sessions_spawn"); - if (!tool) { - throw new Error("missing sessions_spawn tool"); - } + }); const result = await tool.execute("call-thinking", { task: "do thing", @@ -126,13 +132,10 @@ describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => { return {}; }); - const tool = createOpenClawTools({ + const tool = await getSessionsSpawnTool({ agentSessionKey: "discord:group:req", agentChannel: "discord", - }).find((candidate) => candidate.name === "sessions_spawn"); - if (!tool) { - throw new Error("missing sessions_spawn tool"); - } + }); const result = await tool.execute("call-thinking-invalid", { task: "do thing", @@ -166,13 +169,10 @@ describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => { return {}; }); - const tool = createOpenClawTools({ + const tool = await getSessionsSpawnTool({ agentSessionKey: "agent:main:main", agentChannel: "discord", - }).find((candidate) => candidate.name === "sessions_spawn"); - if (!tool) { - throw new Error("missing sessions_spawn tool"); - } + }); const result = await tool.execute("call-default-model", { task: "do thing", @@ -207,13 +207,10 @@ describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => { return {}; }); - const tool = createOpenClawTools({ + const tool = await getSessionsSpawnTool({ agentSessionKey: "agent:main:main", agentChannel: "discord", - }).find((candidate) => candidate.name === "sessions_spawn"); - if (!tool) { - throw new Error("missing sessions_spawn tool"); - } + }); const result = await tool.execute("call-runtime-default-model", { task: "do thing", @@ -255,13 +252,10 @@ describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => { return {}; }); - const tool = createOpenClawTools({ + const tool = await getSessionsSpawnTool({ agentSessionKey: "agent:research:main", agentChannel: "discord", - }).find((candidate) => candidate.name === "sessions_spawn"); - if (!tool) { - throw new Error("missing sessions_spawn tool"); - } + }); const result = await tool.execute("call-agent-model", { task: "do thing", @@ -313,13 +307,10 @@ describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => { return {}; }); - const tool = createOpenClawTools({ + const tool = await getSessionsSpawnTool({ agentSessionKey: "main", agentChannel: "whatsapp", - }).find((candidate) => candidate.name === "sessions_spawn"); - if (!tool) { - throw new Error("missing sessions_spawn tool"); - } + }); const result = await tool.execute("call4", { task: "do thing", @@ -351,13 +342,10 @@ describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => { return {}; }); - const tool = createOpenClawTools({ + const tool = await getSessionsSpawnTool({ agentSessionKey: "main", agentChannel: "whatsapp", - }).find((candidate) => candidate.name === "sessions_spawn"); - if (!tool) { - throw new Error("missing sessions_spawn tool"); - } + }); const result = await tool.execute("call5", { task: "do thing",