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/client/test/issues.test.ts?version=143&format=json
508 linespinch 61% · First import 26% · codex-prose-authorship-1 7% · infra-split 3% · devops 2% · rename 1% · Last change codex-prose-authorship-1 in version 107, 12 versions changed it

You're reading version 143. The newest is 318, and 1 version since then changed this file. Go to the newestCompare with 318

1// The Issues commands (#54) as far as the client alone decides them: which
2// Issues Worker a folder talks to, whether the token may go there, the MCP
3// tools, and the usage mistakes refused before any call. The Issues server
4// here is a stand-in that only counts calls; the commands against the real
5// store are issues/test/client-commands.test.ts, on the platform side (abso
6// issue 141).
7
8import assert from "node:assert/strict";
9import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
10import { createServer, type Server } from "node:http";
11import type { AddressInfo } from "node:net";
12import { tmpdir } from "node:os";
13import { join } from "node:path";
14import { after, before, describe, it } from "node:test";
15import { readConfig, readMachineServers } from "../src/config.ts";
16import { issuesServerFor, tokenGoesTo } from "../src/core.ts";
17import { issuePage, searchLines } from "../src/issues.ts";
18import type { IssuePage } from "../src/issues-wire.ts";
19import { main } from "../src/main.ts";
20import { argvFor, mcpTools } from "../src/mcp.ts";
21import { type Fake, startFake } from "./fake-server.ts";
23const TOKEN = "test-token-not-secret";
25let fake: Fake;
26let issues: Server;
27let issuesUrl: string;
28/** Every call the stand-in Issues server took. */
29const seen: string[] = [];
30/** The bodies of the copy requests it took. */
31const copies: Record<string, unknown>[] = [];
32/** The bodies of the replies it took. */
33const replies: { text: string; question?: boolean }[] = [];
34/** An open ask of fay's from desk with a thread: fay's ack, then a question back, so it waits on desk. */
35const threaded = {
36 id: 7,
37 issue: 3,
38 title: "Pull is slow",
39 by: "desk",
40 of: "fay",
41 kind: "question",
42 question: "Which way?",
43 review: false,
44 due: null,
45 recommendation: null,
46 options: [],
47 blocks: [],
48 at: 0,
49 answer: null,
50 seen: 0,
51 ack: { at: 0, note: "ok, let me check" },
52 replies: [
53 { id: 1, by: "fay", text: "ok, let me check", at: 0 },
54 { id: 2, by: "fay", text: "staging or live?\nlive is 906", at: 0, question: true },
55 ],
56 waitingOn: "desk",
57};
58const dirs: string[] = [];
60before(async () => {
61 fake = await startFake(0, TOKEN);
62 issues = createServer((req, res) => {
63 seen.push(`${req.method} ${req.url}`);
64 const send = (status: number, body: unknown) =>
65 res.writeHead(status, { "content-type": "application/json" }).end(JSON.stringify(body));
66 if (req.method === "POST" && /\/copy$/.test(req.url ?? "")) {
67 let raw = "";
68 req.on("data", (c: Buffer) => (raw += c.toString("utf8")));
69 req.on("end", () => {
70 const body = JSON.parse(raw) as Record<string, unknown>;
71 copies.push(body);
72 // Issue 403 stands for a live server refusing an agent's copy.
73 if (body.issue === 403 && body.dryRun !== true)
74 return send(403, { error: "copying an issue out of its project takes an owner of that project" });
75 const skipped = { comments: [4], asks: [2] };
76 if (body.dryRun === true)
77 return send(200, {
78 dryRun: true,
79 plan: {
80 from: { project: body.from, issue: body.issue },
81 title: "Pull is slow",
82 edited: ["description"],
83 labels: ["client"],
84 closed: { how: "done" },
85 comments: [{ edited: false }, { edited: true }],
86 asks: [{ edited: false }],
87 skipped,
88 },
89 });
90 send(200, { ok: true, id: 31, from: { project: body.from, issue: body.issue }, skipped });
91 });
92 return;
93 }
94 // An ack answers with the ask, acknowledged and still open.
95 const ack = /\/a\/([^/]+)\/ack\/(\d+)$/.exec(req.url ?? "");
96 if (req.method === "POST" && ack)
97 return send(200, {
98 ask: { id: Number(ack[2]), by: "desk", of: ack[1], answer: null, ack: { at: Date.now(), note: "" } },
99 });
100 // Ask 404 stands for a server from before ask threads: neither route is there.
101 if (/\/(ask|reply)\/404$/.test(req.url ?? "")) return send(404, { error: "no such issues route" });
102 // A reply answers with the ask; from the one asked, a question makes it wait on the asker.
103 const reply = /\/a\/([^/]+)\/reply\/(\d+)$/.exec(req.url ?? "");
104 if (req.method === "POST" && reply) {
105 let raw = "";
106 req.on("data", (c: Buffer) => (raw += c.toString("utf8")));
107 req.on("end", () => {
108 const body = JSON.parse(raw) as { text: string; question?: boolean };
109 replies.push(body);
110 send(200, {
111 ask: {
112 id: Number(reply[2]),
113 by: "desk",
114 of: reply[1],
115 answer: null,
116 waitingOn: body.question ? "desk" : reply[1],
117 },
118 });
119 });
120 return;
121 }
122 // One ask with its thread, and the asks an agent sent.
123 const one = /\/ask\/(\d+)$/.exec(req.url ?? "");
124 if (req.method === "GET" && one) return send(200, { ask: { ...threaded, id: Number(one[1]) } });
125 if (req.method === "GET" && /\/a\/[^/]+\/asked$/.test(req.url ?? ""))
126 return send(200, {
127 asks: [
128 threaded,
129 { ...threaded, id: 8, replies: [], answer: { by: "fay", words: "yes", at: 0 }, waitingOn: null },
130 ],
131 });
132 send(500, { error: "a stand-in" });
133 });
134 // As fake-server.ts: never close an idle kept-alive connection, or under load the client can reuse one as it closes
135 // and fail with ECONNRESET (abso 410).
136 issues.keepAliveTimeout = 0;
137 await new Promise<void>((ok) => issues.listen(0, "127.0.0.1", ok));
138 issuesUrl = `http://127.0.0.1:${(issues.address() as AddressInfo).port}`;
139});
140after(async () => {
141 await fake.close();
142 await new Promise((ok) => issues.close(ok));
143 for (const d of dirs) rmSync(d, { recursive: true, force: true, maxRetries: 5 });
144});
146const ENV = (): Record<string, string> => ({
147 AVCS_TOKEN: TOKEN,
148 AVCS_HOOK_FORCE: "1",
149 AVCS_ISSUES_SERVER: issuesUrl,
150 AVCS_SERVERS_FILE: "no-servers.json",
151});
153async function avcs(
154 cwd: string,
155 argv: string[],
156 env: Record<string, string> = ENV(),
157): Promise<{ exit: number; out: string }> {
158 const r = await main([...argv, "--json"], { cwd, env, write: () => {} });
159 return { exit: r.exit, out: r.stdout + r.stderr };
162let projects = 0;
163async function folder(agent: string): Promise<string> {
164 const dir = mkdtempSync(join(tmpdir(), "avcs-issues-"));
165 dirs.push(dir);
166 const r = await avcs(dir, ["init", "--server", fake.url, "--project", `issues${++projects}`, "--agent", agent]);
167 assert.equal(r.exit, 0, r.out);
168 return dir;
171describe("issues commands, the client's part (#54)", () => {
172 it("sends the token only to an Issues Worker it trusts", async () => {
173 const dave = await folder("dave");
174 const before = seen.length;
175 const r = await avcs(dave, ["issues"], { ...ENV(), AVCS_ISSUES_SERVER: "https://issues.example.com" });
176 assert.equal(r.exit, 1, r.out);
177 assert.match(r.out, /sends your token only to its own servers and this machine/);
178 assert.equal(seen.length, before);
179 // A server with no Issues Worker beside it, and none named.
180 const { AVCS_ISSUES_SERVER: _, ...without } = ENV();
181 const none = await avcs(dave, ["waiting"], without);
182 assert.notEqual(none.exit, 0);
183 assert.match(
184 none.out,
185 /has no Issues Worker beside it that abso knows; ~\/\.abso\/servers\.json or ABSO_ISSUES_SERVER names one/,
186 );
187 });
189 it("finds a server's Issues Worker in this machine's servers.json, and may send it the token", async () => {
190 const dir = mkdtempSync(join(tmpdir(), "abso-servers-"));
191 dirs.push(dir);
192 const file = join(dir, "servers.json");
193 writeFileSync(file, JSON.stringify({ servers: { [fake.url]: { issues: issuesUrl } } }));
194 const erin = await folder("erin");
195 const before = seen.length;
196 const { AVCS_ISSUES_SERVER: _, ...without } = ENV();
197 await avcs(erin, ["waiting"], { ...without, AVCS_SERVERS_FILE: file });
198 assert.ok(seen.length > before, "the call went to the Issues Worker servers.json names");
199 const machine = readMachineServers({ AVCS_SERVERS_FILE: file });
200 assert.equal(issuesServerFor(fake.url, machine), issuesUrl);
201 assert.equal(issuesServerFor("https://abso.example", machine), undefined);
202 // abso's own server and its Issues Worker are built in.
203 assert.ok(tokenGoesTo("https://api.abso.dev"));
204 assert.ok(tokenGoesTo("https://issues.abso.dev"));
205 assert.equal(issuesServerFor("https://api.abso.dev/"), "https://issues.abso.dev");
206 });
208 it("are MCP tools", () => {
209 const names = mcpTools().map((t) => t.name);
210 for (const n of ["issues", "issue", "search", "ask", "waiting", "answer", "ack", "reply"])
211 assert.ok(names.includes(n), n);
212 assert.deepEqual(argvFor("ask", { args: ["alice", "Which login?"], issue: "3", review: true }), [
213 "ask",
214 "--issue=3",
215 "--review",
216 "--",
217 "alice",
218 "Which login?",
219 ]);
220 });
222 it("refuses usage mistakes before any call", async () => {
223 const erin = await folder("erin");
224 const before = seen.length;
225 for (const argv of [
226 ["issue"],
227 ["issue", "x"],
228 ["ask", "alice"],
229 ["ask", "a", "q", "--review", "--task"],
230 ["answer", "3"],
231 ["issue", "1", "--comment", "a", "--drop"],
232 ["issues", "extra"],
233 ["ask", "--withdraw", "x"],
234 ["ask", "--withdraw", "3", "alice", "q"],
235 ["ask", "--withdraw", "3", "--issue", "2"],
236 ["ask", "--withdraw", "3", "--task"],
237 ["ask", "alice", "q", "--note", "a note without --withdraw"],
238 ["search"],
239 ["search", "words", "--limit", "0"],
240 ["search", "words", "--limit", "51"],
241 ]) {
242 const r = await avcs(erin, argv);
243 assert.equal(r.exit, 1, `${argv.join(" ")}: ${r.out}`);
244 }
245 assert.equal(seen.length, before);
246 });
248 it("shows a search hit as the issue, then where it matched, without the match markers", () => {
249 const unknownAuthorship = {
250 kind: "unknown" as const,
251 actor: null,
252 provenance: "unknown" as const,
253 authorField: null,
254 };
255 const issue = {
256 id: 12,
257 title: "Pull is slow",
258 status: "open" as const,
259 updated: 0,
260 labels: [],
261 authorship: { title: unknownAuthorship },
262 };
263 assert.deepEqual(
264 searchLines({
265 issue,
266 where: "comment",
267 comment: 40,
268 snippet: "the \u0001network\u0002 drops mid-sync",
269 matchedAuthorship: unknownAuthorship,
270 }),
271 [' 12 open "Pull is slow"', ' in comment 40: "the network drops mid-sync"'],
272 );
273 assert.deepEqual(
274 searchLines({
275 issue,
276 where: "description",
277 snippet: "Pages load late.",
278 meaning: true,
279 matchedAuthorship: unknownAuthorship,
280 }),
281 [' 12 open "Pull is slow"', ' by meaning: "Pages load late."'],
282 );
283 assert.deepEqual(
284 searchLines({ issue, where: "title", snippet: "Pull is slow", matchedAuthorship: unknownAuthorship })[1],
285 " in the title",
286 );
287 });
289 it("withdraw is one POST to the asker's own withdraw/<ask> route", async () => {
290 const erin = await folder("erin");
291 const before = seen.length;
292 await avcs(erin, ["ask", "--withdraw", "#3", "--note", "overtaken by later decisions"]);
293 const posts = seen.slice(before).filter((s) => s.startsWith("POST"));
294 assert.equal(posts.length, 1, posts.join("\n"));
295 assert.match(posts[0]!, /^POST \/p\/issues\d+\/a\/erin\/withdraw\/3$/);
296 });
298 it("ack is one POST to the one asked's ack/<ask> route, and says the ask stays open", async () => {
299 const fay = await folder("fay");
300 const before = seen.length;
301 const r = await main(["ack", "7", "on it after the deploy"], { cwd: fay, env: ENV(), write: () => {} });
302 assert.equal(r.exit, 0, r.stdout + r.stderr);
303 assert.equal(
304 r.stdout,
305 'Acknowledged ask 7. desk hears it; abso reply 7 "..." adds more as you go, and the ask stays open until abso answer 7 "...".\n',
306 );
307 const posts = seen.slice(before).filter((s) => s.startsWith("POST"));
308 assert.deepEqual(posts.length, 1, posts.join("\n"));
309 assert.match(posts[0]!, /^POST \/p\/issues\d+\/a\/fay\/ack\/7$/);
310 assert.equal((await main(["ack"], { cwd: fay, env: ENV(), write: () => {} })).exit, 1);
311 });
313 it("reply is one POST to reply/<ask> with the words, and says whose turn it is", async () => {
314 const fay = await folder("fay");
315 const before = seen.length;
316 const r = await main(["reply", "7", "staging or live?", "--question"], { cwd: fay, env: ENV(), write: () => {} });
317 assert.equal(r.exit, 0, r.stdout + r.stderr);
318 const posts = seen.slice(before).filter((s) => s.startsWith("POST"));
319 assert.equal(posts.length, 1, posts.join("\n"));
320 assert.match(posts[0]!, /^POST \/p\/issues\d+\/a\/fay\/reply\/7$/);
321 assert.deepEqual(replies.at(-1), { text: "staging or live?", question: true });
322 assert.equal(r.stdout, "Replied on ask 7. desk hears it. It waits on desk.\n");
323 assert.equal((await main(["reply", "7"], { cwd: fay, env: ENV(), write: () => {} })).exit, 1);
324 });
326 it("names a server from before ask threads instead of a bare 404", async () => {
327 const fay = await folder("fay");
328 for (const argv of [
329 ["reply", "404", "still there?"],
330 ["ask", "404"],
331 ]) {
332 const r = await main(argv, { cwd: fay, env: ENV(), write: () => {} });
333 assert.equal(r.exit, 1, argv.join(" "));
334 assert.match(r.stderr, /doesn't have ask threads yet/, argv.join(" "));
335 assert.doesNotMatch(r.stderr, /no such issues route/, argv.join(" "));
336 }
337 });
339 it("ask <N> reads one ask with its whole thread, oldest first, and whose turn it is", async () => {
340 const fay = await folder("fay");
341 const before = seen.length;
342 const r = await main(["ask", "7"], { cwd: fay, env: ENV(), write: () => {} });
343 assert.equal(r.exit, 0, r.stdout + r.stderr);
344 assert.match(seen.slice(before).join("\n"), /^GET \/p\/issues\d+\/ask\/7$/m);
345 assert.match(
346 r.stdout,
347 /^ {2}ask 7: desk, .* asks fay a question on issue 3 \("Pull is slow"\) \(2 replies; waiting on desk\): "Which way\?"$/m,
348 );
349 const ack = r.stdout.indexOf(' fay, Jan 1 1970 00:00 UTC: "ok, let me check"');
350 const back = r.stdout.indexOf(' fay, Jan 1 1970 00:00 UTC, a question: "staging or live?\\nlive is 906"');
351 assert.ok(ack > 0 && back > ack, r.stdout);
352 assert.match(
353 r.stdout,
354 /^It waits on desk\. abso reply 7 "\.\.\." adds to it; abso answer 7 "\.\.\." answers and closes it\.$/m,
355 );
356 // The asker reads it as their turn, and can't answer it.
357 const desk = await folder("desk");
358 const d = await main(["ask", "7"], { cwd: desk, env: ENV(), write: () => {} });
359 assert.match(d.stdout, /^It waits on you\. abso reply 7 "\.\.\." adds to it\.$/m);
360 });
362 it("waiting --asked lists the asks you sent, open first, then the latest answered", async () => {
363 const fay = await folder("fay");
364 const before = seen.length;
365 const r = await main(["waiting", "--asked"], { cwd: fay, env: ENV(), write: () => {} });
366 assert.equal(r.exit, 0, r.stdout + r.stderr);
367 assert.match(seen.slice(before).join("\n"), /^GET \/p\/issues\d+\/a\/fay\/asked$/m);
368 assert.match(r.stdout, /^1 open ask you sent:$/m);
369 assert.match(r.stdout, /^ {4}last: fay, .*, a question: "staging or live\? \.\.\."$/m);
370 assert.ok(r.stdout.indexOf("ask 7:") < r.stdout.indexOf("The latest answered:"), r.stdout);
371 assert.ok(r.stdout.indexOf("The latest answered:") < r.stdout.indexOf("ask 8:"), r.stdout);
372 assert.match(r.stdout, /^ {4}answer: "yes"$/m);
373 });
375 it("an acknowledged ask reads as acknowledged, not answered, with the note under it", () => {
376 const ask = {
377 id: 7,
378 issue: 3,
379 by: "desk",
380 of: "fay",
381 kind: "question",
382 question: "Which way?",
383 review: false,
384 due: null,
385 recommendation: null,
386 options: [],
387 blocks: [],
388 at: 0,
389 answer: null,
390 seen: 0,
391 ack: { at: 0, note: "on it after the deploy" },
392 };
393 const page = {
394 issue: {
395 id: 3,
396 title: "t",
397 status: "blocked",
398 parent: null,
399 opened: { by: "desk", at: 0 },
400 agent: null,
401 agents: [],
402 blockedBy: [],
403 labels: [],
404 versions: [],
405 waitingOn: ["fay"],
406 closed: null,
407 description: "",
408 lines: null,
409 watchers: [],
410 },
411 comments: [],
412 edits: [],
413 asks: [ask],
414 claims: [],
415 children: [],
416 } as unknown as IssuePage;
417 const text = issuePage(page).join("\n");
418 assert.match(
419 text,
420 /\n {2}ask 7: desk, [^\n]*asks fay a question on issue 3 \(acknowledged [^;)]+, not answered yet\): "Which way\?"\n {4}fay acknowledged: "on it after the deploy"/,
421 );
422 assert.doesNotMatch(text, /answer:/);
423 const answered = { ...ask, answer: { by: "fay", words: "This way", at: 0 } };
424 const later = issuePage({ ...page, asks: [answered] } as unknown as IssuePage).join("\n");
425 assert.doesNotMatch(later, /acknowledged/, "an answer replaces the ack");
426 });
427});
429describe("abso issue <N> --copy-to <project>", () => {
430 const text = async (cwd: string, argv: string[]) => {
431 const r = await main(argv, { cwd, env: ENV(), write: () => {} });
432 return { exit: r.exit, out: r.stdout + r.stderr };
433 };
435 it("a dry run asks the other project's copy route for the plan, and says nothing was written", async () => {
436 const gil = await folder("gil");
437 const before = seen.length;
438 const r = await text(gil, ["issue", "12", "--copy-to", "core", "--dry-run"]);
439 assert.equal(r.exit, 0, r.out);
440 assert.deepEqual(seen.slice(before), ["POST /p/core/a/gil/copy"]);
441 const from = (copies.at(-1) as { from: string }).from;
442 assert.match(from, /^issues\d+$/);
443 assert.deepEqual(copies.at(-1), { from, issue: 12, dryRun: true });
444 assert.equal(
445 r.out.trimEnd(),
446 [
447 `A dry run: nothing was written. Copying ${from} issue 12 into core would make:`,
448 ` "Pull is slow", done (description edited when copied)`,
449 " 2 comments (1 edited), 1 answered ask, labelled client",
450 " not copied: comments 4; asks 2 (open asks, and what --clean left out)",
451 "Run it again without --dry-run to copy it.",
452 ].join("\n"),
453 );
454 });
456 it("copies with the cleaned texts --clean gives, by source id", async () => {
457 const gil = await folder("gil");
458 writeFileSync(
459 join(gil, "clean.json"),
460 JSON.stringify({ description: "Cleaned.", comments: [{ id: 1 }, { id: 3, text: "Cleaned too." }] }),
461 );
462 const r = await text(gil, ["issue", "12", "--copy-to", "core", "--clean", "clean.json"]);
463 assert.equal(r.exit, 0, r.out);
464 const from = (copies.at(-1) as { from: string }).from;
465 assert.deepEqual(copies.at(-1), {
466 description: "Cleaned.",
467 comments: [{ id: 1 }, { id: 3, text: "Cleaned too." }],
468 from,
469 issue: 12,
470 });
471 assert.match(
472 r.out,
473 new RegExp(`^Copied ${from} issue 12 to core issue 31\\. Its comments and asks keep their authors`),
474 );
475 });
477 it("says a dry run still works when the server refuses the copy", async () => {
478 const gil = await folder("gil");
479 const r = await text(gil, ["issue", "403", "--copy-to", "core"]);
480 assert.equal(r.exit, 1, r.out);
481 assert.match(r.out, /takes an owner of that project\. --dry-run still shows what would go\./);
482 });
484 it("refuses mistakes before any call", async () => {
485 const gil = await folder("gil");
486 writeFileSync(join(gil, "bad.json"), JSON.stringify({ from: "elsewhere" }));
487 const before = seen.length;
488 for (const [argv, why] of [
489 [["issue", "12", "--copy-to", "core", "--comment", "x"], /--copy-to goes alone .* not with --comment/],
490 [["issue", "12", "--dry-run"], /--clean and --dry-run go with --copy-to <project>/],
491 [["issue", "12", "--copy-to", "core", "--clean", "nope.json"], /--clean nope\.json: no such file/],
492 [
493 ["issue", "12", "--copy-to", "core", "--clean", "bad.json"],
494 /from isn't one of title, description, comments, asks/,
495 ],
496 ] as const) {
497 const r = await text(gil, [...argv]);
498 assert.notEqual(r.exit, 0, argv.join(" "));
499 assert.match(r.out, why);
500 }
501 const { project } = readConfig(gil);
502 assert.match(
503 (await text(gil, ["issue", "12", "--copy-to", project])).out,
504 /issue 12 is already in issues\d+; --copy-to names another project/,
505 );
506 assert.equal(seen.length, before, "nothing reached the Issues server");
507 });
508});