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

Versions 68 to 318

Compare

+630 −0 in 1 place
new file, 630 lines
1+// Issues: the store and its routes, on node:sqlite as a Durable Object's SQLite.
2+
3+import assert from "node:assert/strict";
4+import { DatabaseSync } from "node:sqlite";
5+import { describe, it } from "node:test";
6+import { issuesRoute } from "../../src/issues/routes.ts";
7+import { IssuesStore, type Sql, WRITES_PER_MINUTE } from "../../src/issues/store.ts";
8+
9+function sql(): Sql {
10+ const db = new DatabaseSync(":memory:");
11+ return {
12+ exec: (q, ...b) => {
13+ // Like ctx.storage.sql.exec: the statement runs at once; rows come from toArray.
14+ if (/^\s*CREATE\b/i.test(q)) {
15+ db.exec(q);
16+ return { toArray: () => [] };
17+ }
18+ const rows = db.prepare(q).all(...(b as (string | number | null)[]));
19+ return { toArray: () => rows };
20+ },
21+ };
22+}
24+function store(): { s: IssuesStore; tick: (ms?: number) => void } {
25+ let t = Date.parse("2026-10-07T20:00:00Z");
26+ const db = sql();
27+ IssuesStore.createTables(db);
28+ return { s: new IssuesStore(db, () => t), tick: (ms = 1000) => void (t += ms) };
29+}
31+const builder = { agent: "builder3" };
32+const christopher = { person: "u1" };
34+describe("issues: statuses come from the work", () => {
35+ it("open, in progress, in review, blocked, done and dropped, and a dropped issue can be reopened", () => {
36+ const { s, tick } = store();
37+ const a = s.open(builder, { title: "Sign-in page", description: "Pages for sign-in" }).id;
38+ const b = s.open(builder, { title: "Logo", parent: a }).id;
39+ assert.equal(s.page(a).issue.status, "open");
40+ assert.equal(s.page(a).issue.children, 1);
42+ tick();
43+ s.claim("builder3", a, 4400);
44+ assert.equal(s.page(a).issue.status, "in progress");
45+ assert.deepEqual(s.page(a).issue.agents, ["builder3"]);
47+ tick();
48+ const review = s.ask(builder, { issue: a, of: "security", question: "Is the cookie set right?", review: true });
49+ assert.equal(s.page(a).issue.status, "in review");
50+ assert.deepEqual(s.page(a).issue.waitingOn, ["security"]);
51+ assert.deepEqual(review.news.to, ["security"]);
52+ assert.ok(review.news.text.endsWith(`: "Is the cookie set right?" Answer: abso answer ${review.id} "..."`));
54+ // A question that isn't a review blocks, and outranks the review; it can hold up other issues too.
55+ const q = s.ask(builder, {
56+ issue: a,
57+ of: "person:u1",
58+ question: "Take abso.dev?",
59+ options: ["Yes", "No"],
60+ blocks: [b],
61+ due: "2026-10-09",
62+ });
63+ assert.equal(s.page(a).issue.status, "blocked");
64+ assert.equal(s.page(b).issue.status, "blocked", "an ask holds up the issues it names in blocks");
65+ assert.deepEqual(s.page(a).issue.waitingOn, ["security", "person:u1"]);
66+ assert.ok(q.news.text.endsWith('"Take abso.dev?"'), "a person answers elsewhere, so no command");
68+ tick();
69+ const answered = s.answer(christopher, q.id, { option: "Yes", note: "Renew it for two years." });
70+ assert.equal(answered.ask.answer?.words, "Yes\n\nRenew it for two years.", "kept in the person's own words");
71+ assert.equal(s.page(b).issue.status, "open");
72+ assert.equal(s.page(a).issue.status, "in review");
73+ s.answer({ agent: "security" }, review.id, { words: "Looks right." });
74+ assert.equal(s.page(a).issue.status, "in progress");
76+ tick();
77+ const done = s.done("builder3", a, 13);
78+ assert.match(done.news!.text, /^builder3 finished issue 1 \("Sign-in page"\) in version 13$/);
79+ const page = s.page(a);
80+ assert.equal(page.issue.status, "done");
81+ assert.deepEqual(page.issue.closed, { how: "done", by: "builder3", version: 13, at: page.issue.closed!.at });
82+ assert.deepEqual(page.issue.versions, [13]);
83+ assert.deepEqual(page.claims, []);
85+ s.drop(builder, b);
86+ assert.equal(s.page(b).issue.status, "dropped");
87+ assert.throws(() => s.drop(builder, b), /dropped already/);
88+ assert.throws(() => s.markDone(builder, b, null), /reopen it/);
89+ const reopened = s.reopen(builder, b);
90+ assert.match(reopened.news.text, /reopened issue/);
91+ assert.equal(s.page(b).issue.status, "open");
92+ assert.throws(() => s.reopen(builder, b), /is open/);
93+ const marked = s.markDone(builder, b, 381);
94+ assert.match(marked.news.text, /done in version 381/);
95+ assert.equal(s.page(b).issue.status, "done");
96+ assert.deepEqual(s.page(b).issue.versions, [381]);
97+ assert.throws(() => s.reopen(builder, b), /stays done/);
98+ assert.throws(() => s.markDone(builder, b, null), /done already/);
99+ assert.deepEqual(
100+ s.list({ open: true }).map((i) => i.id),
101+ [],
102+ );
103+ });
105+ it("a start note that ends without --done takes the claim back and leaves the issue open", () => {
106+ const { s } = store();
107+ const id = s.open(builder, { title: "x" }).id;
108+ s.claim("builder3", id, 10);
109+ s.unclaim("builder3", id);
110+ assert.equal(s.page(id).issue.status, "open");
111+ // Hooks for an issue that doesn't exist are ignored: the start note stands either way.
112+ s.claim("builder3", 99, 10);
113+ s.unclaim("builder3", 99);
114+ assert.deepEqual(s.done("builder3", 99, 3), {});
115+ });
117+ it("lists by status and agent, most recently updated first", () => {
118+ const { s, tick } = store();
119+ const one = s.open(builder, { title: "one" }).id;
120+ tick();
121+ const two = s.open(builder, { title: "two" }).id;
122+ tick();
123+ s.comment({ agent: "engine" }, one, { text: "on it soon" });
124+ assert.deepEqual(
125+ s.list().map((i) => i.id),
126+ [one, two],
127+ );
128+ s.claim("engine", two, 5);
129+ assert.deepEqual(
130+ s.list({ agent: "engine" }).map((i) => i.id),
131+ [two],
132+ );
133+ assert.deepEqual(
134+ s.list({ status: "open" }).map((i) => i.id),
135+ [one],
136+ );
137+ });
138+});
140+describe("issues: the asker withdraws an ask", () => {
141+ it("closes like an answer: off the waiting list, no longer blocking, kept with the note, and the one asked hears it", () => {
142+ const { s } = store();
143+ const id = s.open(builder, { title: "How judges see abso" }).id;
144+ const ask = s.ask(builder, { of: "person:u1", question: "A, B or C?", issue: id, options: ["A", "B", "C"] });
145+ assert.equal(s.page(id).issue.status, "blocked");
146+ const r = s.withdraw(builder, ask.id, { note: "Overtaken by tonight's rulings" });
147+ assert.equal(r.ask.outcome, "withdrawn");
148+ assert.deepEqual(r.ask.answer && { by: r.ask.answer.by, words: r.ask.answer.words }, {
149+ by: "builder3",
150+ words: "Overtaken by tonight's rulings",
151+ });
152+ assert.deepEqual(r.news.to, ["person:u1"]);
153+ assert.match(r.news.text, /^builder3 withdrew their question of person:u1 on issue \d+: "Overtaken/);
154+ assert.deepEqual(s.waiting("person:u1"), []);
155+ assert.equal(s.page(id).issue.status, "open");
156+ assert.equal(s.page(id).asks[0]!.outcome, "withdrawn");
157+ assert.equal(s.answered("person:u1")[0]!.outcome, "withdrawn");
158+ });
160+ it("only the asker withdraws, only while unanswered, and once; then it can't be answered", () => {
161+ const { s } = store();
162+ const ask = s.ask(builder, { of: "person:u1", question: "Pick one" });
163+ assert.throws(() => s.withdraw(christopher, ask.id, {}), /asked by builder3; only they can withdraw it/);
164+ assert.throws(() => s.withdraw(builder, 99, {}), /there's no ask 99/);
165+ const r = s.withdraw(builder, ask.id, {});
166+ assert.equal(r.ask.answer!.words, "");
167+ assert.equal(r.news.text, "builder3 withdrew their question of person:u1", "no note, so nothing after it");
168+ assert.throws(() => s.withdraw(builder, ask.id, {}), /withdrawn already/);
169+ assert.throws(
170+ () => s.answer(christopher, ask.id, { words: "A" }),
171+ (e: { status?: number; message: string }) => e.status === 409 && /withdrawn by builder3/.test(e.message),
172+ );
173+ const answered = s.ask(builder, { of: "person:u1", question: "Another" });
174+ s.answer(christopher, answered.id, { words: "Yes" });
175+ assert.throws(() => s.withdraw(builder, answered.id, {}), /answered already, so there's nothing to withdraw/);
176+ assert.equal(s.answered("person:u1").find((a) => a.id === answered.id)!.outcome, undefined);
177+ });
178+});
180+describe("issues: the one asked acknowledges an ask", () => {
181+ it("stays open and blocking, shows the ack and its note, and the asker hears it; an answer closes it", () => {
182+ const { s } = store();
183+ const id = s.open(builder, { title: "Which deploy first" }).id;
184+ const ask = s.ask(builder, { of: "person:u1", question: "A or B?", issue: id });
185+ const r = s.ack(christopher, ask.id, { note: "after the review" });
186+ assert.equal(r.ask.ack!.note, "after the review");
187+ assert.equal(r.ask.answer, null);
188+ assert.deepEqual(r.news.to, ["builder3"]);
189+ assert.equal(
190+ r.news.text,
191+ `person:u1 has your question (ask ${ask.id}) on issue ${id} and will answer: "after the review"`,
192+ );
193+ assert.equal(s.page(id).issue.status, "blocked");
194+ assert.equal(s.page(id).asks[0]!.ack!.note, "after the review");
195+ assert.deepEqual(
196+ s.waiting("person:u1").map((a) => a.id),
197+ [ask.id],
198+ );
199+ // Again, with no note: the note and time update.
200+ const again = s.ack(christopher, ask.id, {});
201+ assert.equal(again.ask.ack!.note, "");
202+ assert.equal(again.news.text, `person:u1 has your question (ask ${ask.id}) on issue ${id} and will answer.`);
203+ s.answer(christopher, ask.id, { words: "A" });
204+ assert.equal(s.page(id).issue.status, "open");
205+ assert.deepEqual(s.waiting("person:u1"), []);
206+ });
208+ it("only the one asked acknowledges, and only while it's open", () => {
209+ const { s } = store();
210+ const ask = s.ask(builder, { of: "person:u1", question: "Pick one" });
211+ assert.throws(
212+ () => s.ack(builder, ask.id, {}),
213+ (e: { status?: number; message: string }) => e.status === 403 && /is for person:u1, not builder3/.test(e.message),
214+ );
215+ assert.throws(
216+ () => s.ack(christopher, 99, {}),
217+ (e: { status?: number }) => e.status === 404,
218+ );
219+ s.answer(christopher, ask.id, { words: "A" });
220+ assert.throws(
221+ () => s.ack(christopher, ask.id, {}),
222+ (e: { status?: number; message: string }) => e.status === 409 && /answered already/.test(e.message),
223+ );
224+ const gone = s.ask(builder, { of: "person:u1", question: "Another" });
225+ s.withdraw(builder, gone.id, {});
226+ assert.throws(
227+ () => s.ack(christopher, gone.id, {}),
228+ (e: { status?: number; message: string }) => e.status === 409 && /withdrawn by builder3/.test(e.message),
229+ );
230+ });
231+});
233+describe("issues: asks and answers", () => {
234+ it("an ask on no issue, a task answered done, and waiting sorted by due date", () => {
235+ const { s } = store();
236+ const id = s.open(builder, { title: "Sign-in" }).id;
237+ const later = s.ask(builder, {
238+ of: "person:u1",
239+ question: "Does the avcs command become abso?",
240+ due: "2026-10-20",
241+ recommendation: { text: "Yes, with avcs kept as an alias" },
242+ });
243+ const sooner = s.ask(builder, {
244+ of: "person:u1",
245+ kind: "task",
246+ question: "Upload the sign-in logo",
247+ due: "2026-10-08",
248+ blocks: [id],
249+ });
250+ const none = s.ask(builder, { of: "person:u1", question: "Anything else?" });
251+ const waiting = s.waiting("person:u1");
252+ assert.deepEqual(
253+ waiting.map((a) => a.id),
254+ [sooner.id, later.id, none.id],
255+ );
256+ assert.equal(waiting[1]!.issue, null);
257+ assert.equal(waiting[1]!.title, null);
258+ assert.deepEqual(waiting[1]!.recommendation, { text: "Yes, with avcs kept as an alias", by: "builder3" });
259+ assert.equal(s.page(id).issue.status, "blocked");
260+ s.answer(christopher, sooner.id, { done: true });
261+ assert.equal(s.answered("person:u1")[0]!.answer!.words, "done");
262+ assert.equal(s.page(id).issue.status, "open");
263+ assert.deepEqual(
264+ s.waiting("person:u1").map((a) => a.id),
265+ [later.id, none.id],
266+ );
267+ });
269+ it("only the one asked answers, once, from its options", () => {
270+ const { s } = store();
271+ const ask = s.ask(builder, { of: "person:u1", question: "Pick one", options: ["A", "B"] });
272+ assert.throws(() => s.answer({ person: "u2" }, ask.id, { words: "A" }), /is for person:u1, not person:u2/);
273+ assert.throws(() => s.answer(christopher, ask.id, { option: "C" }), /options are: "A", "B"/);
274+ // The page sends the option's text as it showed it: an index that names another is refused.
275+ assert.throws(
276+ () => s.answer(christopher, ask.id, { option: 1, expect: "A" }),
277+ (e: { status?: number; message: string }) =>
278+ e.status === 409 && /option 2 is "B", not the one you picked/.test(e.message),
279+ );
280+ s.answer(christopher, ask.id, { option: 1, expect: "B" });
281+ assert.throws(() => s.answer(christopher, ask.id, { words: "A" }), /answered already/);
282+ assert.equal(s.answered("person:u1")[0]!.answer!.words, "B");
283+ });
285+ it("checks its input", () => {
286+ const { s } = store();
287+ assert.throws(() => s.open(builder, { title: "" }), /the title is missing/);
288+ assert.throws(() => s.open(builder, { title: "x".repeat(201) }), /201 characters; the most is 200/);
289+ assert.throws(() => s.open(builder, { title: "x", parent: 7 }), /there's no issue 7/);
290+ assert.throws(
291+ () => s.open(builder, { title: "x", lines: { file: "a.ts", from: 3, to: 1, version: 2 } }),
292+ /lines are/,
293+ );
294+ assert.throws(() => s.ask(builder, { of: "x", question: "q", review: true }), /a review ask is on an issue/);
295+ assert.throws(() => s.ask(builder, { of: "x", question: "q", due: "soon" }), /due is a date/);
296+ assert.throws(() => s.ask(builder, { of: "x", question: "q", kind: "chore" }), /kind is "question", or "task"/);
297+ });
298+});
300+describe("issues: routes", () => {
301+ const call = (s: IssuesStore, method: string, path: string, body?: unknown, headers: Record<string, string> = {}) =>
302+ issuesRoute(
303+ s,
304+ new Request(`https://issues.internal${path}`, {
305+ method,
306+ headers,
307+ ...(body !== undefined ? { body: JSON.stringify(body) } : {}),
308+ }),
309+ ).then(async (r) => ({ status: r.status, json: (await r.json()) as Record<string, any> }));
311+ it("agents write under /a/:agent/, a write naming nobody is refused, and everyone reads", async () => {
312+ const { s } = store();
313+ const opened = await call(s, "POST", "/p/web/a/builder3/issue", { title: "Sign-in", description: "d" });
314+ assert.equal(opened.status, 200);
315+ assert.equal(opened.json.id, 1);
316+ assert.equal((await call(s, "POST", "/p/web/a/fe/issue/1/comment", { text: "nice" })).status, 200);
317+ assert.equal((await call(s, "POST", "/p/web/issue/1/comment", { text: "who am I" })).status, 403);
318+ assert.equal(
319+ (await call(s, "POST", "/p/web/issue/1/comment", { text: "a person?" }, { "X-Avcs-User": "u1" })).status,
320+ 403,
321+ "no header makes a person here",
322+ );
323+ const asked = await call(s, "POST", "/p/web/a/builder3/ask", { issue: 1, of: "fe", question: "OK?" });
324+ assert.equal(asked.json.news.to[0], "fe");
325+ assert.equal((await call(s, "POST", `/p/web/a/fe/answer/${asked.json.id}`, { words: "OK" })).status, 200);
327+ const list = await call(s, "GET", "/p/web/issues?open=1");
328+ assert.deepEqual(
329+ list.json.issues.map((i: { id: number; status: string }) => [i.id, i.status]),
330+ [[1, "open"]],
331+ );
332+ const page = await call(s, "GET", "/p/web/issue/1");
333+ assert.deepEqual(
334+ page.json.comments.map((c: { by: string }) => c.by),
335+ ["fe"],
336+ );
337+ assert.equal(page.json.asks[0].answer.words, "OK");
338+ assert.equal((await call(s, "GET", "/p/web/issue/9")).status, 404);
339+ assert.equal((await call(s, "GET", "/p/web/answered")).status, 400);
340+ assert.equal((await call(s, "POST", "/p/web/a/builder3/issue", "not an object")).status, 400);
341+ });
342+});
344+describe("issues: edits, watchers, Blocked by and drafts", () => {
345+ it("an edit tells the watchers by default, adds people, or tells nobody", () => {
346+ const { s, tick } = store();
347+ const a = s.open(christopher, { title: "Accounts" }).id;
348+ const b = s.open(christopher, { title: "Sign-in", agent: "fe", notify: ["design"] });
349+ assert.deepEqual(b.news, {
350+ issue: null,
351+ text: 'person:u1 opened issue 2: "Sign-in" (Agent fe)',
352+ to: ["fe", "design"],
353+ });
354+ s.comment(builder, b.id, { text: "on it soon" });
355+ s.claim("engine", b.id, 40);
356+ tick();
357+ // Issue 1 opened before issue 2, then put under it.
358+ const moved = s.edit(christopher, b.id, { parent: a, title: "Sign-in flow" });
359+ assert.deepEqual(moved.notified, ["builder3", "design", "engine", "fe"]);
360+ assert.equal(moved.news!.text, 'person:u1 edited issue 2 ("Sign-in flow"): title was "Sign-in"; parent is issue 1');
361+ const page = s.page(b.id);
362+ assert.equal(page.issue.parent, a);
363+ assert.deepEqual(page.issue.watchers, ["builder3", "design", "engine", "fe", "person:u1"]);
364+ assert.deepEqual(page.edits[0]!.changes, {
365+ title: { from: "Sign-in", to: "Sign-in flow" },
366+ parent: { from: null, to: 1 },
367+ });
368+ const quiet = s.edit(builder, b.id, { description: "typo", notify: false });
369+ assert.deepEqual(quiet, { edit: 2, notified: [] });
370+ const more = s.edit(builder, b.id, { agent: "web", also: ["person:u2"] });
371+ assert.ok(
372+ more.notified.includes("person:u2") && more.notified.includes("web") && !more.notified.includes("builder3"),
373+ );
374+ assert.equal(s.page(b.id).issue.agent, "web");
375+ assert.throws(() => s.edit(builder, b.id, { agent: "web" }), /that changes nothing on issue 2/);
376+ assert.throws(() => s.edit(builder, a, { parent: b.id }), /issue 2 is issue 1 or under it/);
377+ assert.throws(() => s.edit(builder, a, { notify: "no", title: "A" }), /notify is true/);
378+ });
380+ it("Blocked by holds an issue Blocked until each is Done, and refuses a loop", () => {
381+ const { s } = store();
382+ const a = s.open(builder, { title: "Schema" }).id;
383+ const b = s.open(builder, { title: "Pages", blockedBy: [a] }).id;
384+ assert.equal(s.page(b).issue.status, "blocked");
385+ assert.deepEqual(s.page(b).issue.blockedBy, [a]);
386+ assert.throws(() => s.edit(builder, a, { blockedBy: [b] }), /issue 2 already waits on issue 1/);
387+ assert.throws(() => s.edit(builder, a, { blockedBy: [a] }), /can't be blocked by itself/);
388+ s.done("engine", a, 12);
389+ assert.equal(s.page(b).issue.status, "open");
390+ const c = s.open(builder, { title: "Docs" }).id;
391+ s.edit(builder, c, { blockedBy: [b] });
392+ assert.equal(s.page(c).issue.status, "blocked");
393+ s.edit(builder, c, { blockedBy: [] });
394+ assert.equal(s.page(c).issue.status, "open");
395+ });
397+ it("the first start note sets the Agent when none was set, and the claimer watches", () => {
398+ const { s } = store();
399+ const id = s.open(builder, { title: "x" }).id;
400+ s.claim("engine", id, 3);
401+ s.claim("fe", id, 4);
402+ assert.equal(s.page(id).issue.agent, "engine");
403+ assert.deepEqual(
404+ s.list({ agent: "engine" }).map((i) => i.id),
405+ [id],
406+ );
407+ assert.ok(s.page(id).issue.watchers.includes("fe"));
408+ });
410+ it("drafts are their writer's alone, have no number, make no news, and open as issues", () => {
411+ const { s } = store();
412+ const d = s.saveDraft(christopher, { title: "Half a thought" }).id;
413+ s.saveDraft(christopher, { id: d, title: "A whole thought", agent: "fe" });
414+ assert.deepEqual(
415+ s.drafts(christopher).map((x) => x.body),
416+ [{ title: "A whole thought", agent: "fe" }],
417+ );
418+ assert.deepEqual(s.drafts({ person: "u2" }), []);
419+ assert.throws(() => s.deleteDraft({ person: "u2" }, d), /you have no draft/);
420+ assert.deepEqual(s.list(), []);
421+ assert.deepEqual(s.drafts(christopher)[0]!.id, d);
422+ s.saveDraft(christopher, {});
423+ const opened = s.openDraft(christopher, d, { description: "added when opening" });
424+ assert.equal(opened.id, 1);
425+ assert.deepEqual(opened.news!.to, ["fe"]);
426+ assert.equal(s.page(1).issue.description, "added when opening");
427+ assert.equal(s.drafts(christopher).length, 1);
428+ assert.throws(() => s.openDraft(christopher, s.drafts(christopher)[0]!.id), /the title is missing/);
429+ });
431+ it("refuses words a reader can't see, and titles over more than one line", () => {
432+ const { s } = store();
433+ assert.throws(
434+ () => s.open(builder, { title: "fine\u{E0041}" }),
435+ /a tag character \(U\+E0000-E007F\) at character 5/,
436+ );
437+ assert.throws(() => s.open(builder, { title: "one\ntwo" }), /the title is one line/);
438+ assert.throws(() => s.open(builder, { title: "x", description: "a\u202Eb" }), /bidirectional/);
439+ const id = s.open(builder, { title: "x", description: "two\nlines\tand a tab" }).id;
440+ assert.throws(() => s.comment(builder, id, { text: "hi\u200B" }), /zero-width/);
441+ assert.throws(() => s.edit(builder, id, { title: "a\nb" }), /one line/);
442+ assert.throws(() => s.open(builder, { title: "x", notify: ["fe\nengine"] }), /one line/);
443+ });
445+ it("routes: edit, and drafts read and written by their writer", async () => {
446+ const { s } = store();
447+ const call = (method: string, path: string, body?: unknown, headers: Record<string, string> = {}) =>
448+ issuesRoute(
449+ s,
450+ new Request(`https://issues.internal${path}`, {
451+ method,
452+ headers,
453+ ...(body !== undefined ? { body: JSON.stringify(body) } : {}),
454+ }),
455+ ).then(async (r) => ({ status: r.status, json: (await r.json()) as Record<string, any> }));
456+ const title400 = await call("POST", "/p/web/a/fe/issue", { title: "x\u{E0001}" });
457+ assert.equal(title400.status, 400);
458+ assert.match(title400.json.error, /tag character/);
459+ assert.equal((await call("POST", "/p/web/a/fe/issue", { title: "a\nb" })).status, 400);
460+ await call("POST", "/p/web/a/fe/issue", { title: "Sign-in" });
461+ const edited = await call("POST", "/p/web/a/lead/issue/1/edit", { title: "Sign-in flow" });
462+ assert.equal(edited.status, 200);
463+ assert.deepEqual(edited.json.notified, ["fe"]);
464+ const saved = await call("POST", "/p/web/a/lead/draft", { title: "Later" });
465+ assert.equal((await call("GET", "/p/web/a/lead/drafts", undefined)).json.drafts[0].body.title, "Later");
466+ assert.deepEqual((await call("GET", "/p/web/a/fe/drafts")).json.drafts, []);
467+ // A read naming nobody sees no one's drafts.
468+ assert.equal((await call("GET", "/p/web/drafts")).status, 403);
469+ assert.equal((await call("POST", `/p/web/a/fe/draft/${saved.json.id}/delete`)).status, 404);
470+ assert.equal((await call("POST", `/p/web/a/lead/draft/${saved.json.id}/open`, {})).json.id, 2);
471+ assert.deepEqual((await call("GET", "/p/web/a/lead/drafts", undefined)).json.drafts, []);
472+ });
473+});
475+describe("issues: each writer's limit", () => {
476+ it("one write past the per-minute limit gets 429 with Retry-After; another writer isn't affected", async () => {
477+ const { s, tick } = store();
478+ const call = (path: string, body: unknown, agent: string) =>
479+ issuesRoute(
480+ s,
481+ new Request(`https://issues.internal${path.replace("/p/web/", `/p/web/a/${agent}/`)}`, {
482+ method: "POST",
483+ body: JSON.stringify(body),
484+ }),
485+ );
486+ assert.equal((await call("/p/web/issue", { title: "One" }, "u1")).status, 200);
487+ for (let i = 0; i < WRITES_PER_MINUTE - 1; i++)
488+ assert.equal((await call("/p/web/issue/1/comment", { text: `c${i}` }, "u1")).status, 200);
489+ // A refused write doesn't count, and drafts make no news, so they don't either.
490+ assert.equal((await call("/p/web/draft", { title: "later" }, "u1")).status, 200);
491+ const over = await call("/p/web/issue/1/comment", { text: "over limit" }, "u1");
492+ assert.equal(over.status, 429);
493+ assert.match(
494+ ((await over.json()) as { error: string }).error,
495+ new RegExp(`at most ${WRITES_PER_MINUTE} issue writes a minute`),
496+ );
497+ assert.equal(over.headers.get("Retry-After"), "60");
498+ assert.equal((await call("/p/web/issue/1/comment", { text: "mine" }, "u2")).status, 200);
499+ tick(60_000);
500+ assert.equal((await call("/p/web/issue/1/comment", { text: "a minute on" }, "u1")).status, 200);
501+ });
502+});
504+describe("issues: labels", () => {
505+ it("set on open, changed by edit, filtered by, and listed with counts", () => {
506+ const { s } = store();
507+ const a = s.open(builder, { title: "Sync is slow", labels: ["friction", "client", "friction"] }).id;
508+ const b = s.open(builder, { title: "Blame past a reformat", labels: ["friction", "engine"] }).id;
509+ s.open(builder, { title: "Logo" });
510+ assert.deepEqual(s.page(a).issue.labels, ["client", "friction"]);
511+ assert.deepEqual(
512+ s.list({ labels: ["friction"] }).map((i) => i.id),
513+ [b, a],
514+ );
515+ assert.deepEqual(
516+ s.list({ labels: ["friction", "client"] }).map((i) => i.id),
517+ [a],
518+ );
519+ // A label-only edit tells nobody unless asked; it's in the activity.
520+ const quiet = s.edit(christopher, a, { addLabels: ["good-first-issue"], removeLabels: ["client"] });
521+ assert.deepEqual(quiet.notified, []);
522+ assert.deepEqual(s.page(a).issue.labels, ["friction", "good-first-issue"]);
523+ assert.deepEqual(s.page(a).edits.at(-1)!.changes.labels, {
524+ from: ["client", "friction"],
525+ to: ["friction", "good-first-issue"],
526+ });
527+ const told = s.edit(christopher, a, { labels: ["friction"], notify: true });
528+ assert.match(told.news!.text, /labels friction$/);
529+ s.drop(builder, b);
530+ assert.deepEqual(s.labelsInUse(), [
531+ { label: "engine", open: 0, total: 1 },
532+ { label: "friction", open: 1, total: 2 },
533+ ]);
534+ assert.throws(() => s.edit(builder, a, { addLabels: ["friction"] }), /changes nothing/);
535+ assert.throws(() => s.open(builder, { title: "x", labels: ["two words"] }), /isn't a label/);
536+ // Sent straight to the Worker, upper case and a zero-width are refused, not changed.
537+ assert.throws(
538+ () => s.open(builder, { title: "x", labels: ["Friction"] }),
539+ (e: { status?: number }) => e.status === 400,
540+ );
541+ assert.throws(
542+ () => s.open(builder, { title: "x", labels: ["fric​tion"] }),
543+ (e: { status?: number }) => e.status === 400,
544+ );
545+ assert.throws(() => s.open(builder, { title: "x", labels: ["x".repeat(41)] }), /isn't a label/);
546+ assert.throws(() => s.edit(builder, a, { labels: [], addLabels: ["x"] }), /one or the other/);
547+ assert.throws(() => s.list({ labels: ["Bad Label"] }), /isn't a label/);
548+ });
550+ it("routes: ?label= filters, GET labels lists, and drafts keep labels", async () => {
551+ const { s } = store();
552+ const call = (method: string, path: string, body?: unknown, headers: Record<string, string> = {}) =>
553+ issuesRoute(
554+ s,
555+ new Request(`https://issues.internal${path}`, {
556+ method,
557+ headers,
558+ ...(body !== undefined ? { body: JSON.stringify(body) } : {}),
559+ }),
560+ ).then(async (r) => ({ status: r.status, json: (await r.json()) as Record<string, any> }));
561+ await call("POST", "/p/web/a/fe/issue", { title: "One", labels: ["friction"] });
562+ await call("POST", "/p/web/a/fe/issue", { title: "Two", labels: ["friction", "client"] });
563+ const both = await call("GET", "/p/web/issues?label=friction,client");
564+ assert.deepEqual(
565+ both.json.issues.map((i: { title: string }) => i.title),
566+ ["Two"],
567+ );
568+ assert.equal((await call("GET", "/p/web/issues?label=friction&label=client")).json.issues.length, 1);
569+ assert.equal((await call("GET", "/p/web/issues?label=Not%20one")).status, 400);
570+ assert.deepEqual((await call("GET", "/p/web/labels")).json.labels, [
571+ { label: "client", open: 1, total: 1 },
572+ { label: "friction", open: 2, total: 2 },
573+ ]);
574+ const edited = await call("POST", "/p/web/a/fe/issue/1/edit", { addLabels: ["client"] });
575+ assert.equal(edited.status, 200);
576+ const d = await call("POST", "/p/web/a/fe/draft", { title: "Later", labels: ["friction"] });
577+ const opened = await call("POST", `/p/web/a/fe/draft/${d.json.id}/open`, {});
578+ assert.deepEqual((await call("GET", `/p/web/issue/${opened.json.id}`)).json.issue.labels, ["friction"]);
579+ });
580+});
582+describe("issues: a project's labels are capped", () => {
583+ it("a new label past 200 distinct ones is refused; one in use still goes on", () => {
584+ const { s } = store();
585+ const ids: number[] = [];
586+ for (let i = 0; i < 10; i++)
587+ ids.push(s.open(builder, { title: `t${i}`, labels: Array.from({ length: 20 }, (_, j) => `l${i * 20 + j}`) }).id);
588+ assert.equal(s.labelsInUse().length, 200);
589+ assert.throws(
590+ () => s.open(builder, { title: "one more", labels: ["l-new"] }),
591+ /this project has 200 labels, and 200 is the most/,
592+ );
593+ assert.throws(
594+ () => s.edit(builder, s.open(builder, { title: "room" }).id, { addLabels: ["l-new"] }),
595+ /200 is the most/,
596+ );
597+ assert.equal(s.edit(builder, ids[1]!, { addLabels: ["l0"], removeLabels: ["l20"] }).notified.length, 0);
598+ });
599+});
601+describe("issues: when an ask was first listed to its reader", () => {
602+ const get = (s: IssuesStore, path: string, headers: Record<string, string> = {}) =>
603+ issuesRoute(s, new Request(`https://issues.internal${path}`, { headers }));
605+ it("an agent's own waiting marks what it lists as seen, and says null for what it saw first just now", async () => {
606+ const { s, tick } = store();
607+ const id = s.ask(builder, { of: "security", question: "Is the cookie set right?" }).id;
608+ const read = async (path: string) =>
609+ ((await (await get(s, path)).json()) as { asks: { id: number; seen: number | null }[] }).asks;
610+ assert.deepEqual(await read("/p/abso/waiting?of=security"), [{ ...s.waiting("security")[0]!, seen: null }]);
611+ assert.equal(s.waiting("security")[0]!.seen, null, "a read of someone else's list marks nothing");
612+ tick();
613+ const first = await read("/p/abso/a/security/waiting");
614+ assert.equal(first[0]!.seen, null);
615+ const at = s.waiting("security")[0]!.seen;
616+ assert.equal(at, Date.parse("2026-10-07T20:00:01Z"));
617+ tick();
618+ assert.equal((await read("/p/abso/a/security/waiting"))[0]!.seen, at, "the first time stays");
619+ assert.equal(first[0]!.id, id);
620+ });
622+ it("another agent's read of the list marks nothing", async () => {
623+ const { s } = store();
624+ s.ask(builder, { of: "security", question: "Take abso.dev?" });
625+ await get(s, "/p/abso/a/fe/waiting");
626+ assert.equal(s.waiting("security")[0]!.seen, null);
627+ await get(s, "/p/abso/a/security/waiting");
628+ assert.notEqual(s.waiting("security")[0]!.seen, null);
629+ });
630+});
MCP
compare on this site's /mcp
CLI
abso diff 68 318 server/test/issues/issues.test.ts --json
JSON
/christopher/abso-core/compare/68..318?file=server%2Ftest%2Fissues%2Fissues.test.ts&format=json