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/queue-driver.test.ts?format=json
211 linesFirst import 88% · onboard 10% · rename 2%Last change onboard in version 209, 3 versions changed it
1// The merge queue's checker loop (#39) on a real project, with the check as a
2// function of the candidate's files: batches land whole, a failing batch is
3// halved to the publish that turned it red, a failure must happen twice,
4// box failures pause instead of blaming anyone, and a red shared lands only
5// what passes.
6
7import assert from "node:assert/strict";
8import { test } from "node:test";
9import { MemoryStore, Project } from "../project.ts";
10import { type Candidate, type Checker, type CheckResult, queueRound } from "../queue-driver.ts";
12const AGENTS = ["b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "b10"];
14function setup() {
15 const project = new Project(new MemoryStore());
16 project.checkerReady = true;
17 const files: Record<string, string> = { "avcs.json": '{"queue": true}\n' };
18 for (const a of AGENTS) files[`${a}.ts`] = `export const ${a} = 0;\n`;
19 project.init(files, 0);
20 for (const a of AGENTS) project.sync(a);
21 return project;
24/** Agent `a` publishes `value` into its own file; it must be queued. */
25function queue(project: Project, a: string, value: string, time = 1): number {
26 const e = project.edit(a, { file: `${a}.ts`, old: "= 0", new: `= ${value}` }, time);
27 assert.ok(e.ok);
28 const p = project.publish(a, `${a} is ${value}`, time);
29 assert.ok(p.ok && "queued" in p, JSON.stringify(p));
30 return p.queued;
33/** A check that fails when any file says BAD, counting its runs. */
34function checker(result?: (c: Candidate, run: number) => CheckResult): Checker & { runs: Candidate[] } {
35 const runs: Candidate[] = [];
36 return {
37 runs,
38 async check(c) {
39 runs.push(c);
40 if (result) return result(c, runs.length);
41 return Object.values(c.files).some((t) => t.includes("BAD"))
42 ? { kind: "fail", output: "not ok 1 - BAD" }
43 : { kind: "pass" };
44 },
45 };
48test("an empty queue is idle and runs no check", async () => {
49 const c = checker();
50 assert.deepEqual(await queueRound(setup(), c), { kind: "idle" });
51 assert.equal(c.runs.length, 0);
52});
54test("a passing batch lands whole, each push its own version, in one check", async () => {
55 const project = setup();
56 for (const a of AGENTS.slice(0, 3)) queue(project, a, "1");
57 const c = checker();
58 const r = await queueRound(project, c);
59 assert.deepEqual(r, {
60 kind: "landed",
61 versions: [
62 { id: 1, version: 1 },
63 { id: 2, version: 2 },
64 { id: 3, version: 3 },
65 ],
66 checks: 1,
67 });
68 assert.equal(project.treeAt(3), c.runs[0]!.tree);
69 assert.deepEqual(project.queueChecking(0), []);
70});
72test("a batch is everything waiting, with no cap (Christopher, Oct 14): ten land on one check", async () => {
73 const project = setup();
74 for (const a of AGENTS) queue(project, a, "1");
75 const c = checker();
76 const r = await queueRound(project, c);
77 assert.equal(r.kind === "landed" && r.versions.length, AGENTS.length);
78 assert.deepEqual(
79 c.runs.map((x) => x.ids.length),
80 [AGENTS.length],
81 );
82 assert.deepEqual(project.queue().items, []);
83});
85test("a failing batch past the old cap of 8 still halves to the push that fails, and the rest waits", async () => {
86 const project = setup();
87 for (const [i, a] of AGENTS.entries()) queue(project, a, i === 8 ? '"BAD"' : "1");
88 const c = checker();
89 const r = await queueRound(project, c);
90 assert.equal(c.runs[0]!.ids.length, AGENTS.length, "the first check is the whole queue");
91 assert.ok(r.kind === "pulled");
92 assert.deepEqual(r.pulled, [9]);
93 assert.equal(r.versions.length, 8, "the eight before it land");
94 assert.deepEqual(
95 project.queue().items.map((q) => q.id),
96 [10],
97 );
98});
100test("a failing batch is halved to the first push that fails; the prefix before it lands, the rest waits", async () => {
101 const project = setup();
102 for (const [i, a] of AGENTS.slice(0, 8).entries()) queue(project, a, i === 5 ? '"BAD"' : "1");
103 const c = checker();
104 const r = await queueRound(project, c);
105 // 8 fails; 4 passes; 6 fails; 5 passes; 6 fails again: 5 checks, 1 + log2(8) + 1.
106 assert.deepEqual(
107 c.runs.map((x) => x.ids.length),
108 [8, 4, 6, 5, 6],
109 );
110 assert.equal(r.kind, "pulled");
111 assert.ok(r.kind === "pulled");
112 assert.deepEqual(
113 r.versions.map((v) => v.id),
114 [1, 2, 3, 4, 5],
115 );
116 assert.deepEqual(r.pulled, [6]);
117 assert.equal(r.output, "not ok 1 - BAD");
118 assert.deepEqual(
119 project.queue().items.map((q) => q.id),
120 [7, 8],
121 );
122 assert.ok(project.news("b6").news.some((n) => n.includes("not ok 1 - BAD")));
123 assert.deepEqual(await queueRound(project, c), {
124 kind: "landed",
125 versions: [
126 { id: 7, version: 6 },
127 { id: 8, version: 7 },
128 ],
129 checks: 1,
130 });
131});
133test("a lone failing push is turned back after failing twice", async () => {
134 const project = setup();
135 queue(project, "b1", '"BAD"');
136 const c = checker();
137 const r = await queueRound(project, c);
138 assert.equal(c.runs.length, 2);
139 assert.ok(r.kind === "pulled" && r.pulled[0] === 1 && r.versions.length === 0);
140});
142test("a failure that does not happen again pulls nobody, and the prefix lands", async () => {
143 const project = setup();
144 for (const a of AGENTS.slice(0, 2)) queue(project, a, "1");
145 // Fails once, then passes: flaky.
146 const c = checker((_, run) => (run === 1 ? { kind: "fail", output: "flake" } : { kind: "pass" }));
147 const r = await queueRound(project, c);
148 // 2 fails; 1 passes; 2 passes on the confirming run, so both land.
149 assert.deepEqual(r, {
150 kind: "landed",
151 versions: [
152 { id: 1, version: 1 },
153 { id: 2, version: 2 },
154 ],
155 checks: 3,
156 });
157});
159test("a box failure is retried once; twice in a row pauses the queue and blames nobody", async () => {
160 const project = setup();
161 queue(project, "b1", "1");
162 const once = checker((_, run) => (run === 1 ? { kind: "box", reason: "box lost" } : { kind: "pass" }));
163 assert.equal((await queueRound(project, once)).kind, "landed");
164 queue(project, "b2", "1", 2);
165 const always = checker(() => ({ kind: "box", reason: "no exit code" }));
166 assert.deepEqual(await queueRound(project, always), { kind: "paused", reason: "no exit code", checks: 2 });
167 assert.deepEqual(
168 project.queue().items.map((q) => [q.id, q.checking]),
169 [[2, false]],
170 );
171});
173test("while shared is red, prefixes grow one push at a time; the first that passes lands, nobody is turned back", async () => {
174 const project = setup();
175 queue(project, "b1", "1");
176 queue(project, "b2", "2");
177 queue(project, "b3", "3");
178 // Shared is red until b2's change is in: b1 alone doesn't fix it.
179 const c = checker((cand) =>
180 cand.files["b2.ts"]!.includes("= 2") ? { kind: "pass" } : { kind: "fail", output: "still red" },
181 );
182 assert.deepEqual(await queueRound(project, c, { sharedRed: true }), {
183 kind: "landed",
184 versions: [
185 { id: 1, version: 1 },
186 { id: 2, version: 2 },
187 ],
188 checks: 2,
189 });
190 assert.deepEqual(
191 c.runs.map((x) => x.ids),
192 [[1], [1, 2]],
193 );
194 assert.deepEqual(
195 project.queue().items.map((q) => q.id),
196 [3],
197 );
198});
200test("while shared is red and nothing fixes it, the queue holds everyone", async () => {
201 const project = setup();
202 queue(project, "b1", "1");
203 queue(project, "b2", "2");
204 const c = checker(() => ({ kind: "fail", output: "still red" }));
205 assert.deepEqual(await queueRound(project, c, { sharedRed: true }), { kind: "held", checks: 2, output: "still red" });
206 assert.deepEqual(
207 project.queue().items.map((q) => q.id),
208 [1, 2],
209 "nobody turned back",
210 );
211});