Tests: isolate sessions spawn registry seam

This commit is contained in:
Gustavo Madeira Santana
2026-04-19 19:26:56 -04:00
parent f06493f0ea
commit 6159b17cdf

View File

@@ -3,9 +3,11 @@ import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
const hoisted = vi.hoisted(() => {
const spawnSubagentDirectMock = vi.fn();
const spawnAcpDirectMock = vi.fn();
const registerSubagentRunMock = vi.fn();
return {
spawnSubagentDirectMock,
spawnAcpDirectMock,
registerSubagentRunMock,
};
});
@@ -21,6 +23,10 @@ vi.mock("../acp-spawn.js", () => ({
spawnAcpDirect: (...args: unknown[]) => hoisted.spawnAcpDirectMock(...args),
}));
vi.mock("../subagent-registry.js", () => ({
registerSubagentRun: (...args: unknown[]) => hoisted.registerSubagentRunMock(...args),
}));
let createSessionsSpawnTool: typeof import("./sessions-spawn-tool.js").createSessionsSpawnTool;
describe("sessions_spawn tool", () => {
@@ -39,6 +45,7 @@ describe("sessions_spawn tool", () => {
childSessionKey: "agent:codex:acp:1",
runId: "run-acp",
});
hoisted.registerSubagentRunMock.mockReset();
});
it("uses subagent runtime by default", async () => {
@@ -237,6 +244,7 @@ describe("sessions_spawn tool", () => {
}),
);
expect(hoisted.spawnSubagentDirectMock).not.toHaveBeenCalled();
expect(hoisted.registerSubagentRunMock).not.toHaveBeenCalled();
});
it("adds requested role to forwarded ACP failures", async () => {
@@ -286,6 +294,16 @@ describe("sessions_spawn tool", () => {
sandboxed: true,
}),
);
expect(hoisted.registerSubagentRunMock).toHaveBeenCalledWith(
expect.objectContaining({
runId: "run-acp",
childSessionKey: "agent:codex:acp:1",
requesterSessionKey: "agent:main:subagent:parent",
task: "investigate",
cleanup: "keep",
spawnMode: "run",
}),
);
});
it("passes resumeSessionId through to ACP spawns", async () => {