{"draft":null,"from":72,"to":318,"files":[{"path":"src/engine/test/graph-validation-scratch.test.ts","added":47,"removed":0,"diff":"--- /dev/null\n+++ b/src/engine/test/graph-validation-scratch.test.ts\n@@ -0,0 +1,47 @@\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { buildBase, Graph } from \"../index.ts\";\n+import type { Atom } from \"../types.ts\";\n+import { SqlState } from \"./storage-helper.ts\";\n+\n+test(\"persistent atom validation uses rollback scratch for memberships\", () => {\n+\tconst storage = new SqlState();\n+\ttry {\n+\t\tconst graph = new Graph({ storage });\n+\t\tgraph.add(buildBase({ \"a.txt\": \"base\" }, { author: \"fixture\", message: \"base\", time: 0 }));\n+\t\tconst atom: Atom = {\n+\t\t\tid: \"a1\",\n+\t\t\tseq: 1,\n+\t\t\tauthor: \"fixture\",\n+\t\t\tmessage: \"next\",\n+\t\t\ttime: 1,\n+\t\t\tinserts: [],\n+\t\t\tdeletes: [],\n+\t\t\twrites: [],\n+\t\t\treads: [],\n+\t\t\tholds: [],\n+\t\t\tneeds: [],\n+\t\t\tresolves: [],\n+\t\t\treasons: [],\n+\t\t\tdeps: [\"a0\"],\n+\t\t};\n+\t\tconst before = storage.db.prepare(\"SELECT * FROM state ORDER BY collection,key\").all();\n+\t\tassert.throws(() => graph.add({ ...atom, deps: [\"a0\", \"a0\"] }), /listed twice/);\n+\t\tassert.deepEqual(storage.db.prepare(\"SELECT * FROM state ORDER BY collection,key\").all(), before);\n+\t\tlet scratchWrites = 0;\n+\t\tconst write = storage.write.bind(storage);\n+\t\tstorage.write = (collection, key, value) => {\n+\t\t\tif (collection.startsWith(\"projection-scratch:\") && collection.endsWith(\":deps\")) scratchWrites++;\n+\t\t\twrite(collection, key, value);\n+\t\t};\n+\t\tgraph.add(atom);\n+\t\tassert.ok(scratchWrites > 0);\n+\t\tassert.equal(\n+\t\t\tstorage.db.prepare(\"SELECT COUNT(*) AS n FROM state WHERE collection LIKE 'projection-scratch:%'\").get()!.n,\n+\t\t\t0,\n+\t\t);\n+\t\tassert.equal(new Graph({ storage }).size, 2);\n+\t} finally {\n+\t\tstorage.db.close();\n+\t}\n+});"}],"unmatched":[]}