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/issues.test.ts?format=json
76 linesFirst import 97% · rename 3%Last change rename in version 100, 2 versions changed it
1// Issues' hooks in the engine (#54): a start note can name an issue, the
2// change record keeps it, changes(issue) lists the work on it, and starting()
3// says what the Issues Worker should hear: a claim when a note names an
4// issue, and an end (done after publish --done, with the version that
5// finished it) when that note ends.
6
7import assert from "node:assert/strict";
8import { test } from "node:test";
9import { type EditBody, MemoryStore, Project } from "../project.ts";
11function edit(project: Project, agent: string, body: EditBody, time: number): void {
12 assert.ok(project.edit(agent, body, time).ok);
15function setup() {
16 const store = new MemoryStore();
17 const project = new Project(store, { now: () => 100 });
18 project.init({ "a.ts": "export const a = 1;\n" }, 0);
19 for (const a of ["builder", "other"]) project.sync(a);
20 return { project, store };
23test("a note naming an issue claims it; push --done ends it as done, with the version", () => {
24 const { project, store } = setup();
25 const s = project.starting("builder", "Bigger a", ["a.ts"], 1, { issue: 12 });
26 const at = store.entries.findIndex((e) => e.type === "starting");
27 assert.equal(s.starting?.issue, 12);
28 assert.deepEqual(s.hooks, { claim: { issue: 12, agent: "builder", change: at } });
29 const e = project.edit("builder", { file: "a.ts", old: "1", new: "2" }, 2);
30 assert.ok(e.ok);
31 project.publish("builder", "a is 2", 3);
32 const end = project.starting("builder", null, undefined, 4, { done: true });
33 assert.deepEqual(end.hooks, { unclaim: { issue: 12, agent: "builder", change: at, done: true, version: 1 } });
34 assert.equal(project.change(at).issue, 12);
35 assert.deepEqual(
36 project.changes(0, 50, undefined, 12).changes.map((c) => c.id),
37 [at],
38 );
39 assert.equal(project.changes(0, 50, undefined, 13).changes.length, 0);
40 // Replay keeps it.
41 assert.equal(Project.load(store.entries, new MemoryStore()).change(at).issue, 12);
42});
44test("a new note or a plain take-back ends the claim without done; notes without an issue say nothing", () => {
45 const { project } = setup();
46 assert.equal(project.starting("other", "no issue", undefined, 1).hooks, undefined);
47 project.starting("builder", "First", undefined, 1, { issue: 3 });
48 const next = project.starting("builder", "Second", undefined, 2, { issue: 4 });
49 assert.equal(next.hooks?.unclaim?.issue, 3);
50 assert.equal(next.hooks?.unclaim?.done, false);
51 assert.equal(next.hooks?.unclaim?.version, undefined, "nothing pushed");
52 assert.equal(next.hooks?.claim?.issue, 4);
53 const back = project.starting("builder", null, undefined, 3);
54 assert.deepEqual([back.hooks?.unclaim?.issue, back.hooks?.unclaim?.done, back.hooks?.claim], [4, false, undefined]);
55 assert.equal(project.starting("builder", null, undefined, 4, { done: true }).hooks, undefined, "no note left to end");
56});
58test("a note made inside a named draft gives the draft's change its issue", () => {
59 const { project } = setup();
60 project.switchTo("builder", "feat", 1);
61 edit(project, "builder", { file: "a.ts", old: "1", new: "2" }, 2);
62 project.publish("builder", "draft version", 3);
63 project.starting("builder", "In a draft", undefined, 4, { issue: 5 });
64 edit(project, "builder", { file: "a.ts", old: "2", new: "3" }, 5);
65 project.publish("builder", "again", 6);
66 assert.equal(project.changes(0, 50, undefined, 5).changes.length, 1);
67});
69test("issue and done are checked", () => {
70 const { project } = setup();
71 assert.throws(() => project.starting("builder", "x", undefined, 1, { issue: 0 }), /issue is an issue number/);
72 assert.throws(() => project.starting("builder", "x", undefined, 1, { issue: "12" }), /issue is an issue number/);
73 assert.throws(() => project.starting("builder", null, undefined, 1, { issue: 12 }), /goes with a start note/);
74 assert.throws(() => project.starting("builder", "x", undefined, 1, { done: true }), /done goes with a take-back/);
75 assert.throws(() => project.starting("builder", null, undefined, 1, { done: "yes" }), /done is true or left out/);
76});