- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/worker/project/test/same-line.test.ts?format=json
100 linesFirst import 96% · rename 3% · infra-split 1%Last change rename in version 100, 3 versions changed it
1// Both sides changing the same line (#37): a sync
2// showed the collision with both lines in the file, and the next sync, on
3// unrelated work, merged from a base that already had their line. The draft's
4// copy of both lines then read as the draft adding one, and the collision was
5// gone with both lines kept. Since #11 the first sync writes markers, and they
6// stay until the agent settles them.
8import assert from "node:assert/strict";
9import { test } from "node:test";
10import { MemoryStore, Project } from "../project.ts";
12const GAUGE = [
13 "export function drawHeader(ctx: Ctx, b: Boiler, hot: number) {",
14 " ctx.fillText('Boiler', 14, 24);",
15 " ctx.fillText(b.stall > 0 ? 'valve blown' : `works ×${b.bonus}`, 186, 24);",
16 "}",
17 "",
18].join("\n");
20function setup() {
21 const project = new Project(new MemoryStore());
22 project.init({ "src/smoke/gauge.ts": GAUGE, "src/other.ts": "export const other = 1;\n" }, 0);
23 for (const a of ["writer1", "builder5", "tester1"]) project.sync(a);
24 // writer1 changes the words; builder5 adds a third case to the same line, and a line of its own above.
25 project.edit(
26 "writer1",
27 { file: "src/smoke/gauge.ts", old: "'valve blown' : `works", new: "'valve lifted' : `all output" },
28 1,
29 );
30 assert.equal(project.publish("writer1", "Words", 2).ok, true);
31 project.record(
32 "builder5",
33 {
34 "src/smoke/gauge.ts": GAUGE.replace("'Boiler', 14, 24);", "'Boiler', 14, 24);\n ctx.fillStyle = 'red';").replace(
35 "'valve blown' : `works",
36 "'valve blown' : hot > 0.3 ? 'ease off!' : `works",
37 ),
38 },
39 3,
40 );
41 return project;
42}
44const markerLines = (text: string) =>
45 text.split("\n").filter((l) => /^(<<<<<<< yours|\|\|\|\|\|\|\| before|=======$|>>>>>>> theirs)/.test(l));
47test("a same-line collision a pull showed, with markers, still stands after the next pull brings unrelated work", () => {
48 const project = setup();
49 const first = project.sync("builder5");
50 assert.deepEqual(
51 first.collisions.map((c) => [c.kind, c.marked, c.theirs.agent, c.theirs.version]),
52 [["lines", true, "writer1", 1]],
53 );
54 assert.equal(markerLines(project.draftOf("builder5")!.view.text("src/smoke/gauge.ts")).length, 4);
55 // Someone else publishes something unrelated; builder5 syncs again.
56 project.edit("tester1", { file: "src/other.ts", old: "1", new: "2" }, 4);
57 assert.equal(project.publish("tester1", "Other", 5).ok, true);
58 const second = project.sync("builder5");
59 assert.deepEqual(
60 second.collisions.map((c) => [c.kind, c.marked]),
61 [["lines", true]],
62 );
63 assert.equal(second.merged, undefined);
64 assert.equal(markerLines(project.draftOf("builder5")!.view.text("src/smoke/gauge.ts")).length, 4);
65 assert.equal(project.publish("builder5", "Third case", 6).ok, false);
66});
68test("settling it by editing the block to one line lets the push through, and writer1 hears what was kept", () => {
69 const project = setup();
70 project.sync("builder5");
71 const text = project.draftOf("builder5")!.view.text("src/smoke/gauge.ts");
72 const lines = text.split("\n");
73 const start = lines.indexOf("<<<<<<< yours (unpublished)");
74 const end = lines.findIndex((l) => l.startsWith(">>>>>>> theirs: "));
75 const one =
76 " ctx.fillText(b.stall > 0 ? 'valve lifted' : hot > 0.3 ? 'ease off!' : `all output ×${b.bonus}`, 186, 24);";
77 project.record(
78 "builder5",
79 { "src/smoke/gauge.ts": [...lines.slice(0, start), one, ...lines.slice(end + 1)].join("\n") },
80 4,
81 );
82 const published = project.publish("builder5", "Third case on the new words", 5);
83 assert.deepEqual(published.ok && published.settled, [
84 { file: "src/smoke/gauge.ts", kept: "rewrote", theirs: { agent: "writer1", version: 1 } },
85 ]);
86 assert.equal(
87 project
88 .files()
89 ["src/smoke/gauge.ts"]!.split("\n")
90 .filter((l) => l.includes("186, 24")).length,
91 1,
92 );
93 const heard = project.news("writer1").news;
94 assert.ok(
95 heard.includes(
96 "builder5 settled its collision with your version 1 in src/smoke/gauge.ts, pushing version 2: it kept part of each side or rewrote them. abso show 2:src/smoke/gauge.ts shows the file.",
97 ),
98 heard.join("\n"),
99 );
100});