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

Compare

+137 −0 in 1 place
new file, 137 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("projected text streams lines and line lookup does not read file text", (t) => {
14+ const storage = new SqlState();
15+ t.after(() => storage.db.close());
16+ const text = `${"x".repeat(40000)}\nsecond\nthird\n`;
17+ const repo = Repo.init({ "f.txt": text, "empty.txt": "" });
18+ const graph = new Graph({ storage: new CachedStateStorage(storage) });
19+ graph.add(repo.graph.atom("a0"));
20+ const adapter = new ExperimentalMarkerProjection(storage, graph, "f.txt", "streamed-text");
21+ const state = adapter.apply(adapter.empty(), graph.atom("a0"));
22+ const reader = new ProjectionReader(adapter, state, () => {});
23+ t.mock.method(reader, "lines", () => {
24+ throw Error("full line array forbidden");
25+ });
26+ assert.equal(reader.text("f.txt"), text);
27+ assert.equal(reader.text("empty.txt"), "");
28+ assert.equal(reader.text("missing.txt"), "");
29+ const ids = [...adapter.lineIds(state, "f.txt")];
30+ t.mock.method(graph, "textOf", () => {
31+ throw Error("line lookup must not read text");
32+ });
33+ for (let i = 0; i < ids.length; i++) assert.equal(reader.lineNumber("f.txt", ids[i]!), i);
34+ assert.equal(reader.lineNumber("f.txt", "missing"), -1);
35+});
37+test("unchanged atom builder consumes the private reader for replacement and insertion edits", () => {
38+ const storage = new SqlState();
39+ try {
40+ const repo = Repo.init({ "f.txt": "one\ntwo\nthree\n" });
41+ const graph = new Graph({ storage: new CachedStateStorage(storage) });
42+ graph.add(repo.graph.atom("a0"));
43+ const adapter = new ExperimentalMarkerProjection(storage, graph, "f.txt", "builder-reader");
44+ let state = adapter.apply(adapter.empty(), graph.atom("a0"));
45+ for (let i = 0; i < 16; i++) {
46+ const input = {
47+ author: "writer",
48+ message: `Edit ${i}`,
49+ time: i,
50+ edits: [
51+ {
52+ file: "f.txt",
53+ old: repo.view().text("f.txt"),
54+ new: `one\nrevision ${i}\nthree\n${i % 2 ? "extra\n" : ""}`,
55+ },
56+ ],
57+ };
58+ const expected = buildAtom(repo.view(), input);
59+ const reader = new ProjectionReader(adapter, state, new ProjectionReadScope(graph, () => graph).guard(graph));
60+ const actual = buildAtom(reader, input);
61+ assert.deepEqual(actual, expected);
62+ graph.add(actual);
63+ repo.graph.add(expected);
64+ repo.shared.add(expected.id);
65+ state = adapter.apply(state, actual);
66+ assert.equal(
67+ new ProjectionReader(adapter, state, new ProjectionReadScope(graph, () => graph).guard(graph)).text("f.txt"),
68+ repo.view().text("f.txt"),
69+ );
70+ }
71+ } finally {
72+ storage.db.close();
73+ }
74+});
76+test("private reader builds cross-file moves and resurrects a deleted file", (t) => {
77+ const storage = new SqlState();
78+ try {
79+ const repo = Repo.init({ "f.txt": "one\ntwo\nthree\n", "g.txt": "other\n" });
80+ const graph = new Graph({ storage: new CachedStateStorage(storage) });
81+ graph.add(repo.graph.atom("a0"));
82+ const adapter = new ExperimentalMarkerProjection(storage, graph, "f.txt", "reader-moves");
83+ let state = adapter.apply(adapter.empty(), graph.atom("a0"));
84+ const inputs: Parameters<typeof buildAtom>[1][] = [
85+ { author: "writer", message: "Move", move: { file: "f.txt", start: 1, end: 2, to: "g.txt", at: 1 } },
86+ { author: "writer", message: "Delete file", edits: [{ file: "f.txt", old: "one\nthree\n", new: "" }] },
87+ { author: "writer", message: "Recreate file", edits: [{ file: "f.txt", old: "", new: "reborn\n" }] },
88+ { author: "writer", message: "Move back", move: { file: "g.txt", start: 1, end: 2, to: "f.txt", at: 0 } },
89+ ];
90+ for (const input of inputs) {
91+ const expected = buildAtom(repo.view(), input),
92+ reader = new ProjectionReader(adapter, state, new ProjectionReadScope(graph, () => graph).guard(graph));
93+ const actual = buildAtom(reader, input);
94+ assert.deepEqual(actual, expected);
95+ graph.add(actual);
96+ repo.graph.add(expected);
97+ repo.shared.add(expected.id);
98+ state = adapter.apply(state, actual);
99+ const projected = new ProjectionReader(adapter, state, new ProjectionReadScope(graph, () => graph).guard(graph));
100+ t.mock.method(projected, "parentOf", () => {
101+ throw Error("line ancestry traversal forbidden");
102+ });
103+ for (const path of ["f.txt", "g.txt"]) {
104+ assert.deepEqual(projected.sequence(path), repo.view().sequence(path));
105+ for (const line of projected.sequence(path))
106+ assert.equal(projected.fileOf(line.id), repo.view().fileOf(line.id));
107+ }
108+ }
109+ } finally {
110+ storage.db.close();
111+ }
112+});
114+test("reader orders deletion contributors by Lamport before sequence and treats unknown membership as absent", () => {
115+ const storage = new SqlState();
116+ try {
117+ const repo = Repo.init({ "f.txt": "target\n", "g.txt": "other\n" });
118+ const chain = repo.edit({ edits: [{ file: "g.txt", old: "other", new: "changed" }] });
119+ const high = repo.edit({ edits: [{ file: "f.txt", old: "target\n", new: "" }], needs: [chain.id] });
120+ const low = repo.edit({ edits: [{ file: "f.txt", old: "target\n", new: "" }] }, ["a0"]);
121+ assert.ok(repo.graph.lamportOfSeq(high.seq) > repo.graph.lamportOfSeq(low.seq));
122+ assert.ok(high.seq < low.seq);
123+ const graph = new Graph({ storage: new CachedStateStorage(storage) });
124+ const adapter = new ExperimentalMarkerProjection(storage, graph, "f.txt", "reader-priority");
125+ let state = adapter.empty();
126+ for (const id of ["a0", chain.id, high.id, low.id]) {
127+ const atom = repo.graph.atom(id);
128+ graph.add(atom);
129+ state = adapter.apply(state, atom);
130+ }
131+ const reader = new ProjectionReader(adapter, state, new ProjectionReadScope(graph, () => graph).guard(graph));
132+ assert.deepEqual(reader.sequence("f.txt"), repo.view().sequence("f.txt"));
133+ assert.equal(reader.set.has("unknown-atom"), false);
134+ } finally {
135+ storage.db.close();
136+ }
137+});
MCP
compare on this site's /mcp
CLI
abso diff 97 318 src/engine/test/projection-reader.test.ts --json
JSON
/christopher/abso-core/compare/97..318?file=src%2Fengine%2Ftest%2Fprojection-reader.test.ts&format=json