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

Compare

+135 −0 in 1 place
new file, 135 lines
1+import assert from "node:assert/strict";
2+import { test } from "node:test";
3+import { Graph } from "../graph.ts";
4+import { withProjectionScratch } from "../projection-scratch.ts";
5+import { resolveScratchMoves } from "../relocation-scratch.ts";
6+import { CachedStateStorage, StableOverlaySet } from "../state-source.ts";
7+import { View } from "../view.ts";
8+import { Repo, Rng } from "./helpers.ts";
9+import { SqlState } from "./storage-helper.ts";
11+test("scratch relocation cycle selection matches View across differing memberships and tied moves", () => {
12+ const rng = new Rng(45131);
13+ const source = new SqlState();
14+ const storage = new CachedStateStorage(source, 4096, 16);
15+ try {
16+ for (let trial = 0; trial < 24; trial++) {
17+ const repo = Repo.init({ "f.txt": Array.from({ length: 24 }, (_, n) => `line ${n}\n`).join(""), "g.txt": "" });
18+ const earlier = new Set(repo.shared);
19+ for (let j = 0; j < 32; j++) {
20+ const offset = rng.int(24);
21+ const moves = Array.from({ length: 3 }, (_, index) => {
22+ const line = `a0.${(offset + index) % 24}`;
23+ const candidate = `a0.${rng.int(24)}`;
24+ return { line, parent: candidate === line ? (j % 2 ? "^f.txt" : "^g.txt") : candidate };
25+ });
26+ const id = repo.graph.nextId();
27+ repo.graph.add({
28+ id,
29+ seq: repo.graph.size,
30+ author: "fixture",
31+ message: "move",
32+ time: j,
33+ inserts: [],
34+ deletes: [],
35+ writes: moves.flatMap((move) => [`P:${move.line}`, `G:${move.parent}`]),
36+ reads: [],
37+ holds: [],
38+ needs: [],
39+ resolves: [],
40+ reasons: [],
41+ deps: ["a0"],
42+ moves,
43+ });
44+ repo.shared.add(id);
45+ if (j < 16) earlier.add(id);
46+ }
47+ for (const membership of [repo.shared, earlier, repo.shared]) {
48+ const oracle = new View(repo.graph, membership);
49+ const parents = withProjectionScratch(
50+ storage,
51+ () => {},
52+ (scratch) => {
53+ const resolved = resolveScratchMoves(repo.graph, (id) => membership.has(id), scratch);
54+ return Array.from({ length: 24 }, (_, n) => resolved.parent(`a0.${n}`));
55+ },
56+ );
57+ assert.deepEqual(
58+ parents,
59+ Array.from({ length: 24 }, (_, n) => oracle.parentOf(`a0.${n}`)),
60+ );
61+ assert.equal(source.db.prepare("SELECT count(*) AS n FROM state").get()!.n, 0);
62+ assert.equal(storage.retainedEntries, 0);
63+ }
64+ if (trial < 4) {
65+ const persisted = new SqlState();
66+ try {
67+ const indexed = new Graph({ storage: new CachedStateStorage(persisted, 8192, 32) });
68+ for (const id of repo.shared) indexed.add(repo.graph.atom(id));
69+ const before = persisted.db.prepare("SELECT * FROM state ORDER BY collection, key").all();
70+ // Restart before projecting, then alternate membership on the same graph.
71+ const reopened = new Graph({ storage: new CachedStateStorage(persisted, 8192, 32) });
72+ for (const membership of [repo.shared, earlier, repo.shared]) {
73+ const expected = new View(repo.graph, membership);
74+ const actual = new View(reopened, new StableOverlaySet(membership));
75+ for (const path of ["f.txt", "g.txt"]) {
76+ assert.equal(actual.text(path), expected.text(path));
77+ assert.deepEqual(actual.sequence(path), expected.sequence(path));
78+ }
79+ for (const n of [0, 11, 23]) {
80+ assert.equal(actual.parentOf(`a0.${n}`), expected.parentOf(`a0.${n}`));
81+ assert.equal(actual.fileOf(`a0.${n}`), expected.fileOf(`a0.${n}`));
82+ }
83+ assert.deepEqual(persisted.db.prepare("SELECT * FROM state ORDER BY collection, key").all(), before);
84+ }
85+ } finally {
86+ persisted.db.close();
87+ }
88+ }
89+ }
90+ } finally {
91+ source.db.close();
92+ }
93+});
95+test("scratch relocation write failure rolls back without changing canonical graph state", () => {
96+ const repo = Repo.init({ f: "one\ntwo\n" });
97+ const source = new SqlState();
98+ try {
99+ repo.graph.add({
100+ id: "a1",
101+ seq: 1,
102+ author: "fixture",
103+ message: "move",
104+ time: 1,
105+ inserts: [],
106+ deletes: [],
107+ writes: ["P:a0.0", "G:a0.1"],
108+ reads: [],
109+ holds: [],
110+ needs: [],
111+ resolves: [],
112+ reasons: [],
113+ deps: ["a0"],
114+ moves: [{ line: "a0.0", parent: "a0.1" }],
115+ });
116+ repo.shared.add("a1");
117+ const before = { size: repo.graph.size, lines: repo.graph.lineCount };
118+ source.failWrite = 3;
119+ assert.throws(
120+ () =>
121+ withProjectionScratch(
122+ source,
123+ () => {},
124+ (scratch) => {
125+ resolveScratchMoves(repo.graph, (id) => repo.shared.has(id), scratch);
126+ },
127+ ),
128+ /injected storage failure/,
129+ );
130+ assert.deepEqual({ size: repo.graph.size, lines: repo.graph.lineCount }, before);
131+ assert.equal(source.db.prepare("SELECT count(*) AS n FROM state").get()!.n, 0);
132+ } finally {
133+ source.db.close();
134+ }
135+});
MCP
compare on this site's /mcp
CLI
abso diff 53 318 src/engine/test/relocation-scratch.test.ts --json
JSON
/christopher/abso-core/compare/53..318?file=src%2Fengine%2Ftest%2Frelocation-scratch.test.ts&format=json