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 108 to 109

Compare

+96 −0 in 1 place
new file, 96 lines
1+import assert from "node:assert/strict";
2+import { test } from "node:test";
3+import { checkDraft, Graph, View } from "../index.ts";
4+import { lines, Repo } from "./helpers.ts";
5+import { SqlState } from "./storage-helper.ts";
6+
7+test("stored graph reopens without replay and preserves moves, conflicts and new edits", () => {
8+ const oracle = Repo.init({ "a.txt": lines("one", "two", "three"), "b.txt": "" });
9+ oracle.edit({ edits: [{ file: "a.txt", old: "two", new: "TWO" }] });
10+ oracle.edit({ move: { file: "a.txt", start: 1, end: 2, to: "b.txt", at: 0 } });
11+ const storage = new SqlState();
12+ const original = new Graph({ storage });
13+ for (const atom of oracle.graph.atoms()) original.add(atom);
14+ original.setLabel({ name: "saved", head: "a2", title: "Saved", message: "" });
15+ const reads = storage.reads;
16+ const reopened = new Graph({ storage });
17+ assert.equal(storage.reads, reads, "opening does not hydrate historical collections");
18+ assert.equal(storage.scans, 0);
19+ assert.equal(reopened.size, oracle.graph.size);
20+ assert.equal(reopened.lineCount, oracle.graph.lineCount);
21+ assert.deepEqual([...reopened.movers()], [...oracle.graph.movers()]);
22+ for (const atom of oracle.graph.atoms()) {
23+ assert.deepEqual(reopened.filesOf(atom.id), oracle.graph.filesOf(atom.id));
24+ for (const move of atom.moves ?? []) {
25+ assert.deepEqual(reopened.relocationsOf(move.line), oracle.graph.relocationsOf(move.line));
26+ assert.deepEqual(reopened.relocatedTo(move.parent), oracle.graph.relocatedTo(move.parent));
27+ assert.equal(reopened.codeOf(move.parent), oracle.graph.codeOf(move.parent));
28+ }
29+ }
30+ assert.deepEqual(new View(reopened, oracle.shared).files(), oracle.files());
31+ assert.equal(reopened.label("saved")?.head, "a2");
32+ const draft = oracle.draft({ edits: [{ file: "a.txt", old: "one", new: "ONE" }] });
33+ assert.deepEqual(checkDraft(reopened, oracle.shared, draft), oracle.check(draft));
34+ oracle.graph.add(draft);
35+ reopened.add(draft);
36+ oracle.shared.add(draft.id);
37+ assert.deepEqual(new View(new Graph({ storage }), oracle.shared).files(), oracle.files());
38+ for (let n = 0; n < oracle.graph.lineCount; n++) {
39+ const id = oracle.graph.lineIdOf(n);
40+ assert.deepEqual(reopened.line(id), oracle.graph.line(id));
41+ assert.deepEqual(reopened.deletersOf(id), oracle.graph.deletersOf(id));
42+ }
43+ assert.ok(Object.isFrozen(reopened.atom("a0")));
44+ storage.db.close();
45+});
47+test("stored indexes retain multiple claimants and preserve a real divergent conflict", () => {
48+ const oracle = Repo.init({ "a.txt": lines("one", "two", "three") });
49+ oracle.edit({ edits: [{ file: "a.txt", old: "one", new: "ONE" }], author: "left" });
50+ const right = oracle.draft({ edits: [{ file: "a.txt", old: "one", new: "uno" }], author: "right" }, ["a0"]);
51+ const storage = new SqlState();
52+ const graph = new Graph({ storage });
53+ for (const atom of oracle.graph.atoms()) graph.add(atom);
54+ assert.equal(oracle.check(right).conflicts.length, 1);
55+ assert.deepEqual(checkDraft(new Graph({ storage }), oracle.shared, right), oracle.check(right));
56+ graph.add(right);
57+ oracle.graph.add(right);
58+ assert.deepEqual(new Graph({ storage }).writersOf("L:a0.0"), oracle.graph.writersOf("L:a0.0"));
59+ assert.deepEqual(new Graph({ storage }).deletedLines(right.id), oracle.graph.deletedLines(right.id));
60+ storage.db.close();
61+});
63+test("failed stored append rolls back all graph indexes and can be retried", () => {
64+ const oracle = Repo.init({ "a.txt": lines("one", "two") });
65+ const storage = new SqlState();
66+ const graph = new Graph({ storage });
67+ graph.add(oracle.graph.atom("a0"));
68+ const before = JSON.stringify(graph.toJSON());
69+ const draft = oracle.draft({ edits: [{ file: "a.txt", old: "one", new: "ONE" }] });
70+ storage.failWrite = storage.writes + 10;
71+ assert.throws(() => graph.add(draft), /injected storage failure/);
72+ assert.equal(JSON.stringify(graph.toJSON()), before);
73+ assert.equal(JSON.stringify(new Graph({ storage }).toJSON()), before);
74+ storage.failWrite = Infinity;
75+ graph.add(draft);
76+ assert.equal(new Graph({ storage }).size, 2);
77+ storage.db.close();
78+});
80+test("removing a stored label rolls back dependent rewrites on failure", () => {
81+ const oracle = Repo.init({ "a.txt": lines("one") });
82+ const storage = new SqlState();
83+ const graph = new Graph({ storage });
84+ graph.add(oracle.graph.atom("a0"));
85+ graph.setLabel({ name: "base", head: "a0", title: "Base", message: "" });
86+ graph.setLabel({ name: "child", head: "a0", base: "base", title: "Child", message: "" });
87+ const before = graph.labels();
88+ storage.failWrite = storage.writes + 1;
89+ assert.throws(() => graph.removeLabel("base"), /injected storage failure/);
90+ assert.deepEqual(new Graph({ storage }).labels(), before);
91+ storage.failWrite = Infinity;
92+ assert.equal(graph.removeLabel("base"), true);
93+ assert.equal(new Graph({ storage }).label("base"), undefined);
94+ assert.equal(new Graph({ storage }).label("child")?.base, "a0");
95+ storage.db.close();
96+});
MCP
compare on this site's /mcp
CLI
abso diff 108 109 src/engine/test/state-source.test.ts --json
JSON
/christopher/abso-core/compare/108..109?file=src%2Fengine%2Ftest%2Fstate-source.test.ts&format=json