{"draft":null,"from":205,"to":206,"files":[{"path":"src/engine/test/packed-files.test.ts","added":56,"removed":0,"diff":"--- /dev/null\n+++ b/src/engine/test/packed-files.test.ts\n@@ -0,0 +1,56 @@\n+// Each file's line history packed (abso Capacity, Graph.packedLines): a stored graph lays files out from a few pages,\n+// and must give exactly what the in-memory graph gives, through edits, deletes, moves between files and back.\n+\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { Graph, View } from \"../index.ts\";\n+import { StableOverlaySet } from \"../state-source.ts\";\n+import { lines, Repo } from \"./helpers.ts\";\n+import { SqlState } from \"./storage-helper.ts\";\n+\n+test(\"a packed file lays out as the in-memory graph does, at every step, moves included\", () => {\n+\tconst oracle = Repo.init({ \"a.txt\": lines(\"one\", \"two\", \"three\", \"four\"), \"b.txt\": lines(\"bee\"), \"c.txt\": \"\" });\n+\tconst sets: Set<string>[] = [new Set(oracle.shared)];\n+\tconst step = (change: Parameters<Repo[\"edit\"]>[0]) => {\n+\t\toracle.edit(change);\n+\t\tsets.push(new Set(oracle.shared));\n+\t};\n+\tstep({ edits: [{ file: \"a.txt\", old: \"two\", new: \"TWO\" }] });\n+\tstep({ move: { file: \"a.txt\", start: 1, end: 3, to: \"b.txt\", at: 1 } });\n+\tstep({ edits: [{ file: \"b.txt\", old: \"TWO\", new: \"two again\" }] });\n+\tstep({ edits: [{ file: \"a.txt\", old: \"four\", new: \"\" }] });\n+\tstep({ move: { file: \"b.txt\", start: 0, end: 2, to: \"c.txt\", at: 0 } });\n+\tstep({ edits: [{ file: \"c.txt\", old: \"bee\", new: \"bee\\nafter bee\" }] });\n+\tconst storage = new SqlState();\n+\ttry {\n+\t\tconst graph = new Graph({ storage });\n+\t\tfor (const atom of oracle.graph.atoms()) graph.add(atom);\n+\t\tconst reopened = new Graph({ storage });\n+\t\tassert.equal(reopened.packedFiles, true);\n+\t\tfor (const [i, set] of sets.entries()) {\n+\t\t\tconst packed = new View(reopened, new StableOverlaySet(set));\n+\t\t\tconst memory = new View(oracle.graph, set);\n+\t\t\tassert.deepEqual(packed.paths(), memory.paths(), `step ${i}: paths`);\n+\t\t\tfor (const path of [\"a.txt\", \"b.txt\", \"c.txt\"]) {\n+\t\t\t\tassert.equal(packed.text(path), memory.text(path), `step ${i}: ${path}`);\n+\t\t\t\tassert.deepEqual(packed.sequence(path), memory.sequence(path), `step ${i}: ${path}'s sequence`);\n+\t\t\t\tassert.deepEqual(packed.attrs(path), memory.attrs(path), `step ${i}: ${path}'s attributes`);\n+\t\t\t}\n+\t\t}\n+\t} finally {\n+\t\tstorage.db.close();\n+\t}\n+});\n+\n+test(\"a graph made with packFiles off keeps no packed history\", () => {\n+\tconst oracle = Repo.init({ \"a.txt\": lines(\"one\") });\n+\tconst storage = new SqlState();\n+\ttry {\n+\t\tconst graph = new Graph({ storage, packFiles: false });\n+\t\tfor (const atom of oracle.graph.atoms()) graph.add(atom);\n+\t\tassert.equal(new Graph({ storage }).packedFiles, false);\n+\t\tassert.equal(new View(new Graph({ storage }), new StableOverlaySet(oracle.shared)).text(\"a.txt\"), \"one\\n\");\n+\t} finally {\n+\t\tstorage.db.close();\n+\t}\n+});"}],"unmatched":[]}