Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 5 to 318

Compare

+52 −0 in 1 place
new file, 52 lines
1+import assert from "node:assert/strict";
2+import { test } from "node:test";
3+import { buildBase, Graph } from "../index.ts";
4+import { SqlState } from "./storage-helper.ts";
5+
6+test("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+});
32+test("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+});
MCP
compare on this site's /mcp
CLI
abso diff 5 318 src/engine/test/graph-insertion-storage.test.ts --json
JSON
/christopher/abso-core/compare/5..318?file=src%2Fengine%2Ftest%2Fgraph-insertion-storage.test.ts&format=json