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
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/src/engine/test/graph-long-text.test.ts?version=166&format=json
145 linescodex-capacity-chair 100%Last change codex-capacity-chair in version 166, 2 versions changed it

You're reading version 166. The newest is 318, and 1 version since then changed this file. Go to the newestCompare with 318

1import assert from "node:assert/strict";
2import { test } from "node:test";
3import { MemoryStore, Project } from "../../../worker/project/project.ts";
4import { Graph } from "../graph.ts";
5import { SqlState } from "./storage-helper.ts";
6
7test("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});
29test("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});
50import { SqliteWriterState } from "../../../server/src/writer-host.ts";
51import { memoryStorage } from "../../../server/test/helpers.ts";
53test("persistent atom metadata accepts text beyond the generic state limit", (t) => {
54 const database = memoryStorage();
55 t.after(() => database.db.close());
56 SqliteWriterState.initialize(database);
57 const storage = new SqliteWriterState(database, "long-atom");
58 const memory = new MemoryStore();
59 const value = "x".repeat(8100000);
60 new Project(memory).init({ "large.txt": value }, 0);
61 const entry = memory.entries[0]!;
62 if (entry.type !== "init") throw Error("expected init");
63 new Graph({ storage }).add(entry.atom);
64 assert.ok(JSON.stringify(storage.read("atoms", "0")).length < 4096);
65 const read = storage.read.bind(storage);
66 let textReads = 0;
67 t.mock.method(storage, "read", (collection: string, key: string) => {
68 if (collection === "atom-text:long:chunks") textReads++;
69 return read(collection, key);
70 });
71 const graph = new Graph({ storage });
72 const atom = graph.atom("a0");
73 assert.equal(textReads, 0, "reading atom metadata must not load long text");
74 assert.equal(atom.inserts[0]!.lines[0], value);
75 assert.ok(textReads > 0);
76 assert.equal(graph.lineText("a0.0"), value);
77 assert.equal(
78 database.db
79 .prepare(
80 "SELECT COUNT(*) AS n FROM writer_state WHERE namespace = 'long-atom' AND collection = 'atom-text:long:chunks' AND part = -1",
81 )
82 .get()!.n,
83 Math.ceil(value.length / 16384),
84 );
85 assert.equal(
86 database.db
87 .prepare(
88 "SELECT COUNT(*) AS n FROM writer_state WHERE namespace = 'long-atom' AND collection = 'line-text:long:chunks'",
89 )
90 .get()!.n,
91 0,
92 );
93});
95test("long atom acceptance rolls back partial chunks and detects missing text", (t) => {
96 const storage = new SqlState();
97 t.after(() => storage.db.close());
98 const memory = new MemoryStore();
99 const value = "z".repeat(100000);
100 new Project(memory).init({ "a.txt": value }, 0);
101 const entry = memory.entries[0]!;
102 if (entry.type !== "init") throw Error("expected init");
103 const graph = new Graph({ storage });
104 const rows = () => storage.db.prepare("SELECT * FROM state ORDER BY collection,key").all();
105 const before = rows();
106 const write = storage.write.bind(storage);
107 let chunks = 0;
108 const failure = t.mock.method(storage, "write", (collection: string, key: string, value: unknown) => {
109 write(collection, key, value);
110 if (collection === "atom-text:long:chunks" && ++chunks === 2) throw Error("injected partial atom text");
111 });
112 assert.throws(() => graph.add(entry.atom), /partial atom text/);
113 assert.deepEqual(rows(), before);
114 assert.equal(graph.size, 0);
115 failure.mock.restore();
116 graph.add(entry.atom);
117 assert.equal(graph.lineText("a0.0"), value);
118 const textKey = JSON.stringify(["0", 0]);
119 storage.remove("atom-text:long:chunks", JSON.stringify([textKey, 1]));
120 const reopened = new Graph({ storage });
121 assert.throws(() => reopened.lineText("a0.0"), /incomplete stored text/);
122 assert.throws(() => reopened.atom("a0").inserts[0]!.lines[0], /incomplete stored text/);
123});
125test("persistent graph detaches accepted lists without freezing a second input copy", () => {
126 const storage = new SqlState();
127 try {
128 const memory = new MemoryStore();
129 new Project(memory).init({ "a.txt": "before\nsecond" }, 0);
130 const entry = memory.entries[0]!;
131 if (entry.type !== "init") throw Error("expected init");
132 const atom = structuredClone(entry.atom);
133 const expected = structuredClone(atom);
134 const graph = new Graph({ storage });
135 graph.add(atom);
136 (atom.inserts[0]!.lines as string[])[0] = "changed";
137 (atom.writes as string[]).length = 0;
138 for (const loaded of [graph, new Graph({ storage })]) {
139 assert.deepEqual(JSON.parse(JSON.stringify(loaded.atom("a0"))), expected);
140 assert.equal(loaded.lineText("a0.0"), expected.inserts[0]!.lines[0]);
141 }
142 } finally {
143 storage.db.close();
144 }
145});