mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-29 01:31:18 +00:00
fix(test): make sessions_spawn e2e harness ordering stable
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import { beforeEach, describe, expect, it } from "vitest";
|
import { beforeEach, describe, expect, it } from "vitest";
|
||||||
import "./test-helpers/fast-core-tools.js";
|
import "./test-helpers/fast-core-tools.js";
|
||||||
import { createOpenClawTools } from "./openclaw-tools.js";
|
|
||||||
import {
|
import {
|
||||||
getCallGatewayMock,
|
getCallGatewayMock,
|
||||||
resetSessionsSpawnConfigOverride,
|
resetSessionsSpawnConfigOverride,
|
||||||
@@ -10,6 +9,19 @@ import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
|||||||
|
|
||||||
const callGatewayMock = getCallGatewayMock();
|
const callGatewayMock = getCallGatewayMock();
|
||||||
|
|
||||||
|
type CreateOpenClawTools = (typeof import("./openclaw-tools.js"))["createOpenClawTools"];
|
||||||
|
type CreateOpenClawToolsOpts = Parameters<CreateOpenClawTools>[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)", () => {
|
describe("openclaw-tools: subagents (sessions_spawn allowlist)", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
resetSessionsSpawnConfigOverride();
|
resetSessionsSpawnConfigOverride();
|
||||||
@@ -19,13 +31,10 @@ describe("openclaw-tools: subagents (sessions_spawn allowlist)", () => {
|
|||||||
resetSubagentRegistryForTests();
|
resetSubagentRegistryForTests();
|
||||||
callGatewayMock.mockReset();
|
callGatewayMock.mockReset();
|
||||||
|
|
||||||
const tool = createOpenClawTools({
|
const tool = await getSessionsSpawnTool({
|
||||||
agentSessionKey: "main",
|
agentSessionKey: "main",
|
||||||
agentChannel: "whatsapp",
|
agentChannel: "whatsapp",
|
||||||
}).find((candidate) => candidate.name === "sessions_spawn");
|
});
|
||||||
if (!tool) {
|
|
||||||
throw new Error("missing sessions_spawn tool");
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await tool.execute("call6", {
|
const result = await tool.execute("call6", {
|
||||||
task: "do thing",
|
task: "do thing",
|
||||||
@@ -57,13 +66,10 @@ describe("openclaw-tools: subagents (sessions_spawn allowlist)", () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const tool = createOpenClawTools({
|
const tool = await getSessionsSpawnTool({
|
||||||
agentSessionKey: "main",
|
agentSessionKey: "main",
|
||||||
agentChannel: "whatsapp",
|
agentChannel: "whatsapp",
|
||||||
}).find((candidate) => candidate.name === "sessions_spawn");
|
});
|
||||||
if (!tool) {
|
|
||||||
throw new Error("missing sessions_spawn tool");
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await tool.execute("call9", {
|
const result = await tool.execute("call9", {
|
||||||
task: "do thing",
|
task: "do thing",
|
||||||
@@ -109,13 +115,10 @@ describe("openclaw-tools: subagents (sessions_spawn allowlist)", () => {
|
|||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
const tool = createOpenClawTools({
|
const tool = await getSessionsSpawnTool({
|
||||||
agentSessionKey: "main",
|
agentSessionKey: "main",
|
||||||
agentChannel: "whatsapp",
|
agentChannel: "whatsapp",
|
||||||
}).find((candidate) => candidate.name === "sessions_spawn");
|
});
|
||||||
if (!tool) {
|
|
||||||
throw new Error("missing sessions_spawn tool");
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await tool.execute("call7", {
|
const result = await tool.execute("call7", {
|
||||||
task: "do thing",
|
task: "do thing",
|
||||||
@@ -163,13 +166,10 @@ describe("openclaw-tools: subagents (sessions_spawn allowlist)", () => {
|
|||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
const tool = createOpenClawTools({
|
const tool = await getSessionsSpawnTool({
|
||||||
agentSessionKey: "main",
|
agentSessionKey: "main",
|
||||||
agentChannel: "whatsapp",
|
agentChannel: "whatsapp",
|
||||||
}).find((candidate) => candidate.name === "sessions_spawn");
|
});
|
||||||
if (!tool) {
|
|
||||||
throw new Error("missing sessions_spawn tool");
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await tool.execute("call8", {
|
const result = await tool.execute("call8", {
|
||||||
task: "do thing",
|
task: "do thing",
|
||||||
@@ -217,13 +217,10 @@ describe("openclaw-tools: subagents (sessions_spawn allowlist)", () => {
|
|||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
const tool = createOpenClawTools({
|
const tool = await getSessionsSpawnTool({
|
||||||
agentSessionKey: "main",
|
agentSessionKey: "main",
|
||||||
agentChannel: "whatsapp",
|
agentChannel: "whatsapp",
|
||||||
}).find((candidate) => candidate.name === "sessions_spawn");
|
});
|
||||||
if (!tool) {
|
|
||||||
throw new Error("missing sessions_spawn tool");
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await tool.execute("call10", {
|
const result = await tool.execute("call10", {
|
||||||
task: "do thing",
|
task: "do thing",
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
|||||||
import { emitAgentEvent } from "../infra/agent-events.js";
|
import { emitAgentEvent } from "../infra/agent-events.js";
|
||||||
import "./test-helpers/fast-core-tools.js";
|
import "./test-helpers/fast-core-tools.js";
|
||||||
import { sleep } from "../utils.js";
|
import { sleep } from "../utils.js";
|
||||||
import { createOpenClawTools } from "./openclaw-tools.js";
|
|
||||||
import {
|
import {
|
||||||
getCallGatewayMock,
|
getCallGatewayMock,
|
||||||
resetSessionsSpawnConfigOverride,
|
resetSessionsSpawnConfigOverride,
|
||||||
@@ -18,6 +17,19 @@ vi.mock("./pi-embedded.js", () => ({
|
|||||||
|
|
||||||
const callGatewayMock = getCallGatewayMock();
|
const callGatewayMock = getCallGatewayMock();
|
||||||
|
|
||||||
|
type CreateOpenClawTools = (typeof import("./openclaw-tools.js"))["createOpenClawTools"];
|
||||||
|
type CreateOpenClawToolsOpts = Parameters<CreateOpenClawTools>[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 GatewayRequest = { method?: string; params?: unknown };
|
||||||
type AgentWaitCall = { runId?: string; timeoutMs?: number };
|
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",
|
agentSessionKey: "main",
|
||||||
agentChannel: "whatsapp",
|
agentChannel: "whatsapp",
|
||||||
}).find((candidate) => candidate.name === "sessions_spawn");
|
});
|
||||||
if (!tool) {
|
|
||||||
throw new Error("missing sessions_spawn tool");
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await tool.execute("call2", {
|
const result = await tool.execute("call2", {
|
||||||
task: "do thing",
|
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",
|
agentSessionKey: "discord:group:req",
|
||||||
agentChannel: "discord",
|
agentChannel: "discord",
|
||||||
}).find((candidate) => candidate.name === "sessions_spawn");
|
});
|
||||||
if (!tool) {
|
|
||||||
throw new Error("missing sessions_spawn tool");
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await tool.execute("call1", {
|
const result = await tool.execute("call1", {
|
||||||
task: "do thing",
|
task: "do thing",
|
||||||
@@ -314,13 +320,10 @@ describe("openclaw-tools: subagents (sessions_spawn lifecycle)", () => {
|
|||||||
agentWaitResult: { status: "ok", startedAt: 3000, endedAt: 4000 },
|
agentWaitResult: { status: "ok", startedAt: 3000, endedAt: 4000 },
|
||||||
});
|
});
|
||||||
|
|
||||||
const tool = createOpenClawTools({
|
const tool = await getSessionsSpawnTool({
|
||||||
agentSessionKey: "discord:group:req",
|
agentSessionKey: "discord:group:req",
|
||||||
agentChannel: "discord",
|
agentChannel: "discord",
|
||||||
}).find((candidate) => candidate.name === "sessions_spawn");
|
});
|
||||||
if (!tool) {
|
|
||||||
throw new Error("missing sessions_spawn tool");
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await tool.execute("call1b", {
|
const result = await tool.execute("call1b", {
|
||||||
task: "do thing",
|
task: "do thing",
|
||||||
@@ -404,13 +407,10 @@ describe("openclaw-tools: subagents (sessions_spawn lifecycle)", () => {
|
|||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
const tool = createOpenClawTools({
|
const tool = await getSessionsSpawnTool({
|
||||||
agentSessionKey: "discord:group:req",
|
agentSessionKey: "discord:group:req",
|
||||||
agentChannel: "discord",
|
agentChannel: "discord",
|
||||||
}).find((candidate) => candidate.name === "sessions_spawn");
|
});
|
||||||
if (!tool) {
|
|
||||||
throw new Error("missing sessions_spawn tool");
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await tool.execute("call-timeout", {
|
const result = await tool.execute("call-timeout", {
|
||||||
task: "do thing",
|
task: "do thing",
|
||||||
@@ -474,14 +474,11 @@ describe("openclaw-tools: subagents (sessions_spawn lifecycle)", () => {
|
|||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
const tool = createOpenClawTools({
|
const tool = await getSessionsSpawnTool({
|
||||||
agentSessionKey: "main",
|
agentSessionKey: "main",
|
||||||
agentChannel: "whatsapp",
|
agentChannel: "whatsapp",
|
||||||
agentAccountId: "kev",
|
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", {
|
const result = await tool.execute("call-announce-account", {
|
||||||
task: "do thing",
|
task: "do thing",
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { beforeEach, describe, expect, it } from "vitest";
|
import { beforeEach, describe, expect, it } from "vitest";
|
||||||
import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "./defaults.js";
|
import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "./defaults.js";
|
||||||
import "./test-helpers/fast-core-tools.js";
|
import "./test-helpers/fast-core-tools.js";
|
||||||
import { createOpenClawTools } from "./openclaw-tools.js";
|
|
||||||
import {
|
import {
|
||||||
getCallGatewayMock,
|
getCallGatewayMock,
|
||||||
resetSessionsSpawnConfigOverride,
|
resetSessionsSpawnConfigOverride,
|
||||||
@@ -11,6 +10,19 @@ import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
|||||||
|
|
||||||
const callGatewayMock = getCallGatewayMock();
|
const callGatewayMock = getCallGatewayMock();
|
||||||
|
|
||||||
|
type CreateOpenClawTools = (typeof import("./openclaw-tools.js"))["createOpenClawTools"];
|
||||||
|
type CreateOpenClawToolsOpts = Parameters<CreateOpenClawTools>[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)", () => {
|
describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
resetSessionsSpawnConfigOverride();
|
resetSessionsSpawnConfigOverride();
|
||||||
@@ -46,13 +58,10 @@ describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => {
|
|||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
const tool = createOpenClawTools({
|
const tool = await getSessionsSpawnTool({
|
||||||
agentSessionKey: "discord:group:req",
|
agentSessionKey: "discord:group:req",
|
||||||
agentChannel: "discord",
|
agentChannel: "discord",
|
||||||
}).find((candidate) => candidate.name === "sessions_spawn");
|
});
|
||||||
if (!tool) {
|
|
||||||
throw new Error("missing sessions_spawn tool");
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await tool.execute("call3", {
|
const result = await tool.execute("call3", {
|
||||||
task: "do thing",
|
task: "do thing",
|
||||||
@@ -93,13 +102,10 @@ describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => {
|
|||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
const tool = createOpenClawTools({
|
const tool = await getSessionsSpawnTool({
|
||||||
agentSessionKey: "discord:group:req",
|
agentSessionKey: "discord:group:req",
|
||||||
agentChannel: "discord",
|
agentChannel: "discord",
|
||||||
}).find((candidate) => candidate.name === "sessions_spawn");
|
});
|
||||||
if (!tool) {
|
|
||||||
throw new Error("missing sessions_spawn tool");
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await tool.execute("call-thinking", {
|
const result = await tool.execute("call-thinking", {
|
||||||
task: "do thing",
|
task: "do thing",
|
||||||
@@ -126,13 +132,10 @@ describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => {
|
|||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
const tool = createOpenClawTools({
|
const tool = await getSessionsSpawnTool({
|
||||||
agentSessionKey: "discord:group:req",
|
agentSessionKey: "discord:group:req",
|
||||||
agentChannel: "discord",
|
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", {
|
const result = await tool.execute("call-thinking-invalid", {
|
||||||
task: "do thing",
|
task: "do thing",
|
||||||
@@ -166,13 +169,10 @@ describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => {
|
|||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
const tool = createOpenClawTools({
|
const tool = await getSessionsSpawnTool({
|
||||||
agentSessionKey: "agent:main:main",
|
agentSessionKey: "agent:main:main",
|
||||||
agentChannel: "discord",
|
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", {
|
const result = await tool.execute("call-default-model", {
|
||||||
task: "do thing",
|
task: "do thing",
|
||||||
@@ -207,13 +207,10 @@ describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => {
|
|||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
const tool = createOpenClawTools({
|
const tool = await getSessionsSpawnTool({
|
||||||
agentSessionKey: "agent:main:main",
|
agentSessionKey: "agent:main:main",
|
||||||
agentChannel: "discord",
|
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", {
|
const result = await tool.execute("call-runtime-default-model", {
|
||||||
task: "do thing",
|
task: "do thing",
|
||||||
@@ -255,13 +252,10 @@ describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => {
|
|||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
const tool = createOpenClawTools({
|
const tool = await getSessionsSpawnTool({
|
||||||
agentSessionKey: "agent:research:main",
|
agentSessionKey: "agent:research:main",
|
||||||
agentChannel: "discord",
|
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", {
|
const result = await tool.execute("call-agent-model", {
|
||||||
task: "do thing",
|
task: "do thing",
|
||||||
@@ -313,13 +307,10 @@ describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => {
|
|||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
const tool = createOpenClawTools({
|
const tool = await getSessionsSpawnTool({
|
||||||
agentSessionKey: "main",
|
agentSessionKey: "main",
|
||||||
agentChannel: "whatsapp",
|
agentChannel: "whatsapp",
|
||||||
}).find((candidate) => candidate.name === "sessions_spawn");
|
});
|
||||||
if (!tool) {
|
|
||||||
throw new Error("missing sessions_spawn tool");
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await tool.execute("call4", {
|
const result = await tool.execute("call4", {
|
||||||
task: "do thing",
|
task: "do thing",
|
||||||
@@ -351,13 +342,10 @@ describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => {
|
|||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
const tool = createOpenClawTools({
|
const tool = await getSessionsSpawnTool({
|
||||||
agentSessionKey: "main",
|
agentSessionKey: "main",
|
||||||
agentChannel: "whatsapp",
|
agentChannel: "whatsapp",
|
||||||
}).find((candidate) => candidate.name === "sessions_spawn");
|
});
|
||||||
if (!tool) {
|
|
||||||
throw new Error("missing sessions_spawn tool");
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await tool.execute("call5", {
|
const result = await tool.execute("call5", {
|
||||||
task: "do thing",
|
task: "do thing",
|
||||||
|
|||||||
Reference in New Issue
Block a user