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
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/worker/project/test/agent-views-shared.test.ts?format=json
113 linescapacity 100%Last change capacity in version 237, 2 versions changed it
1// A draft's view takes its base view's layout of every file the draft doesn't touch (abso Capacity, View.shareFiles).
2// On a writer-backed project every agent's view must still read every file as the in-memory project does: a draft
3// that edits lines moved into another file by a published move, one that deletes such a line, one that only sets an
4// attribute, and one that moves lines itself (which shares nothing).
5
6import assert from "node:assert/strict";
7import { test } from "node:test";
8import { storedArray } from "../../../src/engine/state-source.ts";
9import { SqlState } from "../../../src/engine/test/storage-helper.ts";
10import { MemoryStore, Project } from "../project.ts";
11import type { Entry, ProjectStore } from "../project-types.ts";
13function writer() {
14 const storage = new SqlState();
15 const entries = storedArray<Entry>(storage, "canonical-log");
16 const store: ProjectStore = {
17 append(batch) {
18 for (const entry of batch) entries.push(entry);
19 },
20 };
21 return new Project(store, { writerStorage: storage });
24const AREA = "export function area(r: number) {\n const pi = 3.14;\n return pi * r * r;\n}\n";
25const FILES = {
26 "src/shapes.ts": `// shapes\n${AREA}\nexport function other() {\n return 1;\n}\n`,
27 "src/geometry.ts": "// geometry\n",
28 "src/plain.ts": "one\ntwo\nthree\n",
29 "run.sh": "echo hi\n",
30 "README.md": "readme\n",
31};
33function history(project: Project) {
34 let t = 0;
35 project.init(FILES, t);
36 // ann moves area() into geometry.ts and publishes: its lines were written in shapes.ts.
37 project.edit("ann", { file: "src/shapes.ts", old: AREA, new: "" }, ++t);
38 project.edit("ann", { file: "src/geometry.ts", content: `// geometry\n${AREA}` }, ++t);
39 assert.equal(project.publish("ann", "Move area to geometry", ++t).ok, true);
40 for (const agent of ["bob", "cy", "dee", "eve", "fay"]) project.sync(agent);
41 // bob edits a moved line, cy deletes one, dee touches only plain.ts, eve sets an attribute, fay moves lines.
42 project.edit("bob", { file: "src/geometry.ts", old: "3.14", new: "Math.PI" }, ++t);
43 project.edit("cy", { file: "src/geometry.ts", old: " const pi = 3.14;\n", new: "" }, ++t);
44 project.record("dee", { "src/plain.ts": "one\nTWO\nthree\n" }, ++t);
45 project.record("eve", {}, ++t, { "run.sh": { exec: true } });
46 project.edit("fay", { file: "src/plain.ts", old: "one\ntwo\nthree\n", new: "" }, ++t);
47 project.edit("fay", { file: "src/moved.ts", content: "one\ntwo\nthree\n" }, ++t);
50const read = (project: Project, agent: string) => {
51 const view = project.draftOf(agent)!.view;
52 const out: Record<string, unknown> = {};
53 for (const path of view.paths()) out[path] = [view.text(path), view.attrs(path), view.lines(path).map((l) => l.atom)];
54 return out;
55};
57test("every agent's view reads every file as the in-memory project's, with files shared from the base", () => {
58 const oracle = new Project(new MemoryStore());
59 const project = writer();
60 history(oracle);
61 history(project);
62 for (const agent of ["ann", "bob", "cy", "dee", "eve", "fay"]) {
63 // Twice: the second read takes the shared layouts the first one made.
64 assert.deepEqual(read(project, agent), read(oracle, agent), agent);
65 assert.deepEqual(read(project, agent), read(oracle, agent), `${agent} again`);
66 }
67 assert.match(String(read(oracle, "bob")["src/geometry.ts"]), /Math\.PI/);
68 assert.doesNotMatch(String(read(oracle, "cy")["src/geometry.ts"]), /const pi/);
69 assert.deepEqual(project.tree("", { agent: "cy", authors: true }), oracle.tree("", { agent: "cy", authors: true }));
70});
72// A push landed through the merge queue whose delete and write of the same text became a move, by an agent whose base
73// stays older than the landing, then more drafting in the moved-to file: the diff and every file read as in memory.
74// (Here the move is among the agent's own atoms, so nothing is shared; touched-beyond.test.ts covers work held only
75// by dependency.)
76function landedWithMoves(project: Project) {
77 let t = 0;
78 project.checkerReady = true;
79 project.init(
80 {
81 "avcs.json": `${JSON.stringify({ queue: true })}\n`,
82 "src/shapes.ts": `// shapes\n${AREA}`,
83 "src/geometry.ts": "// geometry\n",
84 "notes.md": "notes\n",
85 },
86 t,
87 );
88 project.sync("ann");
89 project.sync("bob");
90 const land = (agent: string, message: string) => {
91 const queued = project.publish(agent, message, ++t);
92 assert.ok(queued.ok && "queued" in queued, JSON.stringify(queued));
93 project.queueChecking(queued.queued);
94 project.queueLand(queued.queued, ++t);
95 };
96 project.record("bob", { "notes.md": "notes\nbob\n" }, ++t);
97 land("bob", "Notes");
98 project.edit("ann", { file: "src/shapes.ts", old: AREA, new: "" }, ++t);
99 project.edit("ann", { file: "src/geometry.ts", content: `// geometry\n${AREA}` }, ++t);
100 project.record("ann", { "README.md": "readme\n" }, ++t);
101 land("ann", "Move area, add a readme");
102 project.edit("ann", { file: "src/geometry.ts", old: "3.14", new: "Math.PI" }, ++t);
103 project.edit("ann", { file: "README.md", content: "readme\nmore\n" }, ++t);
106test("a draft's diff takes nothing from its base that its landed work holds by dependency", () => {
107 const oracle = new Project(new MemoryStore());
108 const project = writer();
109 landedWithMoves(oracle);
110 landedWithMoves(project);
111 assert.deepEqual(project.diffOf("ann"), oracle.diffOf("ann"));
112 assert.deepEqual(read(project, "ann"), read(oracle, "ann"));
113});