{"draft":null,"from":136,"to":318,"files":[{"path":"src/engine/test/state-source.test.ts","added":57,"removed":8,"diff":"--- a/src/engine/test/state-source.test.ts\n+++ b/src/engine/test/state-source.test.ts\n@@ -5,6 +5,49 @@\n import { lines, Repo } from \"./helpers.ts\";\n import { SqlState } from \"./storage-helper.ts\";\n \n+test(\"counter writes avoid rereads while respecting failed writes, rollback and cache bounds\", () => {\n+\tconst source = new SqlState();\n+\ttry {\n+\t\tconst cache = new CachedStateStorage(source, 512, 2);\n+\t\tconst before = source.reads;\n+\t\tfor (let n = 0; n < 100; n++) {\n+\t\t\tcache.write(\"counter\", \"next\", n);\n+\t\t\tassert.equal(cache.read(\"counter\", \"next\"), n);\n+\t\t\tassert.ok(cache.retainedBytes <= 512);\n+\t\t\tassert.ok(cache.retainedEntries <= 2);\n+\t\t}\n+\t\tassert.equal(source.reads, before);\n+\t\tsource.failWrite = source.writes + 1;\n+\t\tassert.throws(() => cache.write(\"counter\", \"next\", 100), /injected/);\n+\t\tassert.equal(cache.read(\"counter\", \"next\"), 99);\n+\t\tsource.failWrite = Infinity;\n+\t\tassert.throws(\n+\t\t\t() =>\n+\t\t\t\tcache.transaction(() => {\n+\t\t\t\t\tcache.write(\"counter\", \"next\", 101);\n+\t\t\t\t\tassert.equal(cache.read(\"counter\", \"next\"), 101);\n+\t\t\t\t\tthrow Error(\"counter rollback\");\n+\t\t\t\t}),\n+\t\t\t/counter rollback/,\n+\t\t);\n+\t\tassert.equal(cache.retainedEntries, 0);\n+\t\tassert.equal(cache.read(\"counter\", \"next\"), 99);\n+\t\tfor (let n = 0; n < 20; n++) cache.write(\"counter\", String(n), n);\n+\t\tassert.ok(cache.retainedBytes <= 512);\n+\t\tassert.ok(cache.retainedEntries <= 2);\n+\t\tassert.equal(cache.read(\"counter\", \"0\"), 0);\n+\t\tconst disabled = new CachedStateStorage(source, 0, 0);\n+\t\tdisabled.write(\"counter\", \"next\", 102);\n+\t\tassert.equal(disabled.retainedEntries, 0);\n+\t\tassert.equal(disabled.read(\"counter\", \"next\"), 102);\n+\t\tcache.write(\"counter\", \"negative-zero\", -0);\n+\t\tassert.equal(Object.is(cache.read(\"counter\", \"negative-zero\"), source.read(\"counter\", \"negative-zero\")), true);\n+\t} finally {\n+\t\tsource.db.close();\n+\t}\n+});\n+\n+// The line-by-line layout, which a graph adopted before packed file history still uses (packFiles: false).\n test(\"current visibility stops at the first included deletion while history retains every deleter\", () => {\n \tclass ObservedStorage extends SqlState {\n \t\tpageReads = 0;\n@@ -17,7 +60,7 @@\n \ttry {\n \t\tconst oracle = Repo.init({ \"a.txt\": \"gone\\nlive\\n\" });\n \t\tconst deletion = oracle.draft({ edits: [{ file: \"a.txt\", old: \"gone\\n\", new: \"\" }] });\n-\t\tconst graph = new Graph({ storage });\n+\t\tconst graph = new Graph({ storage, packFiles: false });\n \t\tgraph.add(oracle.graph.atom(\"a0\"));\n \t\tconst ids = [\"a0\"];\n \t\tfor (let seq = 1; seq <= 514; seq++) {\n@@ -26,7 +69,7 @@\n \t\t\toracle.graph.add(atom);\n \t\t\tids.push(atom.id);\n \t\t}\n-\t\tconst reopened = new Graph({ storage });\n+\t\tconst reopened = new Graph({ storage, packFiles: false });\n \t\tconst membership = new StableOverlaySet(ids);\n \t\tconst view = new View(reopened, membership);\n \t\tstorage.pageReads = 0;\n@@ -437,9 +480,9 @@\n \t\t\t}\n \t\t\tconst before = oracle.view().text(\"a.txt\");\n \t\t\toracle.edit({ edits: [{ file: \"a.txt\", old: before, new: \"live\\n\" }] });\n-\t\t\tconst graph = new Graph({ storage });\n+\t\t\tconst graph = new Graph({ storage, packFiles: false });\n \t\t\tfor (const id of oracle.shared) graph.add(oracle.graph.atom(id));\n-\t\t\tconst reopened = new Graph({ storage });\n+\t\t\tconst reopened = new Graph({ storage, packFiles: false });\n \t\t\treopened.eachChildN = () => {\n \t\t\t\tthrow Error(\"unordered child collection forbidden\");\n \t\t\t};\n@@ -498,15 +541,21 @@\n \tconst storage = new SqlState();\n \ttry {\n \t\tconst oracle = Repo.init({ \"a.txt\": \"one\\n\" });\n-\t\tconst graph = new Graph({ storage });\n+\t\tconst graph = new Graph({ storage, packFiles: false });\n \t\tgraph.add(oracle.graph.atom(\"a0\"));\n \t\tstorage.remove(\"ordered-children\", \"format\");\n-\t\tassert.throws(() => new View(new Graph({ storage }), new StableOverlaySet([\"a0\"])).text(\"a.txt\"), /fresh adoption/);\n \t\tassert.throws(\n-\t\t\t() => new Graph({ storage }).add(oracle.draft({ edits: [{ file: \"a.txt\", old: \"one\", new: \"two\" }] })),\n+\t\t\t() => new View(new Graph({ storage, packFiles: false }), new StableOverlaySet([\"a0\"])).text(\"a.txt\"),\n \t\t\t/fresh adoption/,\n \t\t);\n-\t\tstorage.write(\"ordered-children\", \"format\", 1);\n+\t\tassert.throws(\n+\t\t\t() =>\n+\t\t\t\tnew Graph({ storage, packFiles: false }).add(\n+\t\t\t\t\toracle.draft({ edits: [{ file: \"a.txt\", old: \"one\", new: \"two\" }] }),\n+\t\t\t\t),\n+\t\t\t/fresh adoption/,\n+\t\t);\n+\t\tstorage.write(\"ordered-children\", \"format\", 2);\n \t\tconst parent = graph.startCodeOf(\"a.txt\")!;\n \t\tstorage.remove(\"ordered-children\", JSON.stringify([String(parent), \"meta\"]));\n \t\tassert.throws(() => [...graph.orderedChildrenN(parent)], /missing ordered index metadata/);"}],"unmatched":[]}