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

Compare

+360 −1 in 6 places
new file, 55 lines
1+// Moves before laying out files (abso 714, piece 3): expressMoves looks at the draft's own written and deleted lines
2+// first, and lays out no file when none of its written lines with real content has a deleted line's text. moves.test.ts
3+// covers the moves themselves.
4+
5+import assert from "node:assert/strict";
6+import { test } from "node:test";
7+import type { Graph } from "../../../src/engine/index.ts";
8+import { type ExpressMovesHost, expressMoves } from "../express-moves.ts";
9+import type { AgentState } from "../project-types.ts";
11+/** A draft of two atoms: "del" deletes one line, "add" writes the others. Any view laid out throws. */
12+function host(deleted: string, written: string[]): ExpressMovesHost {
13+ const texts = [deleted, ...written];
14+ const graph = {
15+ deletedLines: (id: string) => (id === "del" ? ["line-0"] : []),
16+ *eachInsertedLine(id: string) {
17+ if (id === "add") for (let k = 1; k < texts.length; k++) yield `line-${k}`;
18+ },
19+ lineN: (line: string) => Number(line.slice("line-".length)),
20+ *textChunks(n: number) {
21+ yield texts[n]!;
22+ },
23+ textOf: (n: number) => texts[n]!,
24+ } as unknown as Graph;
25+ const laidOut = (): never => {
26+ throw new Error("laid out");
27+ };
28+ return {
29+ graph,
30+ draft: () => ["del", "add"],
31+ agentView: laidOut,
32+ beforeDraft: laidOut,
33+ view: laidOut,
34+ apply: laidOut,
35+ addDraft: laidOut,
36+ recordFile: laidOut,
37+ };
38+}
40+const agent = { name: "ann" } as AgentState;
42+test("an edit that only changes lines lays out no file", () => {
43+ expressMoves(host(" return pi * r * r;", [" return Math.PI * r * r;"]), agent, 1, []);
44+});
46+test("a deleted text written again with only brackets or blanks in common lays out no file", () => {
47+ expressMoves(host("}", [" const tree = parse(p);", "}", ""]), agent, 1, []);
48+});
50+test("a written line with real content that the draft also deleted goes on to the files", () => {
51+ assert.throws(
52+ () => expressMoves(host(" return pi * r * r;", ["", " return pi * r * r;"]), agent, 1, []),
53+ /laid out/,
54+ );
55+});
new file, 49 lines
1+// fileExactAt (version-log.ts, abso Capacity, 2026-10-17): the same answer as fileAt for exactly that spelling, at
2+// every version, read from the file's own lines without the version's list of files. abso's worker/test/
3+// project-files.test.ts checks it on the disk engine, where the list is what costs.
4+
5+import assert from "node:assert/strict";
6+import { test } from "node:test";
7+import { MemoryStore, Project } from "../project.ts";
8+
9+/** Files added, edited, emptied, made binary and taken out, beside others, over six versions. */
10+function history(): Project {
11+ const p = new Project(new MemoryStore(), { hasBlob: () => true });
12+ p.init({ "README.md": "hi\n", "abso.json": '{ "check": "true" }\n', "src/a.ts": "a\n" }, 0);
13+ p.record("ann", { "abso.yml": "pipelines:\n ci:\n on: [push]\n", "docs/abso.yml": "not this one\n" }, 1);
14+ p.publish("ann", "a pipeline", 2);
15+ p.record("ann", { "abso.json": '{ "check": "false" }\n', "empty.txt": "" }, 3, {}, { "abso.yaml": "b".repeat(64) });
16+ p.publish("ann", "a binary, and an empty file", 4);
17+ p.record("ann", { "abso.yml": null, "avcs.json": "{}\n", "src/a.ts": "" }, 5);
18+ p.publish("ann", "the pipeline gone, a file emptied", 6);
19+ return p;
20+}
22+const PATHS = [
23+ "abso.yml",
24+ "abso.yaml",
25+ "abso.json",
26+ "avcs.json",
27+ "docs/abso.yml",
28+ "empty.txt",
29+ "src/a.ts",
30+ "README.md",
31+ "never.txt",
32+];
34+test("fileExactAt answers what fileAt answers for the same spelling, at every version", () => {
35+ const p = history();
36+ const last = p.version;
37+ assert.ok(last >= 3);
38+ for (let v = 0; v <= last; v++)
39+ for (const path of PATHS) assert.deepEqual(p.fileExactAt(path, v), p.fileAt(path, v), `${path} at ${v}`);
40+});
42+test("a name nothing ever wrote is null, and another spelling is that spelling, not the stored one", () => {
43+ const p = history();
44+ const last = p.version;
45+ assert.deepEqual(p.fileExactAt("never.txt", last), { path: "never.txt", version: last, text: null });
46+ // fileAt reads the stored spelling for any spelling (#41); fileExactAt reads only the one asked.
47+ assert.equal((p.fileAt("ABSO.json", last) as { text: string | null }).text, '{ "check": "false" }\n');
48+ assert.deepEqual(p.fileExactAt("ABSO.json", last), { path: "ABSO.json", version: last, text: null });
49+});
Lines 105–124 at 318 (were 105–107 at 293)
105105 ] as const)
106106 assert.deepEqual(project.pathsAt(version).files, oracle.draftOf(agent)!.view.paths(), `paths at ${version}`);
107107});
109+test("an agent's files on a writer, from its base version's kept list when it has nothing of its own, as the in-memory project says", () => {
110+ // abso - Performance (abso 711): a status for an agent behind shared listed its files by laying out every known file.
111+ const oracle = new Project(new MemoryStore());
112+ const project = writer();
113+ history(oracle);
114+ history(project);
115+ // v0 and v1 are behind shared with nothing of their own, v2 is at shared, and bob, cy, dee and eve have drafts.
116+ for (const agent of ["v0", "v1", "v2", "bob", "cy", "dee", "eve"]) {
117+ assert.deepEqual(project.agentPaths(agent), oracle.agentPaths(agent), agent);
118+ assert.deepEqual(project.pathsOf(agent), oracle.pathsOf(agent), `${agent} for a reader`);
119+ }
120+ assert.deepEqual(project.agentPaths("v0").files, project.pathsAt(0).files);
121+ assert.equal(project.agentPaths("v0").files.includes("src/gone.ts"), true);
122+ assert.equal(project.agentPaths("v1").files.includes("src/gone.ts"), false);
123+ assert.equal(project.agentPaths("eve").files.includes("src/draft-new.ts"), true);
124+});
Lines 37–42 at 318 (were 37–43 at 293)
3737 );
3838 assert.equal(news[0]!.publisher, "lib");
3939 assert.equal(news[1]!.drafts, 1);
40− assert.equal(news[1]!.files, 1);
4140 assert.equal(news[1]!.changedNames, 1);
4241 assert.equal(news[1]!.news, 1);
4342});
new file, 190 lines
1+// Owed news (abso Capacity, 2026-10-15): with owesDefinitionNews set (abso's disk route sets it), a publish leaves its
2+// definition news for other agents for after its write. The same news, against the publish's version; told once; and
3+// the publisher's own answer as before. abso's worker/test/owed-news.test.ts covers the disk route's marker and alarm.
4+
5+import assert from "node:assert/strict";
6+import { test } from "node:test";
7+import { MemoryStore, Project } from "../project.ts";
8+
9+// abso-core's changed-definition.test.ts scenario: parse.ts defines parsePattern, match.ts imports it.
10+const START = {
11+ "src/parse.ts": [
12+ "export function parsePattern(text: string): Node {",
13+ ' return { kind: "lit", text };',
14+ "}",
15+ "",
16+ "export interface Node {",
17+ " kind: string;",
18+ " text: string;",
19+ "}",
20+ ].join("\n"),
21+ "src/match.ts": [
22+ 'import { parsePattern } from "./parse.ts";',
23+ "",
24+ "export function run(p: string) {",
25+ " return p;",
26+ "}",
27+ ].join("\n"),
28+ "README.md": "Uses parsePattern.\n",
29+};
31+/** bob's draft calls parsePattern; ann's draft changes its signature; cat's touches something else. Nothing published. */
32+function drafts(project: Project): void {
33+ project.init(START, 0);
34+ project.sync("bob");
35+ project.sync("ann");
36+ project.sync("cat");
37+ project.edit(
38+ "bob",
39+ { file: "src/match.ts", old: " return p;\n", new: " const tree = parsePattern(p);\n return tree;\n" },
40+ 1,
41+ );
42+ project.edit(
43+ "ann",
44+ {
45+ file: "src/parse.ts",
46+ old: "parsePattern(text: string): Node",
47+ new: "parsePattern(text: string, flags: string): Node",
48+ },
49+ 2,
50+ );
51+ project.edit("cat", { file: "README.md", old: "Uses parsePattern.", new: "Uses parsePattern, twice." }, 3);
52+}
54+const definitionNews = (news: readonly string[]) => news.filter((n) => /definition of parsePattern/.test(n)).sort();
56+test("the news owed is the news a publish would have told, and the publisher's own answer is the same", () => {
57+ const told = new Project(new MemoryStore());
58+ drafts(told);
59+ const toldAnswer = told.publish("ann", "parsePattern takes flags", 4);
60+ const expected = definitionNews(told.news("bob").news);
61+ assert.equal(expected.length, 1, "the scenario has a definition collision");
63+ const owing = new Project(new MemoryStore());
64+ owing.owesDefinitionNews = true;
65+ drafts(owing);
66+ assert.deepEqual(owing.publish("ann", "parsePattern takes flags", 4), toldAnswer, "the publisher's answer");
67+ const owed = owing.takeOwedDefinitionNews();
68+ assert.deepEqual(owed, [{ version: owing.version, space: owed[0]!.space, publisher: "ann", all: true }]);
69+ assert.deepEqual(owing.takeOwedDefinitionNews(), [], "handed over once");
70+ // Not told yet: bob's news holds no definition news until it's delivered.
71+ assert.deepEqual(definitionNews(owing.news("bob").news), []);
72+ const found = owing.definitionNewsOwed(owed[0]!);
73+ assert.deepEqual(
74+ found.map((f) => f.agent),
75+ ["bob"],
76+ );
77+ assert.ok(owing.deliverOwedNews(found) > 0);
78+ assert.deepEqual(definitionNews(owing.news("bob").news), expected);
79+ // Told twice adds nothing, and a run of the read after delivery finds nothing left.
80+ assert.equal(owing.deliverOwedNews(found), 0);
81+ assert.deepEqual(owing.definitionNewsOwed(owed[0]!), []);
82+});
84+test("worked out against the publish's version, though more was published before the news went out", () => {
85+ const told = new Project(new MemoryStore());
86+ drafts(told);
87+ told.publish("ann", "parsePattern takes flags", 4);
88+ const expected = definitionNews(told.news("bob").news);
90+ const owing = new Project(new MemoryStore());
91+ owing.owesDefinitionNews = true;
92+ drafts(owing);
93+ owing.publish("ann", "parsePattern takes flags", 4);
94+ const [first] = owing.takeOwedDefinitionNews();
95+ // Then parsePattern is removed, before the first publish's news is out: against the newest version the news
96+ // would say "removes"; against the first publish's, it says "changes", as told at publish time.
97+ owing.sync("ann");
98+ owing.edit(
99+ "ann",
100+ {
101+ file: "src/parse.ts",
102+ old: 'export function parsePattern(text: string, flags: string): Node {\n return { kind: "lit", text };\n}\n',
103+ new: "",
104+ },
105+ 5,
106+ );
107+ owing.publish("ann", "parsePattern goes", 6);
108+ assert.ok(owing.deliverOwedNews(owing.definitionNewsOwed(first!)) > 0);
109+ assert.deepEqual(definitionNews(owing.news("bob").news), expected, "the first publish's news, as it was");
110+});
112+test("an agent that synced past the version since isn't told it", () => {
113+ const owing = new Project(new MemoryStore());
114+ owing.owesDefinitionNews = true;
115+ drafts(owing);
116+ owing.publish("ann", "parsePattern takes flags", 4);
117+ const [owed] = owing.takeOwedDefinitionNews();
118+ owing.sync("bob");
119+ assert.deepEqual(owing.definitionNewsOwed(owed!), []);
120+});
122+test("the replay engine tells it at publish time, as before", () => {
123+ const told = new Project(new MemoryStore());
124+ drafts(told);
125+ told.publish("ann", "parsePattern takes flags", 4);
126+ assert.deepEqual(told.takeOwedDefinitionNews(), []);
127+ assert.equal(definitionNews(told.news("bob").news).length, 1);
128+});
130+test("owedAgents lists who may be owed, and the news one agent at a time adds up to the whole (abso 714)", () => {
131+ const owing = new Project(new MemoryStore());
132+ owing.owesDefinitionNews = true;
133+ drafts(owing);
134+ owing.publish("ann", "parsePattern takes flags", 4);
135+ const [owed] = owing.takeOwedDefinitionNews();
136+ assert.deepEqual(owing.owedAgents(owed!), ["bob", "cat"], "every other agent behind it with a draft");
137+ const whole = owing.definitionNewsOwed(owed!);
138+ assert.equal(whole.length, 1);
139+ assert.deepEqual(
140+ owing.owedAgents(owed!).flatMap((agent) => owing.definitionNewsOwed(owed!, [agent])),
141+ whole,
142+ );
143+ owing.sync("bob");
144+ assert.deepEqual(owing.owedAgents(owed!), ["cat"], "synced past it");
145+});
147+test("everything a publish tells other agents is owed and told after it, the same news (abso 714)", () => {
148+ // bob's draft calls parsePattern (definition news), dee's changes the line ann's publish changes (same-lines news),
149+ // and cat's touches nothing of it (no news).
150+ const scenario = (project: Project) => {
151+ drafts(project);
152+ project.sync("dee");
153+ project.edit(
154+ "dee",
155+ { file: "src/parse.ts", old: "parsePattern(text: string): Node", new: "parsePattern(input: string): Node" },
156+ 5,
157+ );
158+ };
159+ const told = new Project(new MemoryStore());
160+ scenario(told);
161+ const toldAnswer = told.publish("ann", "parsePattern takes flags", 6);
162+ const expected = Object.fromEntries(["bob", "cat", "dee"].map((a) => [a, told.news(a).news.toSorted()]));
163+ assert.ok(expected.bob!.length > 0 && expected.dee!.length > 0, "the scenario has both kinds of news");
165+ const owing = new Project(new MemoryStore());
166+ owing.owesDefinitionNews = true;
167+ scenario(owing);
168+ assert.deepEqual(owing.publish("ann", "parsePattern takes flags", 6), toldAnswer, "the publisher's answer");
169+ const [owed] = owing.takeOwedDefinitionNews();
170+ assert.equal(owed!.all, true);
171+ for (const a of ["bob", "cat", "dee"])
172+ assert.deepEqual(owing.news(a).news, [], `${a} is told nothing in the publish`);
173+ const names = owing.owedNewsNames(owed!);
174+ assert.deepEqual(names, ["parsePattern"]);
175+ // One agent at a time, as the host works it out.
176+ for (const agent of owing.owedAgents(owed!)) owing.deliverOwedNews(owing.newsOwed({ ...owed!, names }, [agent]));
177+ for (const a of ["bob", "cat", "dee"]) assert.deepEqual(owing.news(a).news.toSorted(), expected[a], a);
178+ // Twice tells nothing more.
179+ assert.deepEqual(owing.newsOwed({ ...owed!, names }), []);
180+});
182+test("a publish that no other draft can collide with owes nothing", () => {
183+ const owing = new Project(new MemoryStore());
184+ owing.owesDefinitionNews = true;
185+ owing.init({ "a.txt": "one\n" }, 0);
186+ owing.sync("ann");
187+ owing.edit("ann", { file: "a.txt", old: "one", new: "two" }, 1);
188+ owing.publish("ann", "alone", 2);
189+ assert.deepEqual(owing.takeOwedDefinitionNews(), []);
190+});
Lines 36–87 at 318 (were 36–38 at 293)
3636 storage.db.close();
3737 }
3838});
40+test("shared additions read each atom's version from the membership pages, and answer as its events do (abso - Performance, 714)", (t) => {
41+ const storage = new SqlState();
42+ try {
43+ const membership = new Membership(storage),
44+ space = membership.shared;
45+ const ids = (from: number, to: number) => Array.from({ length: to - from }, (_, i) => `a${from + i}`);
46+ const add = (atoms: string[], dropped: string[] = []) =>
47+ addVersion(space, { version: space.versions.length, agent: "test", message: "version", time: 0, atoms, dropped });
48+ // Three pages of atoms; a5 and a400 dropped and a5 back, a601 added and dropped: their events are read.
49+ add(ids(0, 300));
50+ add(ids(300, 600));
51+ add([], ["a5", "a400"]);
52+ add(["a5", "a600"]);
53+ add(["a601"]);
54+ add([], ["a601"]);
55+ const last = space.versions.length - 1;
56+ const { membershipVersions: _pages, ...eventsOnly } = space;
57+ const read = storage.read.bind(storage);
58+ let eventReads = 0;
59+ t.mock.method(storage, "read", (collection: string, key: string) => {
60+ if (collection.startsWith('membership:"":events:')) eventReads++;
61+ return read(collection, key);
62+ });
63+ const walk = (s: typeof space) => {
64+ eventReads = 0;
65+ const out: string[][] = [];
66+ for (let from = 0; from < last; from++)
67+ for (let to = from + 1; to <= last; to++)
68+ out.push([...new SharedAdditions(s, from, membership.at(s, from), membership.at(s, to), to)]);
69+ return { out, eventReads };
70+ };
71+ const paged = walk(space);
72+ const events = walk(eventsOnly);
73+ assert.deepEqual(paged.out, events.out);
74+ assert.ok(
75+ paged.eventReads < events.eventReads / 10,
76+ `${paged.eventReads} event reads against ${events.eventReads}`,
77+ );
78+ assert.deepEqual([...new SharedAdditions(space, 1, membership.at(space, 1), membership.at(space, 3), 3)], ["a600"]);
79+ assert.deepEqual(
80+ [...new SharedAdditions(space, 2, membership.at(space, 2), membership.at(space, 3), 3)],
81+ ["a5", "a600"],
82+ );
83+ assert.deepEqual([...new SharedAdditions(space, 3, membership.at(space, 3), membership.at(space, 5), 5)], []);
84+ } finally {
85+ storage.db.close();
86+ }
87+});
MCP
compare on this site's /mcp
CLI
abso diff 293 318 worker/project/test --json
JSON
/christopher/abso-core/compare/293..318?file=worker%2Fproject%2Ftest&format=json