|
1 | 1 | import { VIEW_BLOCK_VERSION } from "@internal/dashboard-agent-contracts"; |
2 | | -import { describe, expect, it } from "vitest"; |
| 2 | +import { afterEach, describe, expect, it, vi } from "vitest"; |
3 | 3 | import { liveProgress } from "./progress-line"; |
4 | 4 | import { |
| 5 | + fetchChatTranscript, |
5 | 6 | hasOpenInvestigation, |
6 | 7 | mergeSettledMessages, |
7 | 8 | pollSettledTranscript, |
@@ -73,6 +74,51 @@ describe("merging a re-read transcript", () => { |
73 | 74 | }); |
74 | 75 | }); |
75 | 76 |
|
| 77 | +describe("reading the transcript endpoint", () => { |
| 78 | + afterEach(() => { |
| 79 | + vi.unstubAllGlobals(); |
| 80 | + }); |
| 81 | + |
| 82 | + function respondWith(body: unknown, ok = true) { |
| 83 | + vi.stubGlobal("fetch", async () => ({ ok, json: async () => body }) as unknown as Response); |
| 84 | + } |
| 85 | + |
| 86 | + it("returns the transcript when the response carries one", async () => { |
| 87 | + respondWith({ messages: [OPEN, SETTLED] }); |
| 88 | + const fetched = await fetchChatTranscript<typeof OPEN>("/agent/transcript", "chat_1"); |
| 89 | + expect(fetched?.map((message) => message.id)).toEqual([OPEN.id, SETTLED.id]); |
| 90 | + }); |
| 91 | + |
| 92 | + it("reads a response with no messages at all as a failed re-read", async () => { |
| 93 | + respondWith({}); |
| 94 | + expect(await fetchChatTranscript("/agent/transcript", "chat_1")).toBeNull(); |
| 95 | + }); |
| 96 | + |
| 97 | + it("reads a non-array under messages as a failed re-read, not as a transcript", async () => { |
| 98 | + respondWith({ messages: { msg_open: OPEN } }); |
| 99 | + expect(await fetchChatTranscript("/agent/transcript", "chat_1")).toBeNull(); |
| 100 | + }); |
| 101 | + |
| 102 | + it("keeps only entries the merge can key on", async () => { |
| 103 | + respondWith({ messages: [OPEN, null, "msg_open", { revision: 1 }, SETTLED] }); |
| 104 | + const fetched = await fetchChatTranscript<typeof OPEN>("/agent/transcript", "chat_1"); |
| 105 | + expect(fetched?.map((message) => message.id)).toEqual([OPEN.id, SETTLED.id]); |
| 106 | + }); |
| 107 | + |
| 108 | + it("leaves the panel's transcript alone when the endpoint answers with a shape it cannot merge", async () => { |
| 109 | + respondWith({ messages: { msg_open: OPEN } }); |
| 110 | + let rendered: (typeof OPEN)[] = [OPEN]; |
| 111 | + |
| 112 | + await pollSettledTranscript<typeof OPEN>({ |
| 113 | + fetchTranscript: () => fetchChatTranscript("/agent/transcript", "chat_1"), |
| 114 | + apply: (merge) => void (rendered = merge(rendered)), |
| 115 | + wait: async () => {}, |
| 116 | + }); |
| 117 | + |
| 118 | + expect(rendered).toEqual([OPEN]); |
| 119 | + }); |
| 120 | +}); |
| 121 | + |
76 | 122 | describe("an already-open panel when a turn is exhausted", () => { |
77 | 123 | it("stops showing Working… without a reload or a reopen", async () => { |
78 | 124 | // What the mounted panel holds when the stream closes: the card the model opened |
|
0 commit comments