@@ -46,6 +46,16 @@ async function makeRoot(prefix: string): Promise<string> {
|
46 | 46 | return root; |
47 | 47 | } |
48 | 48 | |
| 49 | +function parseJsonLines<T>(raw: string): T[] { |
| 50 | +const records: T[] = []; |
| 51 | +for (const line of raw.trim().split("\n")) { |
| 52 | +if (line.length > 0) { |
| 53 | +records.push(JSON.parse(line) as T); |
| 54 | +} |
| 55 | +} |
| 56 | +return records; |
| 57 | +} |
| 58 | + |
49 | 59 | describe("mirrorCodexAppServerTranscript", () => { |
50 | 60 | it("mirrors user and assistant messages into the Pi transcript", async () => { |
51 | 61 | const sessionFile = await createTempSessionFile(); |
@@ -123,11 +133,9 @@ describe("mirrorCodexAppServerTranscript", () => {
|
123 | 133 | idempotencyScope: "scope-1", |
124 | 134 | }); |
125 | 135 | |
126 | | -const records = (await fs.readFile(sessionFile, "utf8")) |
127 | | -.trim() |
128 | | -.split("\n") |
129 | | -.filter(Boolean) |
130 | | -.map((line) => JSON.parse(line) as { type?: string; message?: { role?: string } }); |
| 136 | +const records = parseJsonLines<{ type?: string; message?: { role?: string } }>( |
| 137 | +await fs.readFile(sessionFile, "utf8"), |
| 138 | +); |
131 | 139 | expect(records.slice(1)).toHaveLength(2); |
132 | 140 | }); |
133 | 141 | |
@@ -290,11 +298,7 @@ describe("mirrorCodexAppServerTranscript", () => {
|
290 | 298 | message?: { role?: string; content?: Array<{ text?: string }> }; |
291 | 299 | }; |
292 | 300 | function readFileMessages(raw: string): Array<{ role?: string; text?: string }> { |
293 | | -return raw |
294 | | -.trim() |
295 | | -.split("\n") |
296 | | -.filter(Boolean) |
297 | | -.map((line) => JSON.parse(line) as FileMessage) |
| 301 | +return parseJsonLines<FileMessage>(raw) |
298 | 302 | .filter((record) => record.type === "message") |
299 | 303 | .map((record) => ({ |
300 | 304 | role: record.message?.role, |
|