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 142 to 143

Compare

+120 −0 in 1 place
new file, 120 lines
1+import assert from "node:assert/strict";
2+import { test } from "node:test";
3+import { ExperimentalMarkerProjection as MarkerProjection } from "../experimental/projection-marker.ts";
4+import { Graph } from "../graph.ts";
5+import { CachedStateStorage } from "../state-source.ts";
6+import { Repo } from "./helpers.ts";
7+import { SqlState } from "./storage-helper.ts";
8+
9+test("typed marker projection matches mixed multi-file edits and reverse removals", () => {
10+ const db = new SqlState();
11+ try {
12+ const repo = Repo.init({ "f.txt": "a\nb\nc\n", "g.txt": "x\ny\n" }),
13+ graph = new Graph({ storage: new CachedStateStorage(db) });
14+ graph.add(repo.graph.atom("a0"));
15+ const p = new MarkerProjection(db, graph, "f.txt", "typed-mixed");
16+ let state = p.apply(p.empty(), repo.graph.atom("a0")),
17+ checks = 0;
18+ const atoms = [],
19+ roots = [];
20+ const check = () => {
21+ const view = repo.view();
22+ for (const path of ["f.txt", "g.txt"]) {
23+ assert.deepEqual(
24+ p.lines(state, path),
25+ view.lines(path).map((x) => x.id),
26+ );
27+ assert.deepEqual(p.attrs(state, path), view.attrs(path));
28+ }
29+ checks++;
30+ };
31+ for (let i = 0; i < 36; i++) {
32+ const file = i % 2 ? "f.txt" : "g.txt",
33+ other = i % 2 ? "g.txt" : "f.txt",
34+ view = repo.view();
35+ let input: Parameters<Repo["edit"]>[0];
36+ if (i % 3 === 0 && view.lines(file).length) input = { move: { file, start: 0, end: 1, to: other, at: 0 } };
37+ else if (i % 3 === 1)
38+ input = {
39+ edits: [{ file, old: view.text(file), new: `new ${i}\n${view.text(file)}` }],
40+ attrs: [{ file, name: "exec", value: i % 2 ? "1" : null }],
41+ };
42+ else input = { edits: [{ file, old: view.text(file), new: `rewrite ${i}\n` }] };
43+ const atom = repo.edit(input);
44+ graph.add(atom);
45+ atoms.push(atom);
46+ state = p.apply(state, atom);
47+ check();
48+ if (i % 9 === 0) roots.push({ state, f: p.lines(state, "f.txt"), g: p.lines(state, "g.txt") });
49+ }
50+ for (const atom of atoms.toReversed()) {
51+ repo.shared.delete(atom.id);
52+ state = p.removeAtom(state, atom);
53+ check();
54+ }
55+ for (const root of roots) {
56+ assert.deepEqual(p.lines(root.state, "f.txt"), root.f);
57+ assert.deepEqual(p.lines(root.state, "g.txt"), root.g);
58+ }
59+ assert.equal(checks, 72);
60+ } finally {
61+ db.db.close();
62+ }
63+});
65+test("typed marker namespaces isolate file identities and temporary metadata", () => {
66+ const storage = new SqlState();
67+ try {
68+ const repo = Repo.init({ "f.txt": "f\n", "g.txt": "g\n" });
69+ const graph = new Graph({ storage: new CachedStateStorage(storage) });
70+ graph.add(repo.graph.atom("a0"));
71+ const alpha = new MarkerProjection(storage, graph, "f.txt", "alpha");
72+ const beta = new MarkerProjection(storage, graph, "g.txt", "beta");
73+ const a = alpha.apply(alpha.empty(), repo.graph.atom("a0"));
74+ const b = beta.apply(beta.empty(), repo.graph.atom("a0"));
75+ const wrongFile = new MarkerProjection(storage, graph, "g.txt", "alpha");
76+ for (const other of [beta, wrongFile]) {
77+ const reads = storage.reads,
78+ writes = storage.writes;
79+ assert.throws(() => other.lines(a, "f.txt"), /constructor context mismatch/);
80+ assert.throws(() => other.apply(a, repo.graph.atom("a0")), /constructor context mismatch/);
81+ assert.equal(storage.reads, reads);
82+ assert.equal(storage.writes, writes);
83+ }
85+ for (const path of ["f.txt", "g.txt"]) {
86+ assert.deepEqual(
87+ alpha.lines(a, path),
88+ repo
89+ .view()
90+ .lines(path)
91+ .map((x) => x.id),
92+ );
93+ assert.deepEqual(
94+ beta.lines(b, path),
95+ repo
96+ .view()
97+ .lines(path)
98+ .map((x) => x.id),
99+ );
100+ }
101+ alpha.storage.write("sequence-meta", "work-scope", 91);
102+ assert.equal(beta.storage.read("sequence-meta", "work-scope"), undefined);
103+ const rows = () => JSON.stringify(storage.db.prepare("SELECT * FROM state ORDER BY collection,key").all());
104+ const before = rows();
105+ assert.throws(
106+ () => alpha.relocateBatch(a, [{ n: -1, parentKey: 0, key: "0".repeat(57) }]),
107+ /invalid relocation plan/,
108+ );
109+ assert.equal(rows(), before);
110+ assert.deepEqual(
111+ beta.lines(b, "f.txt"),
112+ repo
113+ .view()
114+ .lines("f.txt")
115+ .map((x) => x.id),
116+ );
117+ } finally {
118+ storage.db.close();
119+ }
120+});
MCP
compare on this site's /mcp
CLI
abso diff 142 143 src/engine/test/projection-marker.test.ts --json
JSON
/christopher/abso-core/compare/142..143?file=src%2Fengine%2Ftest%2Fprojection-marker.test.ts&format=json