Versions 18 to 318
new file, 46 lines
1+import assert from "node:assert/strict"; 2+import { test } from "node:test"; 3+import { buildBase, Graph } from "../index.ts"; 4+import { lineKey } from "../keys.ts"; 5+import type { Atom } from "../types.ts"; 6+import { SqlState } from "./storage-helper.ts"; 8+test("partial atom-list persistence rolls back and retries on the same graph", () => { 9+ const storage = new SqlState(); 11+ const graph = new Graph({ storage }); 12+ graph.add(buildBase({ "a.txt": "base" }, { author: "fixture", message: "base", time: 0 })); 13+ const keys = Array.from({ length: 257 }, () => lineKey("a0.0")); 30+ const before = storage.db.prepare("SELECT * FROM state ORDER BY collection,key").all(); 31+ const write = storage.write.bind(storage); 32+ storage.write = (collection, key, value) => { 33+ write(collection, key, value); 34+ // Partway through: the second of the list's two pages (256 values to a page). 35+ if (collection === "atom-list:1:writes:pages" && key === "1") throw Error("injected list persistence failure"); 37+ assert.throws(() => graph.add(atom), /injected list persistence failure/); 38+ assert.deepEqual(storage.db.prepare("SELECT * FROM state ORDER BY collection,key").all(), before); 39+ assert.equal(graph.size, 1); 40+ storage.write = write; 42+ assert.deepEqual([...new Graph({ storage }).atom("a1").writes], keys);