|
| 1 | +import { describe, expect, it, vi } from "vitest"; |
| 2 | +import type { ServerNotification } from "../../app-server"; |
| 3 | +import { setupPromptTestSession } from "../acp-test-utils"; |
| 4 | + |
| 5 | +describe("CodexEventHandler - session info updates", () => { |
| 6 | + const sessionId = "test-session-id"; |
| 7 | + |
| 8 | + it("maps thread name updates to ACP session info updates", async () => { |
| 9 | + const { mockFixture } = setupPromptTestSession({ sessionId }); |
| 10 | + |
| 11 | + await mockFixture.getCodexAcpAgent().prompt({ |
| 12 | + sessionId, |
| 13 | + prompt: [{ type: "text", text: "test" }], |
| 14 | + }); |
| 15 | + |
| 16 | + mockFixture.clearAcpConnectionDump(); |
| 17 | + |
| 18 | + const notifications: ServerNotification[] = [ |
| 19 | + { |
| 20 | + method: "thread/name/updated", |
| 21 | + params: { |
| 22 | + threadId: sessionId, |
| 23 | + threadName: "Renamed session", |
| 24 | + }, |
| 25 | + }, |
| 26 | + { |
| 27 | + method: "thread/name/updated", |
| 28 | + params: { |
| 29 | + threadId: sessionId, |
| 30 | + }, |
| 31 | + }, |
| 32 | + ]; |
| 33 | + |
| 34 | + for (const notification of notifications) { |
| 35 | + mockFixture.sendServerNotification(notification); |
| 36 | + } |
| 37 | + |
| 38 | + await vi.waitFor(() => { |
| 39 | + expect(mockFixture.getAcpConnectionEvents([])).toHaveLength(2); |
| 40 | + }); |
| 41 | + |
| 42 | + await expect(`${mockFixture.getAcpConnectionDump([])}\n`).toMatchFileSnapshot( |
| 43 | + "data/session-info-update-title.json" |
| 44 | + ); |
| 45 | + }); |
| 46 | + |
| 47 | + it("maps Codex thread lifecycle metadata to ACP session info updates", async () => { |
| 48 | + const { mockFixture } = setupPromptTestSession({ sessionId }); |
| 49 | + |
| 50 | + await mockFixture.getCodexAcpAgent().prompt({ |
| 51 | + sessionId, |
| 52 | + prompt: [{ type: "text", text: "test" }], |
| 53 | + }); |
| 54 | + |
| 55 | + mockFixture.clearAcpConnectionDump(); |
| 56 | + |
| 57 | + const notifications: ServerNotification[] = [ |
| 58 | + { |
| 59 | + method: "thread/status/changed", |
| 60 | + params: { |
| 61 | + threadId: sessionId, |
| 62 | + status: { |
| 63 | + type: "active", |
| 64 | + activeFlags: ["waitingOnApproval"], |
| 65 | + }, |
| 66 | + }, |
| 67 | + }, |
| 68 | + { |
| 69 | + method: "thread/archived", |
| 70 | + params: { |
| 71 | + threadId: sessionId, |
| 72 | + }, |
| 73 | + }, |
| 74 | + { |
| 75 | + method: "thread/unarchived", |
| 76 | + params: { |
| 77 | + threadId: sessionId, |
| 78 | + }, |
| 79 | + }, |
| 80 | + { |
| 81 | + method: "thread/closed", |
| 82 | + params: { |
| 83 | + threadId: sessionId, |
| 84 | + }, |
| 85 | + }, |
| 86 | + ]; |
| 87 | + |
| 88 | + for (const notification of notifications) { |
| 89 | + mockFixture.sendServerNotification(notification); |
| 90 | + } |
| 91 | + |
| 92 | + await vi.waitFor(() => { |
| 93 | + expect(mockFixture.getAcpConnectionEvents([])).toHaveLength(4); |
| 94 | + }); |
| 95 | + |
| 96 | + await expect(`${mockFixture.getAcpConnectionDump([])}\n`).toMatchFileSnapshot( |
| 97 | + "data/session-info-update-metadata.json" |
| 98 | + ); |
| 99 | + }); |
| 100 | +}); |
0 commit comments