{"draft":null,"from":32,"to":318,"files":[{"path":"src/engine/test/graph-metadata-indexed.test.ts","added":58,"removed":0,"diff":"--- /dev/null\n+++ b/src/engine/test/graph-metadata-indexed.test.ts\n@@ -0,0 +1,58 @@\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { Graph } from \"../graph.ts\";\n+import { Repo } from \"./helpers.ts\";\n+import { SqlState } from \"./storage-helper.ts\";\n+\n+test(\"indexed identities and metadata do not decode atom payloads\", () => {\n+\tconst db = new SqlState();\n+\ttry {\n+\t\tconst repo = Repo.init({ \"a.txt\": \"one\\ntwo\\n\" });\n+\t\tconst graph = new Graph({ storage: db });\n+\t\tgraph.add(repo.graph.atom(\"a0\"));\n+\t\tconst read = db.read.bind(db);\n+\t\tdb.read = (collection, key) => {\n+\t\t\tif (collection === \"atoms\") throw Error(\"atom payload read forbidden\");\n+\t\t\treturn read(collection, key);\n+\t\t};\n+\t\tassert.equal(graph.idOfSeq(0), \"a0\");\n+\t\tassert.equal(graph.lamport(\"a0\"), 0);\n+\t\tassert.deepEqual(graph.filesOf(\"a0\"), [\"a.txt\"]);\n+\t\tassert.equal(graph.line(\"a0.0\")?.atom, \"a0\");\n+\t\tassert.equal(graph.lineIdOf(0), \"a0.0\");\n+\t\tfor (const seq of [-1, 1, 0.5, NaN, Infinity]) assert.throws(() => graph.idOfSeq(seq), /no atom/);\n+\t\tfor (const id of [\"a1\", \"a00\", \"a-1\", \"invalid\"]) {\n+\t\t\tassert.throws(() => graph.lamport(id), /no atom/);\n+\t\t\tassert.throws(() => graph.filesOf(id), /no atom/);\n+\t\t}\n+\t\tassert.equal(graph.line(\"a1.0\"), undefined);\n+\t\tassert.throws(() => graph.atom(\"a0\"), /payload read forbidden/);\n+\t} finally {\n+\t\tdb.db.close();\n+\t}\n+});\n+\n+test(\"accepting an edit does not decode historical atoms to canonicalize identities\", () => {\n+\tconst db = new SqlState();\n+\ttry {\n+\t\tconst repo = Repo.init({ \"a.txt\": `first\\n${\"old\\n\".repeat(8191)}` });\n+\t\tconst graph = new Graph({ storage: db });\n+\t\tgraph.add(repo.graph.atom(\"a0\"));\n+\t\tconst edit = repo.edit({ edits: [{ file: \"a.txt\", old: \"first\\n\", new: \"changed\\n\" }] });\n+\t\tassert.ok(edit.deps.includes(\"a0\"));\n+\t\tconst read = db.read.bind(db);\n+\t\tdb.read = (collection, key) => {\n+\t\t\tif (collection === \"atoms\") throw Error(\"historical atom payload read forbidden\");\n+\t\t\treturn read(collection, key);\n+\t\t};\n+\t\tgraph.add(edit);\n+\t\tassert.equal(graph.size, 2);\n+\t\tassert.equal(graph.idOfSeq(1), edit.id);\n+\t\tassert.equal(graph.lamport(edit.id), repo.graph.lamport(edit.id));\n+\t\tassert.deepEqual(graph.filesOf(edit.id), repo.graph.filesOf(edit.id));\n+\t\tdb.read = read;\n+\t\tassert.deepEqual(graph.atom(edit.id), repo.graph.atom(edit.id));\n+\t} finally {\n+\t\tdb.db.close();\n+\t}\n+});"}],"unmatched":[]}