|
1 | 1 | // Agent Core tests cover jsonl storage behavior. |
2 | 2 | import { describe, expect, it } from "vitest"; |
| 3 | +import { NodeExecutionEnv } from "../env/nodejs.js"; |
3 | 4 | import { ok, type FileSystem } from "../types.js"; |
4 | 5 | import { JsonlSessionStorage, loadJsonlSessionMetadata } from "./jsonl-storage.js"; |
5 | 6 | import { Session } from "./session.js"; |
@@ -57,6 +58,55 @@ describe("JsonlSessionStorage timestamps", () => { |
57 | 58 | ); |
58 | 59 | }); |
59 | 60 |
|
| 61 | + it("reports physical entry line numbers when blank JSONL rows are skipped", async () => { |
| 62 | + const header = JSON.stringify({ |
| 63 | + type: "session", |
| 64 | + version: 3, |
| 65 | + id: "session-1", |
| 66 | + timestamp: "2026-01-01T00:00:00.000Z", |
| 67 | + cwd: "/repo", |
| 68 | + }); |
| 69 | + const entry = JSON.stringify({ |
| 70 | + type: "custom", |
| 71 | + id: "entry-1", |
| 72 | + parentId: null, |
| 73 | + timestamp: "2026-01-01T00:00:01.000Z", |
| 74 | + customType: "note", |
| 75 | + }); |
| 76 | + const invalidContent = [header, "\t\r", "", entry, " ", "not-json", ""].join("\n"); |
| 77 | + const validContent = [header, "\t\r", "", entry, " ", ""].join("\n"); |
| 78 | + const rootEnv = new NodeExecutionEnv({ cwd: process.cwd() }); |
| 79 | + const created = await rootEnv.createTempDir("agent-core-jsonl-"); |
| 80 | + if (!created.ok) { |
| 81 | + throw created.error; |
| 82 | + } |
| 83 | + const fs = new NodeExecutionEnv({ cwd: created.value }); |
| 84 | + |
| 85 | + try { |
| 86 | + const invalidWrite = await fs.writeFile("invalid-entry.jsonl", invalidContent); |
| 87 | + if (!invalidWrite.ok) { |
| 88 | + throw invalidWrite.error; |
| 89 | + } |
| 90 | + await expect(JsonlSessionStorage.open(fs, "invalid-entry.jsonl")).rejects.toMatchObject({ |
| 91 | + name: "SessionError", |
| 92 | + code: "invalid_entry", |
| 93 | + message: "Invalid JSONL session file invalid-entry.jsonl: line 6 is not valid JSON", |
| 94 | + }); |
| 95 | + |
| 96 | + const validWrite = await fs.writeFile("valid.jsonl", validContent); |
| 97 | + if (!validWrite.ok) { |
| 98 | + throw validWrite.error; |
| 99 | + } |
| 100 | + const storage = await JsonlSessionStorage.open(fs, "valid.jsonl"); |
| 101 | + expect((await storage.getEntries()).map((storedEntry) => storedEntry.id)).toEqual([ |
| 102 | + "entry-1", |
| 103 | + ]); |
| 104 | + } finally { |
| 105 | + const removed = await rootEnv.remove(created.value, { recursive: true, force: true }); |
| 106 | + expect(removed.ok).toBe(true); |
| 107 | + } |
| 108 | + }); |
| 109 | + |
60 | 110 | it("uses a leaf control's opaque append parent for the next entry", async () => { |
61 | 111 | let content = [ |
62 | 112 | { |
|
0 commit comments