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
blame on this site's /mcp
CLI
abso blame worker/project/test/markers.test.ts --json
JSON
/christopher/abso-core/blame/worker/project/test/markers.test.ts?format=json
318 linesFirst import 92% · speed 6% · rename 1% · infra-split 1%Last change speed in version 159,

318 lines from 5 changes in 5 versions.

init0Start the project1// Collision markers (#11, round 1, ruled 2026-10-05): a sync writes lines
2// both sides changed differently between diff3 markers; settled means the
3// markers are gone; the other author hears what was kept.
4
5import assert from "node:assert/strict";
6import { test } from "node:test";
7import { blocksIn, keptOf, lostLines, markerBlock, settleLines } from "../markers.ts";
8import { MemoryStore, Project } from "../project.ts";
9
10const GOALS = 'export const GOALS = [\n "Reach the harbour",\n "Light the lamp",\n];\n';
12function collided() {
13 const store = new MemoryStore();
14 const project = new Project(store);
15 project.init({ "src/goals.ts": GOALS, "notes.md": "# notes\n" }, 0);
16 for (const a of ["builder1", "writer1"]) project.sync(a);
17 project.record("writer1", { "src/goals.ts": GOALS.replace('"Reach the harbour"', '"Sail into Smoke Harbour"') }, 1);
18 assert.equal(project.publish("writer1", 'Goal wording "playtest 4"', 2).ok, true);
19 project.record("builder1", { "src/goals.ts": GOALS.replace('"Reach the harbour"', '"Reach harbour"') }, 3);
20 const synced = project.sync("builder1");
21 return { project, store, synced };
24const theirsLine = ">>>>>>> theirs: writer1, version 1 \"Goal wording 'playtest 4'\"";
rename100abso publish is now abso push, abso sync is now abso pull (abso 427) Commands, help, flags, messages, MCP tool names and descriptions, hook text, README, SKILL.md and tests say push and pull; "shared" stays the noun ("Pushed version N"). No aliases, no notices. A queued push that was "pulled" is now "turned back", so pull means one thing. push -f/--force/-u/--all/--tags and pull --rebase/--ff-only/--squash refuse with one plain line naming the abso way; push and pull take no remote or branch. Kept as stored: log entry kinds (publish, sync, pulled), HTTP route paths, the pipeline trigger on: publish, the yours (unpublished) marker, npm-publish.Compare26test("pull writes the block diff3 style, labeled, and lists it as a marked collision", () => {
init0Start the project27 const { project, synced } = collided();
28 const text = project.draftOf("builder1")!.view.text("src/goals.ts");
29 assert.equal(
30 text,
31 [
32 "export const GOALS = [",
33 "<<<<<<< yours (unpublished)",
34 ' "Reach harbour",',
35 "||||||| before (version 0)",
36 ' "Reach the harbour",',
37 "=======",
38 ' "Sail into Smoke Harbour",',
39 theirsLine,
40 ' "Light the lamp",',
41 "];",
42 "",
43 ].join("\n"),
44 );
45 assert.deepEqual(synced.collisions, [
46 {
47 kind: "lines",
48 marked: true,
49 file: "src/goals.ts",
50 yours: { lines: [2, 8], text: ' "Reach harbour",\n' },
51 theirs: {
52 lines: [2, 8],
53 text: ' "Sail into Smoke Harbour",\n',
54 agent: "writer1",
55 message: "Goal wording 'playtest 4'",
56 version: 1,
57 },
58 },
59 ]);
60 // Their line inside the block is still theirs: blame would name writer1.
61 const line = project.draftOf("builder1")!.view.lines("src/goals.ts")[6]!;
62 assert.equal(project.graph.atom(line.atom).author, "writer1");
63});
65test("status lists the open block; an edit to the file says it still needs settling", () => {
66 const { project } = collided();
67 assert.deepEqual(project.status().agents.find((a) => a.agent === "builder1")!.collisions, [
68 {
69 file: "src/goals.ts",
70 lines: [2, 8],
71 theirs: { agent: "writer1", version: 1, message: "Goal wording 'playtest 4'" },
72 },
73 ]);
74 assert.equal(project.status().agents.find((a) => a.agent === "writer1")!.collisions, undefined);
75 const e = project.edit("builder1", { file: "src/goals.ts", old: '"Light the lamp"', new: '"Light the lamp!"' }, 4);
76 assert.deepEqual(e.ok && e.news, [
77 "src/goals.ts still has 1 collision block to settle: abso settle src/goals.ts --yours|--theirs|--both",
78 ]);
79 // Once per count: the next edit says nothing more.
80 const again = project.edit(
81 "builder1",
82 { file: "src/goals.ts", old: '"Light the lamp!"', new: '"Light the lamp."' },
83 5,
84 );
85 assert.deepEqual(again.ok && again.news, []);
86});
88for (const [keep, kept, phrase] of [
89 ["theirs", "theirs", "it kept your lines"],
90 ["yours", "yours", "it kept its own lines, not yours"],
91 ["both", "both", "it kept both its lines and yours"],
92] as const) {
rename100abso publish is now abso push, abso sync is now abso pull (abso 427) Commands, help, flags, messages, MCP tool names and descriptions, hook text, README, SKILL.md and tests say push and pull; "shared" stays the noun ("Pushed version N"). No aliases, no notices. A queued push that was "pulled" is now "turned back", so pull means one thing. push -f/--force/-u/--all/--tags and pull --rebase/--ff-only/--squash refuse with one plain line naming the abso way; push and pull take no remote or branch. Kept as stored: log entry kinds (publish, sync, pulled), HTTP route paths, the pipeline trigger on: publish, the yours (unpublished) marker, npm-publish.Compare93 test(`settled by keeping ${keep}: the push goes through, logs it, and writer1 hears "${phrase}"`, () => {
init0Start the project94 const { project, store } = collided();
95 const lines = project
96 .draftOf("builder1")!
97 .view.lines("src/goals.ts")
98 .map((l) => l.text);
99 project.record("builder1", { "src/goals.ts": settleLines(lines, keep).lines.join("\n") }, 4);
100 const p = project.publish("builder1", "Settled", 5);
101 assert.deepEqual(p.ok && p.settled, [{ file: "src/goals.ts", kept, theirs: { agent: "writer1", version: 1 } }]);
102 assert.ok(
103 project
104 .news("writer1")
105 .news.includes(
rename100abso publish is now abso push, abso sync is now abso pull (abso 427) Commands, help, flags, messages, MCP tool names and descriptions, hook text, README, SKILL.md and tests say push and pull; "shared" stays the noun ("Pushed version N"). No aliases, no notices. A queued push that was "pulled" is now "turned back", so pull means one thing. push -f/--force/-u/--all/--tags and pull --rebase/--ff-only/--squash refuse with one plain line naming the abso way; push and pull take no remote or branch. Kept as stored: log entry kinds (publish, sync, pulled), HTTP route paths, the pipeline trigger on: publish, the yours (unpublished) marker, npm-publish.Compare106 `builder1 settled its collision with your version 1 in src/goals.ts, pushing version 2: ${phrase}. abso show 2:src/goals.ts shows the file.`,
init0Start the project107 ),
108 );
109 assert.deepEqual(project.status().agents.find((a) => a.agent === "builder1")!.collisions, undefined);
110 // Logged on the publish, and the log loads back the same.
111 const entry = store.entries.find((e) => e.type === "publish" && e.version === 2);
112 assert.deepEqual(entry?.type === "publish" && entry.settled, [
113 { file: "src/goals.ts", kept, theirs: { agent: "writer1", version: 1 } },
114 ]);
115 assert.deepEqual(Project.load(store.entries, new MemoryStore()).files(), project.files());
116 });
rename100abso publish is now abso push, abso sync is now abso pull (abso 427) Commands, help, flags, messages, MCP tool names and descriptions, hook text, README, SKILL.md and tests say push and pull; "shared" stays the noun ("Pushed version N"). No aliases, no notices. A queued push that was "pulled" is now "turned back", so pull means one thing. push -f/--force/-u/--all/--tags and pull --rebase/--ff-only/--squash refuse with one plain line naming the abso way; push and pull take no remote or branch. Kept as stored: log entry kinds (publish, sync, pulled), HTTP route paths, the pipeline trigger on: publish, the yours (unpublished) marker, npm-publish.Compare119test("push refuses while the markers are in; asIs keeps both, lists the file, and tells writer1", () => {
init0Start the project120 const { project } = collided();
121 const refused = project.publish("builder1", "Not yet", 4);
122 assert.deepEqual(!refused.ok && refused.collisions.map((c) => [c.kind, c.marked, c.file, c.yours.lines]), [
123 ["lines", true, "src/goals.ts", [2, 8]],
124 ]);
125 const p = project.publish("builder1", "Both belong", 5, { asIs: true });
126 assert.deepEqual(p.ok && p.settled, [
127 { file: "src/goals.ts", kept: "both", theirs: { agent: "writer1", version: 1 } },
128 ]);
129 assert.equal(
130 project.files()["src/goals.ts"],
131 'export const GOALS = [\n "Reach harbour",\n "Sail into Smoke Harbour",\n "Light the lamp",\n];\n',
132 );
133 assert.equal(project.news("writer1").news.length, 1);
134});
136test("a marker line left behind is refused; a document that shows markers is not", () => {
137 const { project } = collided();
138 const lines = project
139 .draftOf("builder1")!
140 .view.lines("src/goals.ts")
141 .map((l) => l.text);
142 // Keeps yours, but leaves the closing marker in.
143 const kept = settleLines(lines, "yours").lines;
144 kept.splice(2, 0, theirsLine);
145 project.record("builder1", { "src/goals.ts": kept.join("\n") }, 4);
146 const refused = project.publish("builder1", "Stray", 5);
147 assert.deepEqual(!refused.ok && refused.collisions.map((c) => [c.marked, c.yours.lines]), [[true, [3, 3]]]);
148 project.record("builder1", { "src/goals.ts": settleLines(lines, "yours").lines.join("\n") }, 6);
149 project.record(
150 "builder1",
151 {
152 "notes.md": "# notes\n\nGit writes conflicts like this:\n\n<<<<<<< HEAD\nmine\n=======\ntheirs\n>>>>>>> branch\n",
153 },
154 7,
155 );
156 assert.equal(project.publish("builder1", "Docs", 8).ok, true);
157});
159test("the open block survives a reload of the log", () => {
160 const { project, store } = collided();
161 const loaded = Project.load(store.entries, new MemoryStore());
162 assert.deepEqual(
163 loaded.status().agents.find((a) => a.agent === "builder1")!.collisions,
164 project.status().agents.find((a) => a.agent === "builder1")!.collisions,
165 );
166 assert.equal(loaded.publish("builder1", "Not yet", 4).ok, false);
167});
infra-split37Comments and test names give each reason in plain words, without naming who raised it Notes like "(#37, Builder 5)" or "(AVCS - Security)" become "(#37)" or go, and a private commit hash after a name goes with it. Issue numbers and references such as git's CVE-2019-1353 stay. Only comments and test names change; no behavior changes.Compare169test("a block is labeled by whose lines are newer, not by an older line it starts with (#37)", () => {
init0Start the project170 const project = new Project(new MemoryStore());
171 project.init({ "fronts.ts": "a\nb\nc\nd\n" }, 0);
172 for (const a of ["builder3", "artist1"]) project.sync(a);
173 project.edit("builder3", { file: "fronts.ts", old: "b\n", new: "b by builder3\n" }, 1);
174 project.publish("builder3", "Storm card", 2);
175 for (const a of ["builder3", "artist1"]) project.sync(a);
176 project.edit("artist1", { file: "fronts.ts", old: "c\n", new: "c by artist1\n" }, 3);
177 project.publish("artist1", "Fronts art", 4);
178 // builder3's draft changes both lines: the block's theirs side starts with builder3's own older line.
179 project.edit("builder3", { file: "fronts.ts", old: "b by builder3\nc\n", new: "b again\nc again\n" }, 5);
180 const s = project.sync("builder3");
181 assert.deepEqual(
182 s.collisions.map((c) => [c.marked, c.theirs.agent, c.theirs.version, c.theirs.message]),
183 [[true, "artist1", 2, "Fronts art"]],
184 );
185 assert.match(
186 project.draftOf("builder3")!.view.text("fronts.ts"),
187 /^>>>>>>> theirs: artist1, version 2 "Fronts art"$/m,
188 );
189});
infra-split39More comments and test names give their reason without naming who raised it The same cleanup as version 37, for notes it missed because they were wrapped or worded differently: "(#37, Playtester 1)" becomes "(#37)", "(#39, agreed with Engine)" becomes "(#39)", and a commit hash after a name goes with the name. Issue numbers stay. No behavior changes.Compare191test("a settle that loses lines both sides still had says so, to the settler and the other author (#37)", () => {
init0Start the project192 const notes =
193 "# playtest\n- [ ] **Beam engine on a Cove with no lighthouse**\n Check it feeds the Fjord.\n- [ ] **Gauge**\n";
194 const project = new Project(new MemoryStore());
195 project.init({ "notes.md": notes }, 0);
196 for (const a of ["builder5", "tester1"]) project.sync(a);
197 project.edit(
198 "tester1",
199 { file: "notes.md", old: " Check it feeds the Fjord.\n", new: " Check it feeds the Fjord. *T1: still open*\n" },
200 1,
201 );
202 project.publish("tester1", "Retest", 2);
203 project.edit(
204 "builder5",
205 {
206 file: "notes.md",
207 old: "- [ ] **Beam engine on a Cove with no lighthouse**\n Check it feeds the Fjord.\n",
208 new: "- [x] **Beam engine on a Cove with no lighthouse**\n Check it feeds the Fjord. *B5: fixed*\n",
209 },
210 3,
211 );
212 project.sync("builder5");
213 // The settle drops the item's header and its annotation line, and keeps only the next item.
214 project.record("builder5", { "notes.md": "# playtest\n- [ ] **Gauge**\n" }, 4);
215 const p = project.publish("builder5", "Tick", 5);
216 assert.deepEqual(p.ok && p.settled, [
217 {
218 file: "notes.md",
219 kept: "rewrote",
220 theirs: { agent: "tester1", version: 1 },
221 lost: ["- [x] **Beam engine on a Cove with no lighthouse**", " Check it feeds the Fjord. *B5: fixed*"],
222 },
223 ]);
224 assert.match(
225 project.news("tester1").news[0]!,
226 /It also lost 2 lines you both still had: "- \[x\] \*\*Beam engine on a Cove with no lighthouse\*\*", "Check it feeds the Fjord\. \*B5: fixed\*"\./,
227 );
228});
230test("lostLines: a rewording is not a loss; a line gone in every version is", () => {
231 const region = {
232 file: "n.md",
233 yours: ["- [x] **Gauge shows coin**", " rate. *B1: sellers too*"],
234 base: ["- [ ] **Gauge shows coin**", " rate."],
235 theirs: ["- [ ] **Gauge shows coin**", " rate. *B5: worth +N coin*"],
236 agent: "t",
237 version: 1,
238 message: "m",
239 };
240 assert.deepEqual(
241 lostLines(["- [x] **Gauge shows coin**", " rate. *B5: worth +N coin* *B1: sellers too*"], region),
242 [],
243 );
244 assert.deepEqual(lostLines([" rate. *B5: worth +N coin*"], region), ["- [x] **Gauge shows coin**"]);
245});
speed159Settles say what they kept in plain words: a held push's hint says the pull writes a marker block, the change page reads "kept bob's" or "rewrote both sides" rather than "kept rewrote", and a line rewritten longer no longer counts as lostCompare247test("lostLines: a line rewritten longer, keeping its words and adding a reason, is not a loss", () => {
248 const region = {
249 file: "store-policy.md",
250 yours: ["Free shipping on orders over $35."],
251 base: ["Free shipping on orders over $50."],
252 theirs: ["Free shipping on orders over $75."],
253 agent: "alice",
254 version: 1,
255 message: "m",
256 };
257 const settled = (line: string) => ["# Store policy", "", line, "Returns accepted within 30 days."];
258 assert.deepEqual(
259 lostLines(settled("Free shipping on orders over $50 (alice wants $75, bob wants $35: decided by Friday)."), region),
260 [],
261 );
262 assert.deepEqual(lostLines(settled("Free shipping on orders over $60."), region), []);
263 assert.deepEqual(lostLines(settled("Shipping is free."), region), ["Free shipping on orders over $35."]);
264});
init0Start the project266test("markers.ts: blocks round-trip, settle, and say what was kept", () => {
267 const who = { agent: "a", version: 3, message: 'Line one\nline two "quoted"' };
268 const block = markerBlock(["y1", "y2"], ["b"], 2, ["t1"], who);
269 assert.deepEqual(block, [
270 "<<<<<<< yours (unpublished)",
271 "y1",
272 "y2",
273 "||||||| before (version 2)",
274 "b",
275 "=======",
276 "t1",
277 '>>>>>>> theirs: a, version 3 "Line one"',
278 ]);
279 const lines = ["top", ...block, "bottom"];
280 assert.deepEqual(blocksIn(lines), [
281 { start: 1, end: 8, yours: ["y1", "y2"], base: ["b"], theirs: ["t1"], agent: "a", version: 3, message: "Line one" },
282 ]);
283 assert.deepEqual(settleLines(lines, "both").lines, ["top", "y1", "y2", "t1", "bottom"]);
284 const region = { file: "f", yours: ["y1", "y2"], base: ["b"], theirs: ["t1"], ...who };
285 assert.equal(keptOf(["top", "t1", "bottom"], region), "theirs");
286 assert.equal(keptOf(["top", "y1", "y2", "bottom"], region), "yours");
287 assert.equal(keptOf(["top", "new", "bottom"], region), "rewrote");
288 // A side that deleted its lines is kept when the other side's lines are gone.
289 assert.equal(keptOf(["top", "bottom"], { ...region, yours: [] }), "yours");
290});
infra-split37Comments and test names give each reason in plain words, without naming who raised it Notes like "(#37, Builder 5)" or "(AVCS - Security)" become "(#37)" or go, and a private commit hash after a name goes with it. Issue numbers and references such as git's CVE-2019-1353 stay. Only comments and test names change; no behavior changes.Compare292test("keeping both, with an edit to a line their block left as it was, is both, not yours (#37)", () => {
init0Start the project293 // The real region from the game log: writer1 added the isle-glut hint above the
294 // isle-welcome line it left alone; builder2 rewrote isle-welcome and added a comment.
295 const welcome =
296 " { id: 'isle-welcome', when: () => true, text: 'Coral Isle. Buildings here cost pearls: click the dive boat to dive for them.' },";
297 const glut =
298 " { id: 'isle-glut', when: (s) => !lv(s, 'lagoonmarket'), text: 'Fish is piling up with nowhere to sell it.' },";
299 const comment = " // Goes once the first dive is made (playtest 7: it outstayed it).";
300 const mine =
301 " { id: 'isle-welcome', when: (s) => !s.ext.isle?.dives, text: 'Coral Isle. Buildings here cost pearls: click the dive boat to dive for them.', transient: true },";
302 const region = {
303 file: "src/render/hints.ts",
304 yours: [comment, mine],
305 base: [welcome],
306 theirs: [glut, welcome],
307 agent: "writer1",
308 version: 533,
309 message: "hints",
310 };
311 assert.equal(keptOf(["export const HINTS = [", glut, comment, mine, "];"], region), "both");
312 assert.equal(keptOf(["export const HINTS = [", glut, welcome, "];"], region), "theirs");
313 assert.equal(keptOf(["export const HINTS = [", comment, mine, "];"], region), "yours");
314 // Their hint kept, but only half of builder2's change (no comment): part of a side is a rewrite.
315 assert.equal(keptOf(["export const HINTS = [", glut, mine, "];"], region), "rewrote");
316 assert.equal(keptOf(["export const HINTS = [", glut, comment, welcome, "];"], region), "rewrote");
317 assert.equal(keptOf(["export const HINTS = [", " { id: 'new' },", "];"], region), "rewrote");
318});