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

+113 −0 in 1 place
new file, 113 lines
1+import assert from "node:assert/strict";
2+import { test } from "node:test";
3+import { buildAtom } from "../build.ts";
4+import { ExperimentalMarkerProjection } from "../experimental/projection-marker.ts";
5+import { ProjectionReadScope } from "../experimental/projection-read-scope.ts";
6+import { ProjectionReader } from "../experimental/projection-reader.ts";
7+import { Graph } from "../graph.ts";
8+import { CachedStateStorage } from "../state-source.ts";
9+
10+import { Repo } from "./helpers.ts";
11+import { SqlState } from "./storage-helper.ts";
13+test("unchanged atom builder consumes the private reader for replacement and insertion edits", () => {
14+ const storage = new SqlState();
15+ try {
16+ const repo = Repo.init({ "f.txt": "one\ntwo\nthree\n" });
17+ const graph = new Graph({ storage: new CachedStateStorage(storage) });
18+ graph.add(repo.graph.atom("a0"));
19+ const adapter = new ExperimentalMarkerProjection(storage, graph, "f.txt", "builder-reader");
20+ let state = adapter.apply(adapter.empty(), graph.atom("a0"));
21+ for (let i = 0; i < 16; i++) {
22+ const input = {
23+ author: "writer",
24+ message: `Edit ${i}`,
25+ time: i,
26+ edits: [
27+ {
28+ file: "f.txt",
29+ old: repo.view().text("f.txt"),
30+ new: `one\nrevision ${i}\nthree\n${i % 2 ? "extra\n" : ""}`,
31+ },
32+ ],
33+ };
34+ const expected = buildAtom(repo.view(), input);
35+ const reader = new ProjectionReader(adapter, state, new ProjectionReadScope(graph, () => graph).guard(graph));
36+ const actual = buildAtom(reader, input);
37+ assert.deepEqual(actual, expected);
38+ graph.add(actual);
39+ repo.graph.add(expected);
40+ repo.shared.add(expected.id);
41+ state = adapter.apply(state, actual);
42+ assert.equal(
43+ new ProjectionReader(adapter, state, new ProjectionReadScope(graph, () => graph).guard(graph)).text("f.txt"),
44+ repo.view().text("f.txt"),
45+ );
46+ }
47+ } finally {
48+ storage.db.close();
49+ }
50+});
52+test("private reader builds cross-file moves and resurrects a deleted file", (t) => {
53+ const storage = new SqlState();
54+ try {
55+ const repo = Repo.init({ "f.txt": "one\ntwo\nthree\n", "g.txt": "other\n" });
56+ const graph = new Graph({ storage: new CachedStateStorage(storage) });
57+ graph.add(repo.graph.atom("a0"));
58+ const adapter = new ExperimentalMarkerProjection(storage, graph, "f.txt", "reader-moves");
59+ let state = adapter.apply(adapter.empty(), graph.atom("a0"));
60+ const inputs: Parameters<typeof buildAtom>[1][] = [
61+ { author: "writer", message: "Move", move: { file: "f.txt", start: 1, end: 2, to: "g.txt", at: 1 } },
62+ { author: "writer", message: "Delete file", edits: [{ file: "f.txt", old: "one\nthree\n", new: "" }] },
63+ { author: "writer", message: "Recreate file", edits: [{ file: "f.txt", old: "", new: "reborn\n" }] },
64+ { author: "writer", message: "Move back", move: { file: "g.txt", start: 1, end: 2, to: "f.txt", at: 0 } },
65+ ];
66+ for (const input of inputs) {
67+ const expected = buildAtom(repo.view(), input),
68+ reader = new ProjectionReader(adapter, state, new ProjectionReadScope(graph, () => graph).guard(graph));
69+ const actual = buildAtom(reader, input);
70+ assert.deepEqual(actual, expected);
71+ graph.add(actual);
72+ repo.graph.add(expected);
73+ repo.shared.add(expected.id);
74+ state = adapter.apply(state, actual);
75+ const projected = new ProjectionReader(adapter, state, new ProjectionReadScope(graph, () => graph).guard(graph));
76+ t.mock.method(projected, "parentOf", () => {
77+ throw Error("line ancestry traversal forbidden");
78+ });
79+ for (const path of ["f.txt", "g.txt"]) {
80+ assert.deepEqual(projected.sequence(path), repo.view().sequence(path));
81+ for (const line of projected.sequence(path))
82+ assert.equal(projected.fileOf(line.id), repo.view().fileOf(line.id));
83+ }
84+ }
85+ } finally {
86+ storage.db.close();
87+ }
88+});
90+test("reader orders deletion contributors by Lamport before sequence and treats unknown membership as absent", () => {
91+ const storage = new SqlState();
92+ try {
93+ const repo = Repo.init({ "f.txt": "target\n", "g.txt": "other\n" });
94+ const chain = repo.edit({ edits: [{ file: "g.txt", old: "other", new: "changed" }] });
95+ const high = repo.edit({ edits: [{ file: "f.txt", old: "target\n", new: "" }], needs: [chain.id] });
96+ const low = repo.edit({ edits: [{ file: "f.txt", old: "target\n", new: "" }] }, ["a0"]);
97+ assert.ok(repo.graph.lamportOfSeq(high.seq) > repo.graph.lamportOfSeq(low.seq));
98+ assert.ok(high.seq < low.seq);
99+ const graph = new Graph({ storage: new CachedStateStorage(storage) });
100+ const adapter = new ExperimentalMarkerProjection(storage, graph, "f.txt", "reader-priority");
101+ let state = adapter.empty();
102+ for (const id of ["a0", chain.id, high.id, low.id]) {
103+ const atom = repo.graph.atom(id);
104+ graph.add(atom);
105+ state = adapter.apply(state, atom);
106+ }
107+ const reader = new ProjectionReader(adapter, state, new ProjectionReadScope(graph, () => graph).guard(graph));
108+ assert.deepEqual(reader.sequence("f.txt"), repo.view().sequence("f.txt"));
109+ assert.equal(reader.set.has("unknown-atom"), false);
110+ } finally {
111+ storage.db.close();
112+ }
113+});
MCP
compare on this site's /mcp
CLI
abso diff 142 143 src/engine/test/projection-reader.test.ts --json
JSON
/christopher/abso-core/compare/142..143?file=src%2Fengine%2Ftest%2Fprojection-reader.test.ts&format=json