Lines 5–53 at 318 (were 5–10 at 133)
55import { lines, Repo } from "./helpers.ts"; 66import { SqlState } from "./storage-helper.ts"; 8+test("counter writes avoid rereads while respecting failed writes, rollback and cache bounds", () => { 9+ const source = new SqlState(); 11+ const cache = new CachedStateStorage(source, 512, 2); 12+ const before = source.reads; 13+ for (let n = 0; n < 100; n++) { 14+ cache.write("counter", "next", n); 15+ assert.equal(cache.read("counter", "next"), n); 16+ assert.ok(cache.retainedBytes <= 512); 17+ assert.ok(cache.retainedEntries <= 2); 19+ assert.equal(source.reads, before); 20+ source.failWrite = source.writes + 1; 21+ assert.throws(() => cache.write("counter", "next", 100), /injected/); 22+ assert.equal(cache.read("counter", "next"), 99); 23+ source.failWrite = Infinity; 26+ cache.transaction(() => { 27+ cache.write("counter", "next", 101); 28+ assert.equal(cache.read("counter", "next"), 101); 29+ throw Error("counter rollback"); 33+ assert.equal(cache.retainedEntries, 0); 34+ assert.equal(cache.read("counter", "next"), 99); 35+ for (let n = 0; n < 20; n++) cache.write("counter", String(n), n); 36+ assert.ok(cache.retainedBytes <= 512); 37+ assert.ok(cache.retainedEntries <= 2); 38+ assert.equal(cache.read("counter", "0"), 0); 39+ const disabled = new CachedStateStorage(source, 0, 0); 40+ disabled.write("counter", "next", 102); 41+ assert.equal(disabled.retainedEntries, 0); 42+ assert.equal(disabled.read("counter", "next"), 102); 43+ cache.write("counter", "negative-zero", -0); 44+ assert.equal(Object.is(cache.read("counter", "negative-zero"), source.read("counter", "negative-zero")), true); 50+// The line-by-line layout, which a graph adopted before packed file history still uses (packFiles: false). 851test("current visibility stops at the first included deletion while history retains every deleter", () => { 952 class ObservedStorage extends SqlState { Lines 60–66 at 318 (were 17–23 at 133)
1861 const oracle = Repo.init({ "a.txt": "gone\nlive\n" }); 1962 const deletion = oracle.draft({ edits: [{ file: "a.txt", old: "gone\n", new: "" }] }); 20− const graph = new Graph({ storage });
63+ const graph = new Graph({ storage, packFiles: false }); 2164 graph.add(oracle.graph.atom("a0")); 2366 for (let seq = 1; seq <= 514; seq++) { Lines 69–75 at 318 (were 26–32 at 133)
2669 oracle.graph.add(atom); 29− const reopened = new Graph({ storage });
72+ const reopened = new Graph({ storage, packFiles: false }); 3073 const membership = new StableOverlaySet(ids); 3174 const view = new View(reopened, membership); 3275 storage.pageReads = 0; Lines 480–488 at 318 (were 437–445 at 133)
438481 const before = oracle.view().text("a.txt"); 439482 oracle.edit({ edits: [{ file: "a.txt", old: before, new: "live\n" }] }); 440− const graph = new Graph({ storage });
483+ const graph = new Graph({ storage, packFiles: false }); 441484 for (const id of oracle.shared) graph.add(oracle.graph.atom(id)); 442− const reopened = new Graph({ storage });
485+ const reopened = new Graph({ storage, packFiles: false }); 443486 reopened.eachChildN = () => { 444487 throw Error("unordered child collection forbidden"); Lines 512–561 at 318 (were 469–487 at 133)
515+test("implicit ordered successors avoid priority reads but retain index validation", () => { 516+ class ObservedStorage extends SqlState { 518+ override read(collection: string, key: string): unknown { 519+ if (collection === "lamport" || collection.startsWith("replacing:")) this.priorityReads++; 520+ return super.read(collection, key); 523+ const storage = new ObservedStorage(); 525+ const oracle = Repo.init({ "a.txt": "one\ntwo\nthree\n" }); 526+ const graph = new Graph({ storage }); 527+ graph.add(oracle.graph.atom("a0")); 528+ storage.priorityReads = 0; 529+ assert.deepEqual([...graph.orderedChildrenN(0)], [1]); 530+ assert.deepEqual([...graph.orderedChildrenN(0, 1)], []); 531+ assert.deepEqual([...graph.orderedChildrenN(2)], []); 532+ assert.equal(storage.priorityReads, 0, "single-child traversal does not decode sort priority"); 533+ storage.remove("ordered-children", "format"); 534+ assert.throws(() => [...graph.orderedChildrenN(0)], /fresh adoption/); 472540test("ordered layout refuses missing format or child metadata instead of dropping history", () => { 473541 const storage = new SqlState(); 475543 const oracle = Repo.init({ "a.txt": "one\n" }); 476− const graph = new Graph({ storage });
544+ const graph = new Graph({ storage, packFiles: false }); 477545 graph.add(oracle.graph.atom("a0")); 478546 storage.remove("ordered-children", "format"); 479− assert.throws(() => new View(new Graph({ storage }), new StableOverlaySet(["a0"])).text("a.txt"), /fresh adoption/);
481− () => new Graph({ storage }).add(oracle.draft({ edits: [{ file: "a.txt", old: "one", new: "two" }] })),
548+ () => new View(new Graph({ storage, packFiles: false }), new StableOverlaySet(["a0"])).text("a.txt"), 484− storage.write("ordered-children", "format", 1);
553+ new Graph({ storage, packFiles: false }).add( 554+ oracle.draft({ edits: [{ file: "a.txt", old: "one", new: "two" }] }), 558+ storage.write("ordered-children", "format", 2); 485559 const parent = graph.startCodeOf("a.txt")!; 486560 storage.remove("ordered-children", JSON.stringify([String(parent), "meta"])); 487561 assert.throws(() => [...graph.orderedChildrenN(parent)], /missing ordered index metadata/);