|
| 1 | +import { describe, it, expect, vi, beforeEach } from "vitest"; |
| 2 | +import type { SessionState } from "../../CodexAcpServer"; |
| 3 | +import type { ServerNotification } from "../../app-server"; |
| 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 - thread goal 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("should send thread goal updates as agent messages", async () => { |
| 28 | + const goalUpdatedNotification: ServerNotification = { |
| 29 | + method: "thread/goal/updated", |
| 30 | + params: { |
| 31 | + threadId: sessionId, |
| 32 | + turnId: "turn-1", |
| 33 | + goal: { |
| 34 | + threadId: sessionId, |
| 35 | + objective: "Ship the goal update", |
| 36 | + status: "active", |
| 37 | + tokenBudget: null, |
| 38 | + tokensUsed: 42, |
| 39 | + timeUsedSeconds: 12, |
| 40 | + createdAt: 1710000000, |
| 41 | + updatedAt: 1710000012, |
| 42 | + }, |
| 43 | + }, |
| 44 | + }; |
| 45 | + |
| 46 | + await setupPromptAndSendNotifications(mockFixture, sessionId, sessionState, [goalUpdatedNotification]); |
| 47 | + |
| 48 | + await expect(mockFixture.getAcpConnectionDump([])).toMatchFileSnapshot( |
| 49 | + "data/thread-goal-updated.json" |
| 50 | + ); |
| 51 | + }); |
| 52 | + |
| 53 | + it("should format multiline thread goal updates", async () => { |
| 54 | + const goalUpdatedNotification: ServerNotification = { |
| 55 | + method: "thread/goal/updated", |
| 56 | + params: { |
| 57 | + threadId: sessionId, |
| 58 | + turnId: null, |
| 59 | + goal: { |
| 60 | + threadId: sessionId, |
| 61 | + objective: " First task\nSecond task\n ", |
| 62 | + status: "budgetLimited", |
| 63 | + tokenBudget: 1000, |
| 64 | + tokensUsed: 1000, |
| 65 | + timeUsedSeconds: 30, |
| 66 | + createdAt: 1710000000, |
| 67 | + updatedAt: 1710000030, |
| 68 | + }, |
| 69 | + }, |
| 70 | + }; |
| 71 | + |
| 72 | + await setupPromptAndSendNotifications(mockFixture, sessionId, sessionState, [goalUpdatedNotification]); |
| 73 | + |
| 74 | + await expect(mockFixture.getAcpConnectionDump([])).toMatchFileSnapshot( |
| 75 | + "data/thread-goal-updated-multiline.json" |
| 76 | + ); |
| 77 | + }); |
| 78 | + |
| 79 | + it("should send thread goal cleared as an agent message", async () => { |
| 80 | + const goalClearedNotification: ServerNotification = { |
| 81 | + method: "thread/goal/cleared", |
| 82 | + params: { |
| 83 | + threadId: sessionId, |
| 84 | + }, |
| 85 | + }; |
| 86 | + |
| 87 | + await setupPromptAndSendNotifications(mockFixture, sessionId, sessionState, [goalClearedNotification]); |
| 88 | + |
| 89 | + await expect(mockFixture.getAcpConnectionDump([])).toMatchFileSnapshot( |
| 90 | + "data/thread-goal-cleared.json" |
| 91 | + ); |
| 92 | + }); |
| 93 | +}); |
0 commit comments