@@ -14,6 +14,27 @@ function readTranscriptLines(transcriptPath: string): string[] {
|
14 | 14 | return lines; |
15 | 15 | } |
16 | 16 | |
| 17 | +async function appendHelloAndRequireId(transcriptPath: string): Promise<string> { |
| 18 | +const appended = await appendInjectedAssistantMessageToTranscript({ |
| 19 | + transcriptPath, |
| 20 | +message: "hello", |
| 21 | +}); |
| 22 | +expect(appended.ok).toBe(true); |
| 23 | +expect(appended.messageId).toBeTypeOf("string"); |
| 24 | +const messageId = appended.messageId; |
| 25 | +if (!messageId) { |
| 26 | +throw new Error("expected appended message id"); |
| 27 | +} |
| 28 | +expect(messageId.length).toBeGreaterThan(0); |
| 29 | +return messageId; |
| 30 | +} |
| 31 | + |
| 32 | +function readLastTranscriptRecord(transcriptPath: string): Record<string, unknown> { |
| 33 | +const lines = readTranscriptLines(transcriptPath); |
| 34 | +expect(lines.length).toBeGreaterThanOrEqual(2); |
| 35 | +return JSON.parse(lines.at(-1) as string) as Record<string, unknown>; |
| 36 | +} |
| 37 | + |
17 | 38 | // Guardrail: Gateway-injected assistant transcript messages must attach to the |
18 | 39 | // current leaf with a `parentId` and must not sever compaction history. |
19 | 40 | describe("gateway chat.inject transcript writes", () => { |
@@ -24,22 +45,8 @@ describe("gateway chat.inject transcript writes", () => {
|
24 | 45 | }); |
25 | 46 | |
26 | 47 | try { |
27 | | -const appended = await appendInjectedAssistantMessageToTranscript({ |
28 | | - transcriptPath, |
29 | | -message: "hello", |
30 | | -}); |
31 | | -expect(appended.ok).toBe(true); |
32 | | -expect(appended.messageId).toBeTypeOf("string"); |
33 | | -const messageId = appended.messageId; |
34 | | -if (!messageId) { |
35 | | -throw new Error("expected appended message id"); |
36 | | -} |
37 | | -expect(messageId.length).toBeGreaterThan(0); |
38 | | - |
39 | | -const lines = readTranscriptLines(transcriptPath); |
40 | | -expect(lines.length).toBeGreaterThanOrEqual(2); |
41 | | - |
42 | | -const last = JSON.parse(lines.at(-1) as string) as Record<string, unknown>; |
| 48 | +await appendHelloAndRequireId(transcriptPath); |
| 49 | +const last = readLastTranscriptRecord(transcriptPath); |
43 | 50 | expect(last.type).toBe("message"); |
44 | 51 | |
45 | 52 | // The regression we saw: raw jsonl appends omitted this field entirely. |
@@ -71,20 +78,8 @@ describe("gateway chat.inject transcript writes", () => {
|
71 | 78 | "utf-8", |
72 | 79 | ); |
73 | 80 | |
74 | | -const appended = await appendInjectedAssistantMessageToTranscript({ |
75 | | - transcriptPath, |
76 | | -message: "hello", |
77 | | -}); |
78 | | -expect(appended.ok).toBe(true); |
79 | | -expect(appended.messageId).toBeTypeOf("string"); |
80 | | -const messageId = appended.messageId; |
81 | | -if (!messageId) { |
82 | | -throw new Error("expected appended message id"); |
83 | | -} |
84 | | -expect(messageId.length).toBeGreaterThan(0); |
85 | | - |
86 | | -const lines = readTranscriptLines(transcriptPath); |
87 | | -const last = JSON.parse(lines.at(-1) as string) as Record<string, unknown>; |
| 81 | +const messageId = await appendHelloAndRequireId(transcriptPath); |
| 82 | +const last = readLastTranscriptRecord(transcriptPath); |
88 | 83 | |
89 | 84 | expect(last.type).toBe("message"); |
90 | 85 | expect(last).toHaveProperty("id", messageId); |
|