{"draft":null,"from":32,"to":318,"files":[{"path":"server/test/decoded-entry-adoption.test.ts","added":62,"removed":0,"diff":"--- /dev/null\n+++ b/server/test/decoded-entry-adoption.test.ts\n@@ -0,0 +1,62 @@\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { SqlState } from \"../../src/engine/test/storage-helper.ts\";\n+import { MemoryStore, Project } from \"../../worker/project/project.ts\";\n+import type { Entry } from \"../../worker/project/project-types.ts\";\n+import { StoredJson, storeJson } from \"../src/stored-json.ts\";\n+import { storedJsonView } from \"../src/stored-json-view.ts\";\n+\n+test(\"Project adopts disk-backed decoded entries with replay parity and source fencing\", (t) => {\n+\tconst storage = new SqlState();\n+\tt.after(() => storage.db.close());\n+\tconst log = new MemoryStore();\n+\tconst oracle = new Project(log);\n+\toracle.init({ \"a.txt\": \"old\\n\" }, 0);\n+\toracle.record(\"alice\", { \"a.txt\": \"new\\n\" }, 1);\n+\toracle.publish(\"alice\", \"edit\", 2);\n+\tconst source = { generation: 1, logLength: log.entries.length, sharedVersion: oracle.version };\n+\tconst frames = log.entries.map((entry, seq) => {\n+\t\tconst json = JSON.stringify(entry);\n+\t\tconst namespace = `decoded:${seq}`;\n+\t\tstoreJson(\n+\t\t\tstorage,\n+\t\t\tnamespace,\n+\t\t\t(function* () {\n+\t\t\t\tfor (let i = 0; i < json.length; i += 11) yield json.slice(i, i + 11);\n+\t\t\t})(),\n+\t\t);\n+\t\treturn { seq, bytes: Buffer.byteLength(json), entry: storedJsonView(new StoredJson(storage, namespace)) as Entry };\n+\t});\n+\tconst before = storage.db.prepare(\"SELECT * FROM state ORDER BY collection,key\").all();\n+\tlet checks = 0;\n+\tassert.throws(\n+\t\t() =>\n+\t\t\tProject.adoptWriterPage(storage, {\n+\t\t\t\tsource,\n+\t\t\t\tfrom: 0,\n+\t\t\t\tframes,\n+\t\t\t\tmaxEntries: 32,\n+\t\t\t\tmaxBytes: 100000,\n+\t\t\t\tcurrentSource: () => (++checks === 1 ? source : { ...source, generation: 2 }),\n+\t\t\t}),\n+\t\t/source changed during/,\n+\t);\n+\tassert.deepEqual(storage.db.prepare(\"SELECT * FROM state ORDER BY collection,key\").all(), before);\n+\tt.mock.method(Project, \"load\", () => {\n+\t\tthrow Error(\"full history load forbidden\");\n+\t});\n+\tassert.equal(\n+\t\tProject.adoptWriterPage(storage, {\n+\t\t\tsource,\n+\t\t\tfrom: 0,\n+\t\t\tframes,\n+\t\t\tmaxEntries: 32,\n+\t\t\tmaxBytes: 100000,\n+\t\t\tcurrentSource: () => source,\n+\t\t}).ready,\n+\t\ttrue,\n+\t);\n+\tconst reopened = Project.openWriter(log, storage, log.entries.length);\n+\tassert.deepEqual(reopened.files(), oracle.files());\n+\tassert.deepEqual(reopened.status(), oracle.status());\n+});"}],"unmatched":[]}