|
| 1 | +import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 2 | +import type { ServerNotification } from "../../app-server"; |
| 3 | +import type { SessionState } from "../../CodexAcpServer"; |
| 4 | +import { AgentMode } from "../../AgentMode"; |
| 5 | +import { |
| 6 | + createCodexMockTestFixture, |
| 7 | + createTestSessionState, |
| 8 | + setupPromptAndSendNotifications, |
| 9 | + type CodexMockTestFixture, |
| 10 | +} from "../acp-test-utils"; |
| 11 | + |
| 12 | +describe("CodexEventHandler - collab agent tool call events", () => { |
| 13 | + let mockFixture: CodexMockTestFixture; |
| 14 | + const sessionId = "test-session-id"; |
| 15 | + |
| 16 | + beforeEach(() => { |
| 17 | + mockFixture = createCodexMockTestFixture(); |
| 18 | + vi.clearAllMocks(); |
| 19 | + }); |
| 20 | + |
| 21 | + const sessionState: SessionState = createTestSessionState({ |
| 22 | + sessionId, |
| 23 | + currentModelId: "model-id[effort]", |
| 24 | + agentMode: AgentMode.DEFAULT_AGENT_MODE, |
| 25 | + }); |
| 26 | + |
| 27 | + it("maps live collab agent tool calls to ACP tool call updates", async () => { |
| 28 | + const notifications: ServerNotification[] = [ |
| 29 | + { |
| 30 | + method: "item/started", |
| 31 | + params: { |
| 32 | + threadId: sessionId, |
| 33 | + turnId: "turn-1", |
| 34 | + startedAtMs: 0, |
| 35 | + item: { |
| 36 | + type: "collabAgentToolCall", |
| 37 | + id: "call-spawn-weather", |
| 38 | + tool: "spawnAgent", |
| 39 | + status: "inProgress", |
| 40 | + senderThreadId: "thread-main", |
| 41 | + receiverThreadIds: ["thread-paris"], |
| 42 | + prompt: "Find the current weather in Paris.", |
| 43 | + model: null, |
| 44 | + reasoningEffort: null, |
| 45 | + agentsStates: { |
| 46 | + "thread-paris": { |
| 47 | + status: "running", |
| 48 | + message: "Checking weather", |
| 49 | + }, |
| 50 | + }, |
| 51 | + }, |
| 52 | + }, |
| 53 | + }, |
| 54 | + { |
| 55 | + method: "item/completed", |
| 56 | + params: { |
| 57 | + threadId: sessionId, |
| 58 | + turnId: "turn-1", |
| 59 | + completedAtMs: 0, |
| 60 | + item: { |
| 61 | + type: "collabAgentToolCall", |
| 62 | + id: "call-spawn-weather", |
| 63 | + tool: "spawnAgent", |
| 64 | + status: "completed", |
| 65 | + senderThreadId: "thread-main", |
| 66 | + receiverThreadIds: ["thread-paris"], |
| 67 | + prompt: "Find the current weather in Paris.", |
| 68 | + model: null, |
| 69 | + reasoningEffort: null, |
| 70 | + agentsStates: { |
| 71 | + "thread-paris": { |
| 72 | + status: "completed", |
| 73 | + message: null, |
| 74 | + }, |
| 75 | + }, |
| 76 | + }, |
| 77 | + }, |
| 78 | + }, |
| 79 | + ]; |
| 80 | + |
| 81 | + await setupPromptAndSendNotifications(mockFixture, sessionId, sessionState, notifications); |
| 82 | + |
| 83 | + await expect(`${mockFixture.getAcpConnectionDump([])}\n`).toMatchFileSnapshot( |
| 84 | + "data/collab-agent-tool-call-flow.json" |
| 85 | + ); |
| 86 | + }); |
| 87 | +}); |
0 commit comments