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 145 to 146

Compare

+95 −72 in 1 place
Lines 1–106 at 146 (were 1–83 at 145)
11import assert from "node:assert/strict";
22import { test } from "node:test";
3+import { ProjectionAtomAdoption } from "../experimental/projection-atom-adoption.ts";
34import { ExperimentalMarkerProjection as MarkerProjection } from "../experimental/projection-marker.ts";
45import { Graph } from "../graph.ts";
56import { CachedStateStorage } from "../state-source.ts";
7+import type { Atom } from "../types.ts";
68import { Repo, Rng } from "./helpers.ts";
79import { SqlState } from "./storage-helper.ts";
9−test("typed marker projection matches competing cyclic moves and removals", () => {
10− const db = new SqlState();
11− try {
12− const repo = Repo.init({ "f.txt": Array.from({ length: 12 }, (_, n) => `${n}\n`).join("") }),
13− graph = new Graph({ storage: new CachedStateStorage(db) }),
14− rng = new Rng(45131);
15− graph.add(repo.graph.atom("a0"));
16− const p = new MarkerProjection(db, graph, "f.txt", "typed-" + "cycle");
17− let state = p.apply(p.empty(), repo.graph.atom("a0")),
18− checks = 0;
19− const atoms = [];
20− const check = () => {
21− const view = repo.view();
22− assert.deepEqual(
23− p.lines(state),
24− view.lines("f.txt").map((x) => x.id),
25− );
26− for (let n = 0; n < 12; n++) {
27− const parent = view.parentOf(`a0.${n}`);
28− assert.equal(
29− (p.markers.get(state.locator, n + 1) as { parentKey: number }).parentKey,
30− parent.startsWith("^") ? 0 : graph.lineN(parent) + 1,
11+for (const paged of [false, true])
12+ test(`typed marker projection matches competing cyclic moves and removals (paged=${paged})`, () => {
13+ const db = new SqlState();
14+ try {
15+ const repo = Repo.init({ "f.txt": Array.from({ length: 12 }, (_, n) => `${n}\n`).join("") }),
16+ graph = new Graph({ storage: new CachedStateStorage(db) }),
17+ rng = new Rng(45131);
18+ graph.add(repo.graph.atom("a0"));
19+ const p = new MarkerProjection(db, graph, "f.txt", "typed-" + "cycle");
20+ let state = p.apply(p.empty(), repo.graph.atom("a0")),
21+ checks = 0;
22+ const atoms = [];
23+ let task = 0;
24+ const apply = (atom: Atom, remove: boolean) => {
25+ if (!paged) return remove ? p.removeAtom(state, atom) : p.apply(state, atom);
26+ const job = new ProjectionAtomAdoption(p, String(task++));
27+ const previous = state;
28+ for (let pages = 0; pages < 10000; pages++) {
29+ const result = job.page({
30+ previous,
31+ atom,
32+ remove,
33+ source: "c".repeat(64),
34+ maxSteps: 3,
35+ validateSource: () => {},
36+ });
37+ assert.ok(result.steps <= 3);
38+ assert.equal(result.atomicMoveWork, false);
39+ if (result.done) return result.state;
40+ }
41+ throw Error("move adoption did not finish");
42+ };
43+ const check = () => {
44+ const view = repo.view();
45+ assert.deepEqual(
46+ p.lines(state),
47+ view.lines("f.txt").map((x) => x.id),
3148 );
32− }
33− checks++;
34− };
35− for (let j = 0; j < 24; j++) {
36− const offset = rng.int(12),
37− moves = Array.from({ length: 3 }, (_, i) => {
38− const line = `a0.${(offset + i) % 12}`,
39− candidate = `a0.${rng.int(12)}`;
40− return { line, parent: candidate === line ? "^f.txt" : candidate };
41− });
42− const atom = {
43− id: repo.graph.nextId(),
44− seq: repo.graph.size,
45− author: "fixture",
46− message: "move",
47− time: j,
48− inserts: [],
49− deletes: [],
50− writes: moves.flatMap((m) => [`P:${m.line}`, `G:${m.parent}`]),
51− reads: [],
52− holds: [],
53− needs: [],
54− resolves: [],
55− reasons: [],
56− deps: ["a0"],
57− moves,
49+ for (let n = 0; n < 12; n++) {
50+ const parent = view.parentOf(`a0.${n}`);
51+ assert.equal(
52+ (p.markers.get(state.locator, n + 1) as { parentKey: number }).parentKey,
53+ parent.startsWith("^") ? 0 : graph.lineN(parent) + 1,
54+ );
55+ }
56+ checks++;
5857 };
59− repo.graph.add(atom);
60− repo.shared.add(atom.id);
61− graph.add(atom);
62− atoms.push(atom);
63− state = p.apply(state, atom);
64− check();
58+ for (let j = 0; j < 24; j++) {
59+ const offset = rng.int(12),
60+ moves = Array.from({ length: 3 }, (_, i) => {
61+ const line = `a0.${(offset + i) % 12}`,
62+ candidate = `a0.${rng.int(12)}`;
63+ return { line, parent: candidate === line ? "^f.txt" : candidate };
64+ });
65+ const atom = {
66+ id: repo.graph.nextId(),
67+ seq: repo.graph.size,
68+ author: "fixture",
69+ message: "move",
70+ time: j,
71+ inserts: [],
72+ deletes: [],
73+ writes: moves.flatMap((m) => [`P:${m.line}`, `G:${m.parent}`]),
74+ reads: [],
75+ holds: [],
76+ needs: [],
77+ resolves: [],
78+ reasons: [],
79+ deps: ["a0"],
80+ moves,
81+ };
82+ repo.graph.add(atom);
83+ repo.shared.add(atom.id);
84+ graph.add(atom);
85+ atoms.push(atom);
86+ state = apply(atom, false);
87+ check();
88+ }
89+ for (const atom of atoms.filter((_, i) => i % 2 === 0)) {
90+ repo.shared.delete(atom.id);
91+ state = apply(atom, true);
92+ check();
93+ }
94+ assert.equal(
95+ db.db
96+ .prepare(
97+ "SELECT count(*) AS n FROM state WHERE collection LIKE '%sequence-resolver:%' OR collection LIKE '%sequence-relocation-work:%' OR collection LIKE '%move-adoption:%'",
98+ )
99+ .get()!.n,
100+ 0,
101+ );
102+ assert.equal(checks, 36);
103+ } finally {
104+ db.db.close();
65105 }
66− for (const atom of atoms.filter((_, i) => i % 2 === 0)) {
67− repo.shared.delete(atom.id);
68− state = p.removeAtom(state, atom);
69− check();
70− }
71− assert.equal(
72− db.db
73− .prepare(
74− "SELECT count(*) AS n FROM state WHERE collection LIKE '%sequence-resolver:%' OR collection LIKE '%sequence-relocation-work:%'",
75− )
76− .get()!.n,
77− 0,
78− );
79− assert.equal(checks, 36);
80− } finally {
81− db.db.close();
82− }
83−});
106+ });
MCP
compare on this site's /mcp
CLI
abso diff 145 146 src/engine/test/projection-marker-cycle.test.ts --json
JSON
/christopher/abso-core/compare/145..146?file=src%2Fengine%2Ftest%2Fprojection-marker-cycle.test.ts&format=json