mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
test: fold sessions timeout checks into pure coverage
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import "./test-helpers/fast-core-tools.js";
|
||||
import {
|
||||
getCallGatewayMock,
|
||||
getSessionsSpawnTool,
|
||||
resetSessionsSpawnConfigOverride,
|
||||
setSessionsSpawnConfigOverride,
|
||||
setupSessionsSpawnGatewayMock,
|
||||
} from "./openclaw-tools.subagents.sessions-spawn.test-harness.js";
|
||||
import { resetSubagentRegistryForTests } from "./subagent-registry.js";
|
||||
|
||||
const MAIN_SESSION_KEY = "agent:test:main";
|
||||
|
||||
function configureDefaultsWithoutTimeout() {
|
||||
setSessionsSpawnConfigOverride({
|
||||
session: { mainKey: "main", scope: "per-sender" },
|
||||
agents: { defaults: { subagents: { maxConcurrent: 8 } } },
|
||||
});
|
||||
}
|
||||
|
||||
function readSpawnTimeout(calls: Array<{ method?: string; params?: unknown }>): number | undefined {
|
||||
const spawn = calls.find((entry) => {
|
||||
if (entry.method !== "agent") {
|
||||
return false;
|
||||
}
|
||||
const params = entry.params as { lane?: string } | undefined;
|
||||
return params?.lane === "subagent";
|
||||
});
|
||||
const params = spawn?.params as { timeout?: number } | undefined;
|
||||
return params?.timeout;
|
||||
}
|
||||
|
||||
describe("sessions_spawn default runTimeoutSeconds (config absent)", () => {
|
||||
beforeEach(() => {
|
||||
resetSessionsSpawnConfigOverride();
|
||||
resetSubagentRegistryForTests();
|
||||
getCallGatewayMock().mockClear();
|
||||
});
|
||||
|
||||
it("falls back to 0 (no timeout) when config key is absent", async () => {
|
||||
configureDefaultsWithoutTimeout();
|
||||
const gateway = setupSessionsSpawnGatewayMock({});
|
||||
const tool = await getSessionsSpawnTool({ agentSessionKey: MAIN_SESSION_KEY });
|
||||
|
||||
const result = await tool.execute("call-1", { task: "hello" });
|
||||
expect(result.details).toMatchObject({ status: "accepted" });
|
||||
expect(readSpawnTimeout(gateway.calls)).toBe(0);
|
||||
});
|
||||
});
|
||||
@@ -1,60 +0,0 @@
|
||||
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";
|
||||
|
||||
function applySubagentTimeoutDefault(seconds: number) {
|
||||
sessionsHarness.setSessionsSpawnConfigOverride({
|
||||
session: { mainKey: "main", scope: "per-sender" },
|
||||
agents: { defaults: { subagents: { runTimeoutSeconds: seconds } } },
|
||||
});
|
||||
}
|
||||
|
||||
function getSubagentTimeout(
|
||||
calls: Array<{ method?: string; params?: unknown }>,
|
||||
): number | undefined {
|
||||
for (const call of calls) {
|
||||
if (call.method !== "agent") {
|
||||
continue;
|
||||
}
|
||||
const params = call.params as { lane?: string; timeout?: number } | undefined;
|
||||
if (params?.lane === "subagent") {
|
||||
return params.timeout;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async function spawnSubagent(callId: string, payload: Record<string, unknown>) {
|
||||
const tool = await sessionsHarness.getSessionsSpawnTool({ agentSessionKey: MAIN_SESSION_KEY });
|
||||
const result = await tool.execute(callId, payload);
|
||||
expect(result.details).toMatchObject({ status: "accepted" });
|
||||
}
|
||||
|
||||
describe("sessions_spawn default runTimeoutSeconds", () => {
|
||||
beforeEach(() => {
|
||||
sessionsHarness.resetSessionsSpawnConfigOverride();
|
||||
resetSubagentRegistryForTests();
|
||||
sessionsHarness.getCallGatewayMock().mockClear();
|
||||
});
|
||||
|
||||
it("uses config default when agent omits runTimeoutSeconds", async () => {
|
||||
applySubagentTimeoutDefault(900);
|
||||
const gateway = sessionsHarness.setupSessionsSpawnGatewayMock({});
|
||||
|
||||
await spawnSubagent("call-1", { task: "hello" });
|
||||
|
||||
expect(getSubagentTimeout(gateway.calls)).toBe(900);
|
||||
});
|
||||
|
||||
it("explicit runTimeoutSeconds wins over config default", async () => {
|
||||
applySubagentTimeoutDefault(900);
|
||||
const gateway = sessionsHarness.setupSessionsSpawnGatewayMock({});
|
||||
|
||||
await spawnSubagent("call-2", { task: "hello", runTimeoutSeconds: 300 });
|
||||
|
||||
expect(getSubagentTimeout(gateway.calls)).toBe(300);
|
||||
});
|
||||
});
|
||||
@@ -151,4 +151,14 @@ describe("subagent spawn model + thinking plan", () => {
|
||||
}),
|
||||
).toBe(2);
|
||||
});
|
||||
|
||||
it("falls back to 0 when config omits the timeout", () => {
|
||||
expect(
|
||||
resolveConfiguredSubagentRunTimeoutSeconds({
|
||||
cfg: createConfig({
|
||||
agents: { defaults: { subagents: { maxConcurrent: 8 } } },
|
||||
}),
|
||||
}),
|
||||
).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user