- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/src/engine/test/graph-insertion-storage.test.ts?format=json
52 linescodex-capacity-chair 100%Last change codex-capacity-chair in version 162, 1 version changed it
1import assert from "node:assert/strict";
2import { test } from "node:test";
3import { buildBase, Graph } from "../index.ts";
4import { SqlState } from "./storage-helper.ts";
6test("persisted insertion lines stay out of atom metadata", (t) => {
7 const storage = new SqlState();
8 t.after(() => storage.db.close());
9 const text = Array.from({ length: 513 }, (_, i) => `line ${i}\n`).join("");
10 const graph = new Graph({ storage });
11 const atom = buildBase({ "a.txt": text }, { author: "fixture", message: "base", time: 0 });
12 const oracle = new Graph();
13 oracle.add(atom);
14 graph.add(atom);
15 const bytes = Buffer.byteLength(JSON.stringify(storage.read("atoms", "0")));
16 assert.ok(bytes < 2048, `atom metadata retained ${bytes} bytes for 513 insertion lines`);
17 assert.deepEqual([...new Graph({ storage }).atom("a0").inserts[0]!.lines], oracle.atom("a0").inserts[0]!.lines);
18 const read = storage.read.bind(storage);
19 let lineReads = 0;
20 storage.read = (collection, key) => {
21 if (collection === "atom-inserts:0:lines:0") lineReads++;
22 return read(collection, key);
23 };
24 const saved = new Graph({ storage }).atom("a0");
25 assert.equal(lineReads, 0);
26 assert.equal(saved.inserts[0]!.lines.length, 513);
27 assert.equal(lineReads, 0);
28 assert.equal(saved.inserts[0]!.lines[512], oracle.atom("a0").inserts[0]!.lines[512]);
29 assert.equal(lineReads, 1);
30});
32test("partial insertion persistence rolls back and retries on the same graph", (t) => {
33 const storage = new SqlState();
34 t.after(() => storage.db.close());
35 const graph = new Graph({ storage });
36 const atom = buildBase(
37 { "a.txt": Array.from({ length: 513 }, (_, i) => `line ${i}\n`).join("") },
38 { author: "fixture", message: "base", time: 0 },
39 );
40 const before = storage.db.prepare("SELECT * FROM state ORDER BY collection,key").all();
41 const write = storage.write.bind(storage);
42 storage.write = (collection, key, value) => {
43 write(collection, key, value);
44 if (collection === "atom-inserts:0:lines:0" && key === "128") throw Error("injected insertion failure");
45 };
46 assert.throws(() => graph.add(atom), /injected insertion failure/);
47 assert.deepEqual(storage.db.prepare("SELECT * FROM state ORDER BY collection,key").all(), before);
48 assert.equal(graph.size, 0);
49 storage.write = write;
50 graph.add(atom);
51 assert.deepEqual([...new Graph({ storage }).atom("a0").inserts[0]!.lines], atom.inserts[0]!.lines);
52});