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 116 to 318

Compare

+100 −0 in 1 place
new file, 100 lines
1+import assert from "node:assert/strict";
2+import { test } from "node:test";
3+import { MemoryStore, Project } from "../../../worker/project/project.ts";
4+import { Graph } from "../graph.ts";
5+import { SqlState } from "./storage-helper.ts";
6+
7+test("large insertion text stays lazy even when the run has few lines", (t) => {
8+ const storage = new SqlState();
9+ t.after(() => storage.db.close());
10+ const memory = new MemoryStore();
11+ const line = "x".repeat(100000);
12+ new Project(memory).init({ "a.txt": `${line}\n${line}\n${line}\n` }, 0);
13+ const entry = memory.entries[0]!;
14+ if (entry.type !== "init") throw Error("expected init");
15+ new Graph({ storage }).add(entry.atom);
16+ const read = storage.read.bind(storage);
17+ let textReads = 0;
18+ t.mock.method(storage, "read", (collection: string, key: string) => {
19+ if (collection === "atom-text:long:chunks") textReads++;
20+ return read(collection, key);
21+ });
22+ const atom = new Graph({ storage }).atom("a0");
23+ assert.equal(atom.inserts[0]!.lines.length, 3);
24+ assert.equal(textReads, 0, "reading line count must not decode the complete run");
25+ assert.equal(atom.inserts[0]!.lines[1], line);
26+ assert.equal(textReads, Math.ceil(line.length / 16384), "an indexed read decodes only the selected line");
27+});
29+test("persistent graph stores long lines in chunks and reopens exact text", () => {
30+ const storage = new SqlState();
31+ try {
32+ const memory = new MemoryStore();
33+ const value = `${"x".repeat(100000)}\uD83D\uDE00`;
34+ new Project(memory).init({ "a.txt": value }, 0);
35+ const entry = memory.entries[0]!;
36+ assert.equal(entry.type, "init");
37+ if (entry.type !== "init") throw Error("expected init");
38+ new Graph({ storage }).add(entry.atom);
39+ assert.deepEqual(storage.read("line-text", "0"), { format: 1, text: JSON.stringify(["0", 0]) });
40+ assert.equal(new Graph({ storage }).lineText("a0.0"), value);
41+ assert.ok(
42+ (storage.db.prepare("SELECT COUNT(*) AS n FROM state WHERE collection = 'atom-text:long:chunks'").get()!
43+ .n as number) > 1,
44+ );
45+ } finally {
46+ storage.db.close();
47+ }
48+});
50+test("long atom acceptance rolls back partial chunks and detects missing text", (t) => {
51+ const storage = new SqlState();
52+ t.after(() => storage.db.close());
53+ const memory = new MemoryStore();
54+ const value = "z".repeat(100000);
55+ new Project(memory).init({ "a.txt": value }, 0);
56+ const entry = memory.entries[0]!;
57+ if (entry.type !== "init") throw Error("expected init");
58+ const graph = new Graph({ storage });
59+ const rows = () => storage.db.prepare("SELECT * FROM state ORDER BY collection,key").all();
60+ const before = rows();
61+ const write = storage.write.bind(storage);
62+ let chunks = 0;
63+ const failure = t.mock.method(storage, "write", (collection: string, key: string, value: unknown) => {
64+ write(collection, key, value);
65+ if (collection === "atom-text:long:chunks" && ++chunks === 2) throw Error("injected partial atom text");
66+ });
67+ assert.throws(() => graph.add(entry.atom), /partial atom text/);
68+ assert.deepEqual(rows(), before);
69+ assert.equal(graph.size, 0);
70+ failure.mock.restore();
71+ graph.add(entry.atom);
72+ assert.equal(graph.lineText("a0.0"), value);
73+ const textKey = JSON.stringify(["0", 0]);
74+ storage.remove("atom-text:long:chunks", JSON.stringify([textKey, 1]));
75+ const reopened = new Graph({ storage });
76+ assert.throws(() => reopened.lineText("a0.0"), /incomplete stored text/);
77+ assert.throws(() => reopened.atom("a0").inserts[0]!.lines[0], /incomplete stored text/);
78+});
80+test("persistent graph detaches accepted lists without freezing a second input copy", () => {
81+ const storage = new SqlState();
82+ try {
83+ const memory = new MemoryStore();
84+ new Project(memory).init({ "a.txt": "before\nsecond" }, 0);
85+ const entry = memory.entries[0]!;
86+ if (entry.type !== "init") throw Error("expected init");
87+ const atom = structuredClone(entry.atom);
88+ const expected = structuredClone(atom);
89+ const graph = new Graph({ storage });
90+ graph.add(atom);
91+ (atom.inserts[0]!.lines as string[])[0] = "changed";
92+ (atom.writes as string[]).length = 0;
93+ for (const loaded of [graph, new Graph({ storage })]) {
94+ assert.deepEqual(JSON.parse(JSON.stringify(loaded.atom("a0"))), expected);
95+ assert.equal(loaded.lineText("a0.0"), expected.inserts[0]!.lines[0]);
96+ }
97+ } finally {
98+ storage.db.close();
99+ }
100+});
MCP
compare on this site's /mcp
CLI
abso diff 116 318 src/engine/test/graph-long-text.test.ts --json
JSON
/christopher/abso-core/compare/116..318?file=src%2Fengine%2Ftest%2Fgraph-long-text.test.ts&format=json