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/queued-moves.test.ts?format=json
89 linesFirst import 96% · pinch 2% · rename 2%Last change rename in version 100, 3 versions changed it
1// A publish while the agent's earlier publish still waits in the queue (#39)
2// must leave the queued one's changes alone (abso issue 135, item 4). Moves
3// (#28) are expressed by dropping the draft's changes to the files involved
4// and making them again; when that took a queued item's atoms too, the queue
5// later landed the item with a tie depending on discarded atoms, and the
6// project's log no longer loaded (typescript-rs, entries 6017 and 6504).
7
8import assert from "node:assert/strict";
9import { test } from "node:test";
10import { type EditBody, MemoryStore, Project } from "../project.ts";
12function edit(project: Project, agent: string, body: EditBody, time: number): void {
13 const a = project.edit(agent, body, time);
14 if (!a.ok) throw new Error(`edit by ${agent} was out of step`);
17test("a move in a later push leaves the agent's queued push whole, and both land", () => {
18 const store = new MemoryStore();
19 const project = new Project(store);
20 project.checkerReady = true;
21 project.init(
22 {
23 "avcs.json": `${JSON.stringify({ queue: true })}\n`,
24 "a.ts": "export const a = 1;\nexport function kept() {\n\treturn 'x';\n}\n",
25 "c.ts": "export const c = 1;\n",
26 },
27 0,
28 );
29 project.sync("one");
30 // The first publish changes a.ts and waits in the queue.
31 edit(project, "one", { file: "a.ts", old: "const a = 1", new: "const a = 2" }, 1);
32 const first = project.publish("one", "a is 2", 2);
33 assert.ok(first.ok && "queued" in first, JSON.stringify(first));
34 // The second moves kept() from a.ts to c.ts, so a.ts is a file the move involves.
35 edit(project, "one", { file: "a.ts", old: "export function kept() {\n\treturn 'x';\n}\n", new: "" }, 3);
36 edit(
37 project,
38 "one",
39 {
40 file: "c.ts",
41 old: "export const c = 1;\n",
42 new: "export const c = 1;\nexport function kept() {\n\treturn 'x';\n}\n",
43 },
44 4,
45 );
46 const second = project.publish("one", "move kept to c", 5);
47 assert.ok(second.ok && "queued" in second, JSON.stringify(second));
49 const ids = project.queue().items.map((q) => q.id);
50 assert.equal(ids.length, 2);
51 project.queueChecking(2);
52 assert.deepEqual(
53 project.queueLand(2, 6).versions.map((v) => v.version),
54 [1, 2],
55 );
56 assert.equal(project.files()["a.ts"], "export const a = 2;\n");
57 assert.equal(project.files()["c.ts"], "export const c = 1;\nexport function kept() {\n\treturn 'x';\n}\n");
58 // The log replays: no publish depends on a discarded atom.
59 const again = Project.load(store.entries, new MemoryStore());
60 assert.equal(again.files()["a.ts"], "export const a = 2;\n");
61 assert.equal(again.version, 2);
62});
64test("restore while a push waits in the queue undoes only the later edits, and the queued one lands", () => {
65 const store = new MemoryStore();
66 const project = new Project(store);
67 project.checkerReady = true;
68 project.init(
69 { "avcs.json": `${JSON.stringify({ queue: true })}\n`, "a.ts": "export const a = 1;\nexport const b = 1;\n" },
70 0,
71 );
72 project.sync("one");
73 edit(project, "one", { file: "a.ts", old: "const a = 1", new: "const a = 2" }, 1);
74 const first = project.publish("one", "a is 2", 2);
75 assert.ok(first.ok && "queued" in first, JSON.stringify(first));
76 edit(project, "one", { file: "a.ts", old: "const b = 1", new: "const b = 2" }, 3);
77 const r = project.restore("one", ["a.ts"], 4);
78 assert.equal(r.files["a.ts"], "export const a = 2;\nexport const b = 1;\n", "the queued change stays");
79 project.queueChecking(1);
80 assert.deepEqual(
81 project.queueLand(1, 5).versions.map((v) => v.version),
82 [1],
83 );
84 assert.equal(project.files()["a.ts"], "export const a = 2;\nexport const b = 1;\n");
85 assert.equal(
86 Project.load(store.entries, new MemoryStore()).files()["a.ts"],
87 "export const a = 2;\nexport const b = 1;\n",
88 );
89});