mirror of https://github.com/openclaw/openclaw.git
Merge 0f22258329 into c4265a5f16
This commit is contained in:
commit
6b9573acff
|
|
@ -1,10 +1,14 @@
|
|||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import "./test-helpers/fast-core-tools.js";
|
||||
import * as harness from "./openclaw-tools.subagents.sessions-spawn.test-harness.js";
|
||||
import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
||||
|
||||
const MAIN_SESSION_KEY = "agent:test:main";
|
||||
|
||||
async function resetRegistry() {
|
||||
const { resetSubagentRegistryForTests } = await import("./subagent-registry.js");
|
||||
resetSubagentRegistryForTests();
|
||||
}
|
||||
|
||||
type ThinkingLevel = "high" | "medium" | "low";
|
||||
|
||||
function applyThinkingDefault(thinking: ThinkingLevel) {
|
||||
|
|
@ -60,9 +64,9 @@ async function expectThinkingPropagation(input: {
|
|||
}
|
||||
|
||||
describe("sessions_spawn thinking defaults", () => {
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
harness.resetSessionsSpawnConfigOverride();
|
||||
resetSubagentRegistryForTests();
|
||||
await resetRegistry();
|
||||
harness.getCallGatewayMock().mockClear();
|
||||
applyThinkingDefault("high");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -7,10 +7,14 @@ import {
|
|||
setSessionsSpawnConfigOverride,
|
||||
setupSessionsSpawnGatewayMock,
|
||||
} from "./openclaw-tools.subagents.sessions-spawn.test-harness.js";
|
||||
import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
||||
|
||||
const MAIN_SESSION_KEY = "agent:test:main";
|
||||
|
||||
async function resetRegistry() {
|
||||
const { resetSubagentRegistryForTests } = await import("./subagent-registry.js");
|
||||
resetSubagentRegistryForTests();
|
||||
}
|
||||
|
||||
function configureDefaultsWithoutTimeout() {
|
||||
setSessionsSpawnConfigOverride({
|
||||
session: { mainKey: "main", scope: "per-sender" },
|
||||
|
|
@ -31,9 +35,9 @@ function readSpawnTimeout(calls: Array<{ method?: string; params?: unknown }>):
|
|||
}
|
||||
|
||||
describe("sessions_spawn default runTimeoutSeconds (config absent)", () => {
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
resetSessionsSpawnConfigOverride();
|
||||
resetSubagentRegistryForTests();
|
||||
await resetRegistry();
|
||||
getCallGatewayMock().mockClear();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import "./test-helpers/fast-core-tools.js";
|
||||
import * as sessionsHarness from "./openclaw-tools.subagents.sessions-spawn.test-harness.js";
|
||||
import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
||||
|
||||
const MAIN_SESSION_KEY = "agent:test:main";
|
||||
|
||||
async function resetRegistry() {
|
||||
const { resetSubagentRegistryForTests } = await import("./subagent-registry.js");
|
||||
resetSubagentRegistryForTests();
|
||||
}
|
||||
|
||||
function applySubagentTimeoutDefault(seconds: number) {
|
||||
sessionsHarness.setSessionsSpawnConfigOverride({
|
||||
session: { mainKey: "main", scope: "per-sender" },
|
||||
|
|
@ -34,9 +38,9 @@ async function spawnSubagent(callId: string, payload: Record<string, unknown>) {
|
|||
}
|
||||
|
||||
describe("sessions_spawn default runTimeoutSeconds", () => {
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
sessionsHarness.resetSessionsSpawnConfigOverride();
|
||||
resetSubagentRegistryForTests();
|
||||
await resetRegistry();
|
||||
sessionsHarness.getCallGatewayMock().mockClear();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -2,9 +2,7 @@ import fs from "node:fs";
|
|||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { addSubagentRunForTests, resetSubagentRegistryForTests } from "./subagent-registry.js";
|
||||
import { createPerSenderSessionConfig } from "./test-helpers/session-config.js";
|
||||
import { createSessionsSpawnTool } from "./tools/sessions-spawn-tool.js";
|
||||
|
||||
const callGatewayMock = vi.fn();
|
||||
|
||||
|
|
@ -25,6 +23,23 @@ vi.mock("../config/config.js", async (importOriginal) => {
|
|||
};
|
||||
});
|
||||
|
||||
async function createTool(opts: { agentSessionKey?: string }) {
|
||||
const { createSessionsSpawnTool } = await import("./tools/sessions-spawn-tool.js");
|
||||
return createSessionsSpawnTool(opts);
|
||||
}
|
||||
|
||||
async function resetRegistry() {
|
||||
const { resetSubagentRegistryForTests } = await import("./subagent-registry.js");
|
||||
resetSubagentRegistryForTests();
|
||||
}
|
||||
|
||||
async function addRegistryRun(
|
||||
run: Parameters<(typeof import("./subagent-registry.js"))["addSubagentRunForTests"]>[0],
|
||||
) {
|
||||
const { addSubagentRunForTests } = await import("./subagent-registry.js");
|
||||
addSubagentRunForTests(run);
|
||||
}
|
||||
|
||||
function writeStore(agentId: string, store: Record<string, unknown>) {
|
||||
const storePath = storeTemplatePath.replaceAll("{agentId}", agentId);
|
||||
fs.mkdirSync(path.dirname(storePath), { recursive: true });
|
||||
|
|
@ -61,8 +76,8 @@ function seedDepthTwoAncestryStore(params?: { sessionIds?: boolean }) {
|
|||
}
|
||||
|
||||
describe("sessions_spawn depth + child limits", () => {
|
||||
beforeEach(() => {
|
||||
resetSubagentRegistryForTests();
|
||||
beforeEach(async () => {
|
||||
await resetRegistry();
|
||||
callGatewayMock.mockClear();
|
||||
storeTemplatePath = path.join(
|
||||
os.tmpdir(),
|
||||
|
|
@ -85,10 +100,7 @@ describe("sessions_spawn depth + child limits", () => {
|
|||
});
|
||||
|
||||
it("rejects spawning when caller depth reaches maxSpawnDepth", async () => {
|
||||
const tool = createSessionsSpawnTool({
|
||||
agentSessionKey: "agent:main:subagent:parent",
|
||||
workspaceDir: "/parent/workspace",
|
||||
});
|
||||
const tool = await createTool({ agentSessionKey: "agent:main:subagent:parent" });
|
||||
const result = await tool.execute("call-depth-reject", { task: "hello" });
|
||||
|
||||
expect(result.details).toMatchObject({
|
||||
|
|
@ -100,7 +112,7 @@ describe("sessions_spawn depth + child limits", () => {
|
|||
it("allows depth-1 callers when maxSpawnDepth is 2", async () => {
|
||||
setSubagentLimits({ maxSpawnDepth: 2 });
|
||||
|
||||
const tool = createSessionsSpawnTool({ agentSessionKey: "agent:main:subagent:parent" });
|
||||
const tool = await createTool({ agentSessionKey: "agent:main:subagent:parent" });
|
||||
const result = await tool.execute("call-depth-allow", { task: "hello" });
|
||||
|
||||
expect(result.details).toMatchObject({
|
||||
|
|
@ -140,7 +152,7 @@ describe("sessions_spawn depth + child limits", () => {
|
|||
},
|
||||
});
|
||||
|
||||
const tool = createSessionsSpawnTool({ agentSessionKey: callerKey });
|
||||
const tool = await createTool({ agentSessionKey: callerKey });
|
||||
const result = await tool.execute("call-depth-2-reject", { task: "hello" });
|
||||
|
||||
expect(result.details).toMatchObject({
|
||||
|
|
@ -153,7 +165,7 @@ describe("sessions_spawn depth + child limits", () => {
|
|||
setSubagentLimits({ maxSpawnDepth: 2 });
|
||||
const { callerKey } = seedDepthTwoAncestryStore();
|
||||
|
||||
const tool = createSessionsSpawnTool({ agentSessionKey: callerKey });
|
||||
const tool = await createTool({ agentSessionKey: callerKey });
|
||||
const result = await tool.execute("call-depth-ancestry-reject", { task: "hello" });
|
||||
|
||||
expect(result.details).toMatchObject({
|
||||
|
|
@ -166,7 +178,7 @@ describe("sessions_spawn depth + child limits", () => {
|
|||
setSubagentLimits({ maxSpawnDepth: 2 });
|
||||
seedDepthTwoAncestryStore({ sessionIds: true });
|
||||
|
||||
const tool = createSessionsSpawnTool({ agentSessionKey: "depth-2-session" });
|
||||
const tool = await createTool({ agentSessionKey: "depth-2-session" });
|
||||
const result = await tool.execute("call-depth-sessionid-reject", { task: "hello" });
|
||||
|
||||
expect(result.details).toMatchObject({
|
||||
|
|
@ -188,7 +200,7 @@ describe("sessions_spawn depth + child limits", () => {
|
|||
},
|
||||
};
|
||||
|
||||
addSubagentRunForTests({
|
||||
await addRegistryRun({
|
||||
runId: "existing-run",
|
||||
childSessionKey: "agent:main:subagent:existing",
|
||||
requesterSessionKey: "agent:main:subagent:parent",
|
||||
|
|
@ -199,7 +211,7 @@ describe("sessions_spawn depth + child limits", () => {
|
|||
startedAt: Date.now(),
|
||||
});
|
||||
|
||||
const tool = createSessionsSpawnTool({ agentSessionKey: "agent:main:subagent:parent" });
|
||||
const tool = await createTool({ agentSessionKey: "agent:main:subagent:parent" });
|
||||
const result = await tool.execute("call-max-children", { task: "hello" });
|
||||
|
||||
expect(result.details).toMatchObject({
|
||||
|
|
@ -222,7 +234,7 @@ describe("sessions_spawn depth + child limits", () => {
|
|||
},
|
||||
};
|
||||
|
||||
const tool = createSessionsSpawnTool({ agentSessionKey: "agent:main:subagent:parent" });
|
||||
const tool = await createTool({ agentSessionKey: "agent:main:subagent:parent" });
|
||||
const result = await tool.execute("call-max-concurrent-independent", { task: "hello" });
|
||||
|
||||
expect(result.details).toMatchObject({
|
||||
|
|
@ -247,7 +259,7 @@ describe("sessions_spawn depth + child limits", () => {
|
|||
return {};
|
||||
});
|
||||
|
||||
const tool = createSessionsSpawnTool({ agentSessionKey: "main" });
|
||||
const tool = await createTool({ agentSessionKey: "main" });
|
||||
const result = await tool.execute("call-model-reject", {
|
||||
task: "hello",
|
||||
model: "bad-model",
|
||||
|
|
|
|||
|
|
@ -6,10 +6,14 @@ import {
|
|||
resetSessionsSpawnConfigOverride,
|
||||
setSessionsSpawnConfigOverride,
|
||||
} from "./openclaw-tools.subagents.sessions-spawn.test-harness.js";
|
||||
import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
||||
|
||||
const callGatewayMock = getCallGatewayMock();
|
||||
|
||||
async function resetRegistry() {
|
||||
const { resetSubagentRegistryForTests } = await import("./subagent-registry.js");
|
||||
resetSubagentRegistryForTests();
|
||||
}
|
||||
|
||||
describe("openclaw-tools: subagents (sessions_spawn allowlist)", () => {
|
||||
function setAllowAgents(allowAgents: string[]) {
|
||||
setSessionsSpawnConfigOverride({
|
||||
|
|
@ -125,9 +129,9 @@ describe("openclaw-tools: subagents (sessions_spawn allowlist)", () => {
|
|||
expect(callGatewayMock).not.toHaveBeenCalled();
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
resetSessionsSpawnConfigOverride();
|
||||
resetSubagentRegistryForTests();
|
||||
await resetRegistry();
|
||||
callGatewayMock.mockClear();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -6,17 +6,25 @@ import {
|
|||
resetSessionsSpawnConfigOverride,
|
||||
setupSessionsSpawnGatewayMock,
|
||||
} from "./openclaw-tools.subagents.sessions-spawn.test-harness.js";
|
||||
import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
||||
import { SUBAGENT_SPAWN_ACCEPTED_NOTE } from "./subagent-spawn.js";
|
||||
|
||||
const callGatewayMock = getCallGatewayMock();
|
||||
|
||||
async function getAcceptedNote() {
|
||||
const { SUBAGENT_SPAWN_ACCEPTED_NOTE } = await import("./subagent-spawn.js");
|
||||
return SUBAGENT_SPAWN_ACCEPTED_NOTE;
|
||||
}
|
||||
|
||||
async function resetRegistry() {
|
||||
const { resetSubagentRegistryForTests } = await import("./subagent-registry.js");
|
||||
resetSubagentRegistryForTests();
|
||||
}
|
||||
|
||||
type SpawnResult = { status?: string; note?: string };
|
||||
|
||||
describe("sessions_spawn: cron isolated session note suppression", () => {
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
callGatewayMock.mockReset();
|
||||
resetSubagentRegistryForTests();
|
||||
await resetRegistry();
|
||||
resetSessionsSpawnConfigOverride();
|
||||
});
|
||||
|
||||
|
|
@ -32,17 +40,19 @@ describe("sessions_spawn: cron isolated session note suppression", () => {
|
|||
});
|
||||
|
||||
it("preserves ACCEPTED_NOTE for regular sessions (mode=run)", async () => {
|
||||
const acceptedNote = await getAcceptedNote();
|
||||
setupSessionsSpawnGatewayMock({});
|
||||
const tool = await getSessionsSpawnTool({
|
||||
agentSessionKey: "agent:main:telegram:63448508",
|
||||
});
|
||||
const result = await tool.execute("call-regular-run", { task: "test task", mode: "run" });
|
||||
const details = result.details as SpawnResult;
|
||||
expect(details.note).toBe(SUBAGENT_SPAWN_ACCEPTED_NOTE);
|
||||
expect(details.note).toBe(acceptedNote);
|
||||
expect(details.status).toBe("accepted");
|
||||
});
|
||||
|
||||
it("does not suppress ACCEPTED_NOTE for non-canonical cron-like keys", async () => {
|
||||
const acceptedNote = await getAcceptedNote();
|
||||
setupSessionsSpawnGatewayMock({});
|
||||
const tool = await getSessionsSpawnTool({
|
||||
agentSessionKey: "agent:main:slack:cron:job:run:uuid",
|
||||
|
|
@ -51,15 +61,16 @@ describe("sessions_spawn: cron isolated session note suppression", () => {
|
|||
task: "test task",
|
||||
mode: "run",
|
||||
});
|
||||
expect((result.details as SpawnResult).note).toBe(SUBAGENT_SPAWN_ACCEPTED_NOTE);
|
||||
expect((result.details as SpawnResult).note).toBe(acceptedNote);
|
||||
});
|
||||
|
||||
it("does not suppress note when agentSessionKey is undefined", async () => {
|
||||
const acceptedNote = await getAcceptedNote();
|
||||
setupSessionsSpawnGatewayMock({});
|
||||
const tool = await getSessionsSpawnTool({
|
||||
agentSessionKey: undefined,
|
||||
});
|
||||
const result = await tool.execute("call-no-key", { task: "test task", mode: "run" });
|
||||
expect((result.details as SpawnResult).note).toBe(SUBAGENT_SPAWN_ACCEPTED_NOTE);
|
||||
expect((result.details as SpawnResult).note).toBe(acceptedNote);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,7 +8,11 @@ import {
|
|||
setupSessionsSpawnGatewayMock,
|
||||
setSessionsSpawnConfigOverride,
|
||||
} from "./openclaw-tools.subagents.sessions-spawn.test-harness.js";
|
||||
import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
||||
|
||||
async function resetRegistry() {
|
||||
const { resetSubagentRegistryForTests } = await import("./subagent-registry.js");
|
||||
resetSubagentRegistryForTests();
|
||||
}
|
||||
|
||||
const fastModeEnv = vi.hoisted(() => {
|
||||
const previous = process.env.OPENCLAW_TEST_FAST;
|
||||
|
|
@ -103,7 +107,7 @@ async function emitLifecycleEndAndFlush(params: {
|
|||
}
|
||||
|
||||
describe("openclaw-tools: subagents (sessions_spawn lifecycle)", () => {
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
resetSessionsSpawnConfigOverride();
|
||||
setSessionsSpawnConfigOverride({
|
||||
session: {
|
||||
|
|
@ -116,7 +120,7 @@ describe("openclaw-tools: subagents (sessions_spawn lifecycle)", () => {
|
|||
},
|
||||
},
|
||||
});
|
||||
resetSubagentRegistryForTests();
|
||||
await resetRegistry();
|
||||
callGatewayMock.mockClear();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -7,13 +7,21 @@ import {
|
|||
resetSessionsSpawnConfigOverride,
|
||||
setSessionsSpawnConfigOverride,
|
||||
} from "./openclaw-tools.subagents.sessions-spawn.test-harness.js";
|
||||
import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
||||
import { SUBAGENT_SPAWN_ACCEPTED_NOTE } from "./subagent-spawn.js";
|
||||
|
||||
const callGatewayMock = getCallGatewayMock();
|
||||
type GatewayCall = { method?: string; params?: unknown };
|
||||
type SessionsSpawnConfigOverride = Parameters<typeof setSessionsSpawnConfigOverride>[0];
|
||||
|
||||
async function getAcceptedNote() {
|
||||
const { SUBAGENT_SPAWN_ACCEPTED_NOTE } = await import("./subagent-spawn.js");
|
||||
return SUBAGENT_SPAWN_ACCEPTED_NOTE;
|
||||
}
|
||||
|
||||
async function resetRegistry() {
|
||||
const { resetSubagentRegistryForTests } = await import("./subagent-registry.js");
|
||||
resetSubagentRegistryForTests();
|
||||
}
|
||||
|
||||
function mockLongRunningSpawnFlow(params: {
|
||||
calls: GatewayCall[];
|
||||
acceptedAtBase: number;
|
||||
|
|
@ -97,13 +105,14 @@ async function expectSpawnUsesConfiguredModel(params: {
|
|||
}
|
||||
|
||||
describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => {
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
resetSessionsSpawnConfigOverride();
|
||||
resetSubagentRegistryForTests();
|
||||
await resetRegistry();
|
||||
callGatewayMock.mockClear();
|
||||
});
|
||||
|
||||
it("sessions_spawn applies a model to the child session", async () => {
|
||||
const acceptedNote = await getAcceptedNote();
|
||||
const calls: GatewayCall[] = [];
|
||||
mockLongRunningSpawnFlow({ calls, acceptedAtBase: 3000 });
|
||||
|
||||
|
|
@ -120,7 +129,7 @@ describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => {
|
|||
});
|
||||
expect(result.details).toMatchObject({
|
||||
status: "accepted",
|
||||
note: SUBAGENT_SPAWN_ACCEPTED_NOTE,
|
||||
note: acceptedNote,
|
||||
modelApplied: true,
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -5,13 +5,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|||
import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
||||
import { decodeStrictBase64, spawnSubagentDirect } from "./subagent-spawn.js";
|
||||
|
||||
const callGatewayMock = vi.fn();
|
||||
|
||||
vi.mock("../gateway/call.js", () => ({
|
||||
callGateway: (opts: unknown) => callGatewayMock(opts),
|
||||
}));
|
||||
|
||||
let configOverride: Record<string, unknown> = {
|
||||
const hoisted = vi.hoisted(() => {
|
||||
const defaultConfigOverride: Record<string, unknown> = {
|
||||
session: {
|
||||
mainKey: "main",
|
||||
scope: "per-sender",
|
||||
|
|
@ -28,17 +23,40 @@ let configOverride: Record<string, unknown> = {
|
|||
},
|
||||
agents: {
|
||||
defaults: {
|
||||
workspace: os.tmpdir(),
|
||||
workspace: "/tmp",
|
||||
},
|
||||
},
|
||||
};
|
||||
let workspaceDirOverride = "";
|
||||
const state = {
|
||||
configOverride: defaultConfigOverride,
|
||||
};
|
||||
return {
|
||||
callGatewayMock: vi.fn(),
|
||||
defaultConfigOverride,
|
||||
state,
|
||||
};
|
||||
});
|
||||
|
||||
const callGatewayMock = hoisted.callGatewayMock;
|
||||
|
||||
vi.mock("../gateway/call.js", () => ({
|
||||
callGateway: (opts: unknown) => callGatewayMock(opts),
|
||||
}));
|
||||
|
||||
let workspaceDirOverride = "";
|
||||
vi.mock("../config/config.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../config/config.js")>();
|
||||
return {
|
||||
...actual,
|
||||
loadConfig: () => configOverride,
|
||||
loadConfig: () => hoisted.state.configOverride,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../../config/config.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../config/config.js")>();
|
||||
return {
|
||||
...actual,
|
||||
loadConfig: () => hoisted.state.configOverride,
|
||||
};
|
||||
});
|
||||
|
||||
|
|
@ -144,6 +162,7 @@ describe("decodeStrictBase64", () => {
|
|||
|
||||
describe("spawnSubagentDirect filename validation", () => {
|
||||
beforeEach(() => {
|
||||
hoisted.state.configOverride = hoisted.defaultConfigOverride;
|
||||
resetSubagentRegistryForTests();
|
||||
callGatewayMock.mockClear();
|
||||
setupGatewayMock();
|
||||
|
|
|
|||
Loading…
Reference in New Issue