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/spelling-clash.test.ts?format=json
121 linesFirst import 98% · rename 2% · infra-split 1%Last change rename in version 100, 3 versions changed it
1// Two spellings of one name never both reach shared (#49): two agents creating README.md and
2// readme.md at once, one record naming both, init, a file and a folder with
3// one name, and plain git. A clash shared already holds isn't charged to new
4// work.
5
6import assert from "node:assert/strict";
7import { test } from "node:test";
8import { MemoryStore, Project } from "../project.ts";
9
10function setup() {
11 const project = new Project(new MemoryStore());
12 project.init({ "x.ts": "x\n" }, 0);
13 for (const a of ["alice", "bob", "carol"]) project.sync(a);
14 return project;
17test("two agents creating one name in two spellings: the second push is refused, naming both", () => {
18 const p = setup();
19 p.record("alice", { "README.md": "# A\n" }, 1);
20 p.record("bob", { "readme.md": "# b\n" }, 2);
21 assert.equal(p.publish("alice", "readme", 3).ok, true);
22 assert.throws(
23 () => p.publish("bob", "readme too", 4),
24 /readme\.md and README\.md would both be in shared, but they're one file/,
25 );
26 assert.deepEqual(Object.keys(p.files()).sort(), ["README.md", "x.ts"]);
27 // Once bob moves his to the stored spelling, it goes.
28 p.sync("bob");
29 assert.ok(p.draftOf("bob")!.view.hasFile("README.md"));
30});
32test("one record naming two spellings, both written, is refused; a rename (one of them null) is not", () => {
33 const p = setup();
34 assert.throws(
35 () => p.record("carol", { "Notes.md": "one\n", "notes.md": "two\n" }, 1),
36 /Notes\.md and notes\.md are one file/,
37 );
38 p.record("carol", { "x.ts": null, "X.ts": "x\n" }, 2);
39 p.publish("carol", "capital X", 3);
40 assert.deepEqual(Object.keys(p.files()), ["X.ts"]);
41});
43test("init with two spellings, or a file and a folder of one name, is refused", () => {
44 assert.throws(
45 () => new Project(new MemoryStore()).init({ "A.ts": "a\n", "a.ts": "b\n" }, 0),
46 /init: A\.ts and a\.ts are one file/,
47 );
48 assert.throws(
49 () => new Project(new MemoryStore()).init({ docs: "d\n", "Docs/readme.md": "r\n" }, 0),
50 /docs is a file, and Docs\/readme\.md puts a file in a folder of that name/,
51 );
52});
54test("a file and a folder of one name, from two agents, either way round", () => {
55 const p = setup();
56 p.record("alice", { docs: "notes\n" }, 1);
57 p.record("bob", { "Docs/readme.md": "# docs\n" }, 2);
58 assert.equal(p.publish("alice", "docs", 3).ok, true);
59 assert.throws(
60 () => p.publish("bob", "docs folder", 4),
61 /Docs\/readme\.md puts a file in folder Docs, but docs is a file of that name/,
62 );
63 const q = setup();
64 q.record("bob", { "Docs/readme.md": "# docs\n" }, 1);
65 q.record("alice", { docs: "notes\n" }, 2);
66 assert.equal(q.publish("bob", "docs folder", 3).ok, true);
67 assert.throws(
68 () => q.publish("alice", "docs", 4),
69 /docs is a file, but Docs\/readme\.md makes a folder of that name/,
70 );
71});
73test("a land of a named draft is checked too, and plain git", () => {
74 const p = setup();
75 p.record("alice", { "Plan.md": "a\n" }, 1);
76 p.publish("alice", "plan", 2);
77 p.switchTo("bob", "side", 3);
78 p.record("bob", { "plan.md": "b\n" }, 4, {}, {}, {}, { exactSpelling: true });
79 p.publish("bob", "plan in side", 5);
80 assert.throws(() => p.land("bob", "land it", 6), /plan\.md and Plan\.md would both be in shared/);
81 assert.throws(
82 () =>
83 p.ingest(
84 {
85 author: "Robin",
86 base: p.version,
87 commits: [{ sha: "abcdef1", message: "two", files: { "x.ts": "x\n", "Y.md": "y\n", "y.md": "z\n" } }],
88 },
89 7,
90 ),
91 /commit abcdef1: Y\.md and y\.md are one file/,
92 );
93});
95test("a clash shared already holds doesn't block work on either file", () => {
96 const old = new MemoryStore();
97 new Project(old).init({ "a.md": "lower\n", "X.md": "upper\n" }, 0);
98 const p = Project.load(JSON.parse(JSON.stringify(old.entries).replaceAll("X.md", "A.md")), new MemoryStore());
99 p.sync("alice");
100 p.record("alice", { "a.md": "lower, edited\n" }, 1, {}, {}, {}, { exactSpelling: true });
101 assert.equal(p.publish("alice", "edit one of them", 2).ok, true);
102});
104test("with the merge queue, a push that clashes with one queued ahead is refused at queue time", () => {
105 const p = new Project(new MemoryStore());
106 p.checkerReady = true;
107 p.init({ "avcs.json": '{"queue": true}\n' }, 0);
108 for (const a of ["alice", "bob"]) p.sync(a);
109 p.record("alice", { "README.md": "# A\n" }, 1);
110 p.record("bob", { "readme.md": "# b\n" }, 2);
111 const first = p.publish("alice", "readme", 3);
112 assert.ok(first.ok && "queued" in first);
113 assert.throws(() => p.publish("bob", "readme too", 4), /readme\.md and README\.md would both be in shared/);
114 assert.equal(p.queue().items.length, 1);
115 // Once the queued one lands, shared holds one spelling (abso issue 68).
116 p.queueLand(p.queue().items[0]!.id, 5);
117 assert.deepEqual(
118 Object.keys(p.files()).filter((f) => f.toLowerCase() === "readme.md"),
119 ["README.md"],
120 );
121});