Lines 5–53 at 318 (were 5–10 at 140)
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 140)
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 140)
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 140)
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 541–560 at 318 (were 498–511 at 140)
498541 const storage = new SqlState(); 500543 const oracle = Repo.init({ "a.txt": "one\n" }); 501− const graph = new Graph({ storage });
544+ const graph = new Graph({ storage, packFiles: false }); 502545 graph.add(oracle.graph.atom("a0")); 503546 storage.remove("ordered-children", "format"); 504− assert.throws(() => new View(new Graph({ storage }), new StableOverlaySet(["a0"])).text("a.txt"), /fresh adoption/);
506− () => 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"), 553+ new Graph({ storage, packFiles: false }).add( 554+ oracle.draft({ edits: [{ file: "a.txt", old: "one", new: "two" }] }), 509558 storage.write("ordered-children", "format", 2); 510559 const parent = graph.startCodeOf("a.txt")!; 511560 storage.remove("ordered-children", JSON.stringify([String(parent), "meta"]));