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 161 to 162

Compare

+123 −0 in 1 place
new file, 123 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("persistent graph stores long lines in chunks and reopens exact text", () => {
8+ const storage = new SqlState();
9+ try {
10+ const memory = new MemoryStore();
11+ const value = `${"x".repeat(100000)}\uD83D\uDE00`;
12+ new Project(memory).init({ "a.txt": value }, 0);
13+ const entry = memory.entries[0]!;
14+ assert.equal(entry.type, "init");
15+ if (entry.type !== "init") throw Error("expected init");
16+ new Graph({ storage }).add(entry.atom);
17+ assert.deepEqual(storage.read("line-text", "0"), { format: 1, text: JSON.stringify(["0", 0]) });
18+ assert.equal(new Graph({ storage }).lineText("a0.0"), value);
19+ assert.ok(
20+ (storage.db.prepare("SELECT COUNT(*) AS n FROM state WHERE collection = 'atom-text:long:chunks'").get()!
21+ .n as number) > 1,
22+ );
23+ } finally {
24+ storage.db.close();
25+ }
26+});
28+import { SqliteWriterState } from "../../../server/src/writer-host.ts";
29+import { memoryStorage } from "../../../server/test/helpers.ts";
31+test("persistent atom metadata accepts text beyond the generic state limit", (t) => {
32+ const database = memoryStorage();
33+ t.after(() => database.db.close());
34+ SqliteWriterState.initialize(database);
35+ const storage = new SqliteWriterState(database, "long-atom");
36+ const memory = new MemoryStore();
37+ const value = "x".repeat(8100000);
38+ new Project(memory).init({ "large.txt": value }, 0);
39+ const entry = memory.entries[0]!;
40+ if (entry.type !== "init") throw Error("expected init");
41+ new Graph({ storage }).add(entry.atom);
42+ assert.ok(JSON.stringify(storage.read("atoms", "0")).length < 4096);
43+ const read = storage.read.bind(storage);
44+ let textReads = 0;
45+ t.mock.method(storage, "read", (collection: string, key: string) => {
46+ if (collection === "atom-text:long:chunks") textReads++;
47+ return read(collection, key);
48+ });
49+ const graph = new Graph({ storage });
50+ const atom = graph.atom("a0");
51+ assert.equal(textReads, 0, "reading atom metadata must not load long text");
52+ assert.equal(atom.inserts[0]!.lines[0], value);
53+ assert.ok(textReads > 0);
54+ assert.equal(graph.lineText("a0.0"), value);
55+ assert.equal(
56+ database.db
57+ .prepare(
58+ "SELECT COUNT(*) AS n FROM writer_state WHERE namespace = 'long-atom' AND collection = 'atom-text:long:chunks' AND part = -1",
59+ )
60+ .get()!.n,
61+ Math.ceil(value.length / 16384),
62+ );
63+ assert.equal(
64+ database.db
65+ .prepare(
66+ "SELECT COUNT(*) AS n FROM writer_state WHERE namespace = 'long-atom' AND collection = 'line-text:long:chunks'",
67+ )
68+ .get()!.n,
69+ 0,
70+ );
71+});
73+test("long atom acceptance rolls back partial chunks and detects missing text", (t) => {
74+ const storage = new SqlState();
75+ t.after(() => storage.db.close());
76+ const memory = new MemoryStore();
77+ const value = "z".repeat(100000);
78+ new Project(memory).init({ "a.txt": value }, 0);
79+ const entry = memory.entries[0]!;
80+ if (entry.type !== "init") throw Error("expected init");
81+ const graph = new Graph({ storage });
82+ const rows = () => storage.db.prepare("SELECT * FROM state ORDER BY collection,key").all();
83+ const before = rows();
84+ const write = storage.write.bind(storage);
85+ let chunks = 0;
86+ const failure = t.mock.method(storage, "write", (collection: string, key: string, value: unknown) => {
87+ write(collection, key, value);
88+ if (collection === "atom-text:long:chunks" && ++chunks === 2) throw Error("injected partial atom text");
89+ });
90+ assert.throws(() => graph.add(entry.atom), /partial atom text/);
91+ assert.deepEqual(rows(), before);
92+ assert.equal(graph.size, 0);
93+ failure.mock.restore();
94+ graph.add(entry.atom);
95+ assert.equal(graph.lineText("a0.0"), value);
96+ const textKey = JSON.stringify(["0", 0]);
97+ storage.remove("atom-text:long:chunks", JSON.stringify([textKey, 1]));
98+ const reopened = new Graph({ storage });
99+ assert.throws(() => reopened.lineText("a0.0"), /incomplete stored text/);
100+ assert.throws(() => reopened.atom("a0").inserts[0]!.lines[0], /incomplete stored text/);
101+});
103+test("persistent graph detaches accepted lists without freezing a second input copy", () => {
104+ const storage = new SqlState();
105+ try {
106+ const memory = new MemoryStore();
107+ new Project(memory).init({ "a.txt": "before\nsecond" }, 0);
108+ const entry = memory.entries[0]!;
109+ if (entry.type !== "init") throw Error("expected init");
110+ const atom = structuredClone(entry.atom);
111+ const expected = structuredClone(atom);
112+ const graph = new Graph({ storage });
113+ graph.add(atom);
114+ (atom.inserts[0]!.lines as string[])[0] = "changed";
115+ (atom.writes as string[]).length = 0;
116+ for (const loaded of [graph, new Graph({ storage })]) {
117+ assert.deepEqual(JSON.parse(JSON.stringify(loaded.atom("a0"))), expected);
118+ assert.equal(loaded.lineText("a0.0"), expected.inserts[0]!.lines[0]);
119+ }
120+ } finally {
121+ storage.db.close();
122+ }
123+});
MCP
compare on this site's /mcp
CLI
abso diff 161 162 src/engine/test/graph-long-text.test.ts --json
JSON
/christopher/abso-core/compare/161..162?file=src%2Fengine%2Ftest%2Fgraph-long-text.test.ts&format=json