mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 14:18:26 +00:00
refactor(test): dedupe sessions_spawn thinking assertions
This commit is contained in:
@@ -33,21 +33,37 @@ vi.mock("../gateway/call.js", () => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
type GatewayCall = { method: string; params?: Record<string, unknown> };
|
||||||
|
|
||||||
|
async function getGatewayCalls(): Promise<GatewayCall[]> {
|
||||||
|
const { callGateway } = await import("../gateway/call.js");
|
||||||
|
return (callGateway as unknown as ReturnType<typeof vi.fn>).mock.calls.map(
|
||||||
|
(call) => call[0] as GatewayCall,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function findLastCall(calls: GatewayCall[], predicate: (call: GatewayCall) => boolean) {
|
||||||
|
for (let i = calls.length - 1; i >= 0; i -= 1) {
|
||||||
|
const call = calls[i];
|
||||||
|
if (call && predicate(call)) {
|
||||||
|
return call;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
describe("sessions_spawn thinking defaults", () => {
|
describe("sessions_spawn thinking defaults", () => {
|
||||||
it("applies agents.defaults.subagents.thinking when thinking is omitted", async () => {
|
it("applies agents.defaults.subagents.thinking when thinking is omitted", async () => {
|
||||||
const tool = createSessionsSpawnTool({ agentSessionKey: "agent:test:main" });
|
const tool = createSessionsSpawnTool({ agentSessionKey: "agent:test:main" });
|
||||||
const result = await tool.execute("call-1", { task: "hello" });
|
const result = await tool.execute("call-1", { task: "hello" });
|
||||||
expect(result.details).toMatchObject({ status: "accepted" });
|
expect(result.details).toMatchObject({ status: "accepted" });
|
||||||
|
|
||||||
const { callGateway } = await import("../gateway/call.js");
|
const calls = await getGatewayCalls();
|
||||||
const calls = (callGateway as unknown as ReturnType<typeof vi.fn>).mock.calls;
|
const agentCall = findLastCall(calls, (call) => call.method === "agent");
|
||||||
|
const thinkingPatch = findLastCall(
|
||||||
const agentCall = calls
|
calls,
|
||||||
.map((call) => call[0] as { method: string; params?: Record<string, unknown> })
|
(call) => call.method === "sessions.patch" && call.params?.thinkingLevel !== undefined,
|
||||||
.findLast((call) => call.method === "agent");
|
);
|
||||||
const thinkingPatch = calls
|
|
||||||
.map((call) => call[0] as { method: string; params?: Record<string, unknown> })
|
|
||||||
.findLast((call) => call.method === "sessions.patch" && call.params?.thinkingLevel);
|
|
||||||
|
|
||||||
expect(agentCall?.params?.thinking).toBe("high");
|
expect(agentCall?.params?.thinking).toBe("high");
|
||||||
expect(thinkingPatch?.params?.thinkingLevel).toBe("high");
|
expect(thinkingPatch?.params?.thinkingLevel).toBe("high");
|
||||||
@@ -58,15 +74,12 @@ describe("sessions_spawn thinking defaults", () => {
|
|||||||
const result = await tool.execute("call-2", { task: "hello", thinking: "low" });
|
const result = await tool.execute("call-2", { task: "hello", thinking: "low" });
|
||||||
expect(result.details).toMatchObject({ status: "accepted" });
|
expect(result.details).toMatchObject({ status: "accepted" });
|
||||||
|
|
||||||
const { callGateway } = await import("../gateway/call.js");
|
const calls = await getGatewayCalls();
|
||||||
const calls = (callGateway as unknown as ReturnType<typeof vi.fn>).mock.calls;
|
const agentCall = findLastCall(calls, (call) => call.method === "agent");
|
||||||
|
const thinkingPatch = findLastCall(
|
||||||
const agentCall = calls
|
calls,
|
||||||
.map((call) => call[0] as { method: string; params?: Record<string, unknown> })
|
(call) => call.method === "sessions.patch" && call.params?.thinkingLevel !== undefined,
|
||||||
.findLast((call) => call.method === "agent");
|
);
|
||||||
const thinkingPatch = calls
|
|
||||||
.map((call) => call[0] as { method: string; params?: Record<string, unknown> })
|
|
||||||
.findLast((call) => call.method === "sessions.patch" && call.params?.thinkingLevel);
|
|
||||||
|
|
||||||
expect(agentCall?.params?.thinking).toBe("low");
|
expect(agentCall?.params?.thinking).toBe("low");
|
||||||
expect(thinkingPatch?.params?.thinkingLevel).toBe("low");
|
expect(thinkingPatch?.params?.thinkingLevel).toBe("low");
|
||||||
|
|||||||
Reference in New Issue
Block a user