mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 15:48:28 +00:00
test(agents): dedupe sessions_spawn model preference assertions
This commit is contained in:
@@ -12,6 +12,7 @@ import { SUBAGENT_SPAWN_ACCEPTED_NOTE } from "./subagent-spawn.js";
|
|||||||
|
|
||||||
const callGatewayMock = getCallGatewayMock();
|
const callGatewayMock = getCallGatewayMock();
|
||||||
type GatewayCall = { method?: string; params?: unknown };
|
type GatewayCall = { method?: string; params?: unknown };
|
||||||
|
type SessionsSpawnConfigOverride = Parameters<typeof setSessionsSpawnConfigOverride>[0];
|
||||||
|
|
||||||
function mockLongRunningSpawnFlow(params: {
|
function mockLongRunningSpawnFlow(params: {
|
||||||
calls: GatewayCall[];
|
calls: GatewayCall[];
|
||||||
@@ -60,6 +61,39 @@ function mockPatchAndSingleAgentRun(params: { calls: GatewayCall[]; runId: strin
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function expectSpawnUsesConfiguredModel(params: {
|
||||||
|
config: SessionsSpawnConfigOverride;
|
||||||
|
runId: string;
|
||||||
|
callId: string;
|
||||||
|
expectedModel: string;
|
||||||
|
}) {
|
||||||
|
resetSubagentRegistryForTests();
|
||||||
|
callGatewayMock.mockReset();
|
||||||
|
setSessionsSpawnConfigOverride(params.config);
|
||||||
|
const calls: GatewayCall[] = [];
|
||||||
|
mockPatchAndSingleAgentRun({ calls, runId: params.runId });
|
||||||
|
|
||||||
|
const tool = await getSessionsSpawnTool({
|
||||||
|
agentSessionKey: "agent:research:main",
|
||||||
|
agentChannel: "discord",
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await tool.execute(params.callId, {
|
||||||
|
task: "do thing",
|
||||||
|
});
|
||||||
|
expect(result.details).toMatchObject({
|
||||||
|
status: "accepted",
|
||||||
|
modelApplied: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const patchCall = calls.find(
|
||||||
|
(call) => call.method === "sessions.patch" && (call.params as { model?: string })?.model,
|
||||||
|
);
|
||||||
|
expect(patchCall?.params).toMatchObject({
|
||||||
|
model: params.expectedModel,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => {
|
describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
resetSessionsSpawnConfigOverride();
|
resetSessionsSpawnConfigOverride();
|
||||||
@@ -222,70 +256,32 @@ describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("sessions_spawn prefers per-agent subagent model over defaults", async () => {
|
it("sessions_spawn prefers per-agent subagent model over defaults", async () => {
|
||||||
resetSubagentRegistryForTests();
|
await expectSpawnUsesConfiguredModel({
|
||||||
callGatewayMock.mockReset();
|
config: {
|
||||||
setSessionsSpawnConfigOverride({
|
session: { mainKey: "main", scope: "per-sender" },
|
||||||
session: { mainKey: "main", scope: "per-sender" },
|
agents: {
|
||||||
agents: {
|
defaults: { subagents: { model: "minimax/MiniMax-M2.1" } },
|
||||||
defaults: { subagents: { model: "minimax/MiniMax-M2.1" } },
|
list: [{ id: "research", subagents: { model: "opencode/claude" } }],
|
||||||
list: [{ id: "research", subagents: { model: "opencode/claude" } }],
|
},
|
||||||
},
|
},
|
||||||
});
|
runId: "run-agent-model",
|
||||||
const calls: GatewayCall[] = [];
|
callId: "call-agent-model",
|
||||||
mockPatchAndSingleAgentRun({ calls, runId: "run-agent-model" });
|
expectedModel: "opencode/claude",
|
||||||
|
|
||||||
const tool = await getSessionsSpawnTool({
|
|
||||||
agentSessionKey: "agent:research:main",
|
|
||||||
agentChannel: "discord",
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await tool.execute("call-agent-model", {
|
|
||||||
task: "do thing",
|
|
||||||
});
|
|
||||||
expect(result.details).toMatchObject({
|
|
||||||
status: "accepted",
|
|
||||||
modelApplied: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const patchCall = calls.find(
|
|
||||||
(call) => call.method === "sessions.patch" && (call.params as { model?: string })?.model,
|
|
||||||
);
|
|
||||||
expect(patchCall?.params).toMatchObject({
|
|
||||||
model: "opencode/claude",
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("sessions_spawn prefers target agent primary model over global default", async () => {
|
it("sessions_spawn prefers target agent primary model over global default", async () => {
|
||||||
resetSubagentRegistryForTests();
|
await expectSpawnUsesConfiguredModel({
|
||||||
callGatewayMock.mockReset();
|
config: {
|
||||||
setSessionsSpawnConfigOverride({
|
session: { mainKey: "main", scope: "per-sender" },
|
||||||
session: { mainKey: "main", scope: "per-sender" },
|
agents: {
|
||||||
agents: {
|
defaults: { model: { primary: "minimax/MiniMax-M2.1" } },
|
||||||
defaults: { model: { primary: "minimax/MiniMax-M2.1" } },
|
list: [{ id: "research", model: { primary: "opencode/claude" } }],
|
||||||
list: [{ id: "research", model: { primary: "opencode/claude" } }],
|
},
|
||||||
},
|
},
|
||||||
});
|
runId: "run-agent-primary-model",
|
||||||
const calls: GatewayCall[] = [];
|
callId: "call-agent-primary-model",
|
||||||
mockPatchAndSingleAgentRun({ calls, runId: "run-agent-primary-model" });
|
expectedModel: "opencode/claude",
|
||||||
|
|
||||||
const tool = await getSessionsSpawnTool({
|
|
||||||
agentSessionKey: "agent:research:main",
|
|
||||||
agentChannel: "discord",
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await tool.execute("call-agent-primary-model", {
|
|
||||||
task: "do thing",
|
|
||||||
});
|
|
||||||
expect(result.details).toMatchObject({
|
|
||||||
status: "accepted",
|
|
||||||
modelApplied: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const patchCall = calls.find(
|
|
||||||
(call) => call.method === "sessions.patch" && (call.params as { model?: string })?.model,
|
|
||||||
);
|
|
||||||
expect(patchCall?.params).toMatchObject({
|
|
||||||
model: "opencode/claude",
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user