{"draft":null,"from":151,"to":318,"files":[{"path":"src/engine/test/projection-marker.test.ts","added":69,"removed":0,"diff":"--- a/src/engine/test/projection-marker.test.ts\n+++ b/src/engine/test/projection-marker.test.ts\n@@ -6,6 +6,28 @@\n import { Repo } from \"./helpers.ts\";\n import { SqlState } from \"./storage-helper.ts\";\n \n+test(\"projection apply and removal compare atom contents without whole-atom JSON\", (t) => {\n+\tconst storage = new SqlState();\n+\tt.after(() => storage.db.close());\n+\tconst repo = Repo.init({ \"f.txt\": `${\"x\".repeat(40000)}\\n` });\n+\tconst atom = repo.graph.atom(\"a0\");\n+\tconst projection = new MarkerProjection(storage, repo.graph, \"f.txt\", \"streamed-comparison\");\n+\tconst stringify = JSON.stringify;\n+\tt.mock.method(JSON, \"stringify\", (...args: Parameters<typeof JSON.stringify>) => {\n+\t\tassert.notEqual(args[0], atom, \"projection validation must not serialize the full atom\");\n+\t\treturn stringify(...args);\n+\t});\n+\tconst state = projection.apply(projection.empty(), atom);\n+\tconst before = storage.writes;\n+\tconst altered = { ...atom, message: \"forged\" };\n+\tassert.throws(() => projection.apply(state, altered), /canonical atom mismatch/);\n+\tassert.throws(() => projection.removeAtom(state, altered), /canonical atom mismatch/);\n+\tassert.equal(storage.writes, before);\n+\tconst removed = projection.removeAtom(state, atom);\n+\tassert.deepEqual(projection.lines(removed, \"f.txt\"), []);\n+\tassert.equal(projection.lines(state, \"f.txt\").length, 1);\n+});\n+\n test(\"typed marker projection matches mixed multi-file edits and reverse removals\", () => {\n \tconst db = new SqlState();\n \ttry {\n@@ -118,3 +140,50 @@\n \t\tstorage.db.close();\n \t}\n });\n+\n+test(\"visibility batches roll back earlier batches and retry with exact line parity\", (t) => {\n+\tconst db = new SqlState();\n+\tt.after(() => db.db.close());\n+\tconst text = Array.from({ length: 35 }, (_, n) => `line ${n}\\n`).join(\"\");\n+\tconst repo = Repo.init({ \"f.txt\": text });\n+\tconst graph = new Graph({ storage: new CachedStateStorage(db) });\n+\tgraph.add(repo.graph.atom(\"a0\"));\n+\tconst p = new MarkerProjection(db, graph, \"f.txt\", \"batch-failure\");\n+\tconst initial = p.apply(p.empty(), repo.graph.atom(\"a0\"));\n+\tconst originalLines = p.lines(initial, \"f.txt\");\n+\tconst atom = repo.edit({ edits: [{ file: \"f.txt\", old: text, new: \"\" }] });\n+\tgraph.add(atom);\n+\tconst rows = () => db.db.prepare(\"SELECT * FROM state ORDER BY collection,key\").all();\n+\tconst before = rows();\n+\tconst original = p.sequence.updateMany.bind(p.sequence);\n+\tconst sizes: number[] = [];\n+\tlet fail = true;\n+\tt.mock.method(\n+\t\tp.sequence,\n+\t\t\"updateMany\",\n+\t\t(state: Parameters<typeof original>[0], operations: Parameters<typeof original>[1]) => {\n+\t\t\tconst next = original(state, operations);\n+\t\t\tif (operations.every((op) => op.kind === \"visibility\")) {\n+\t\t\t\tsizes.push(operations.length);\n+\t\t\t\tif (fail && sizes.length === 2) throw Error(\"second visibility batch failure\");\n+\t\t\t}\n+\t\t\treturn next;\n+\t\t},\n+\t);\n+\tassert.throws(() => p.apply(initial, atom), /second visibility batch/);\n+\tassert.deepEqual(sizes, [16, 16]);\n+\tassert.deepEqual(rows(), before);\n+\tassert.deepEqual(p.lines(initial, \"f.txt\"), originalLines);\n+\tfail = false;\n+\tsizes.length = 0;\n+\tconst next = p.apply(initial, atom);\n+\tassert.deepEqual(sizes, [16, 16, 3]);\n+\tassert.deepEqual(\n+\t\tp.lines(next, \"f.txt\"),\n+\t\trepo\n+\t\t\t.view()\n+\t\t\t.lines(\"f.txt\")\n+\t\t\t.map((line) => line.id),\n+\t);\n+\tassert.deepEqual(p.lines(initial, \"f.txt\"), originalLines);\n+});"}],"unmatched":[]}