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 0 to 318

Compare

+410 −13 in 6 places
Lines 12–21 at 318 (were 12–19 at 0)
1212import { tmpdir } from "node:os";
1313import { join } from "node:path";
1414import { after, before, describe, it } from "node:test";
15−import { readMachineServers } from "../src/config.ts";
16−import { issuesServerFor, tokenGoesTo } from "../src/core.ts";
15+import { readConfig, readMachineServers } from "../src/config.ts";
16+import { issuesServerFor, tokenGoesTo, tokenGoesToIssues } from "../src/core.ts";
17+import { issuePage, searchLines } from "../src/issues.ts";
18+import type { IssuePage } from "../src/issues-wire.ts";
1719import { main } from "../src/main.ts";
1820import { argvFor, mcpTools } from "../src/mcp.ts";
1921import { type Fake, startFake } from "./fake-server.ts";
Lines 27–139 at 318 (were 25–38 at 0)
2527let issuesUrl: string;
2628/** Every call the stand-in Issues server took. */
2729const seen: string[] = [];
30+/** The bodies of the copy requests it took. */
31+const copies: Record<string, unknown>[] = [];
32+/** The bodies of the replies it took. */
33+const 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. */
35+const 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+};
2858const dirs: string[] = [];
2959
3060before(async () => {
3161 fake = await startFake(0, TOKEN);
3262 issues = createServer((req, res) => {
3363 seen.push(`${req.method} ${req.url}`);
34− res.writeHead(500, { "content-type": "application/json" }).end(JSON.stringify({ error: "a stand-in" }));
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" });
35133 });
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;
36137 await new Promise<void>((ok) => issues.listen(0, "127.0.0.1", ok));
37138 issuesUrl = `http://127.0.0.1:${(issues.address() as AddressInfo).port}`;
38139});
Lines 176–217 at 318 (were 75–90 at 0)
75176 assert.equal(r.exit, 1, r.out);
76177 assert.match(r.out, /sends your token only to its own servers and this machine/);
77178 assert.equal(seen.length, before);
78− // A server with no Issues Worker beside it, and none named.
79− const { AVCS_ISSUES_SERVER: _, ...without } = ENV();
80− const none = await avcs(dave, ["waiting"], without);
81− assert.notEqual(none.exit, 0);
82− assert.match(
83− none.out,
84− /has no Issues Worker beside it that abso knows; ~\/\.avcs\/servers\.json or AVCS_ISSUES_SERVER names one/,
85− );
86179 });
87180
181+ it("with no Issues Worker named, uses the server's own /issues, as the open server keeps them", () => {
182+ assert.equal(issuesServerFor("https://abso.example"), "https://abso.example/issues");
183+ assert.equal(issuesServerFor("https://Abso.Example/"), "https://abso.example/issues");
184+ assert.equal(issuesServerFor("http://localhost:8787"), "http://localhost:8787/issues");
185+ assert.equal(issuesServerFor("not a server"), undefined);
186+ // abso's hosted server keeps its own Issues Worker, and servers.json still comes first.
187+ assert.equal(issuesServerFor("https://api.abso.dev"), "https://issues.abso.dev");
188+ const machine = {
189+ trusted: [],
190+ issues: { "https://staging.abso.example": "https://issues-staging.abso.example" },
191+ };
192+ assert.equal(issuesServerFor("https://staging.abso.example", machine), "https://issues-staging.abso.example");
193+ // The token goes to <server>/issues exactly where it goes to <server>.
194+ assert.ok(tokenGoesToIssues("https://api.abso.dev/issues"));
195+ assert.ok(tokenGoesToIssues("http://localhost:8787/issues"));
196+ assert.ok(tokenGoesToIssues("https://mine.example/issues", "https://mine.example"));
197+ assert.equal(tokenGoesToIssues("https://evil.example/issues"), false);
198+ assert.equal(tokenGoesToIssues("https://api.abso.dev@evil.example/issues"), false);
199+ assert.equal(tokenGoesToIssues("https://api.abso.dev/issues?x=1"), false);
200+ assert.equal(tokenGoesToIssues("http://mine.example/issues", "http://mine.example"), false, "plain http only here");
201+ // The server itself still takes no path.
202+ assert.equal(tokenGoesTo("https://api.abso.dev/issues"), false);
203+ });
205+ it("calls <issues server>/p/<project>/... when the Issues Worker is at a path", async () => {
206+ const fay = await folder("fay");
207+ const before = seen.length;
208+ const env = { ...ENV(), AVCS_ISSUES_SERVER: `${issuesUrl}/issues` };
209+ const r = await main(["ask", "7"], { cwd: fay, env, write: () => {} });
210+ assert.equal(r.exit, 0, r.stdout + r.stderr);
211+ const { project } = readConfig(fay);
212+ assert.deepEqual(seen.slice(before), [`GET /issues/p/${project}/ask/7`]);
213+ });
88215 it("finds a server's Issues Worker in this machine's servers.json, and may send it the token", async () => {
89216 const dir = mkdtempSync(join(tmpdir(), "abso-servers-"));
90217 dirs.push(dir);
Lines 224–230 at 318 (were 97–103 at 0)
97224 assert.ok(seen.length > before, "the call went to the Issues Worker servers.json names");
98225 const machine = readMachineServers({ AVCS_SERVERS_FILE: file });
99226 assert.equal(issuesServerFor(fake.url, machine), issuesUrl);
100− assert.equal(issuesServerFor("https://abso.example", machine), undefined);
227+ assert.equal(issuesServerFor("https://abso.example", machine), "https://abso.example/issues");
101228 // abso's own server and its Issues Worker are built in.
102229 assert.ok(tokenGoesTo("https://api.abso.dev"));
103230 assert.ok(tokenGoesTo("https://issues.abso.dev"));
Lines 233–240 at 318 (were 106–112 at 0)
106233
107234 it("are MCP tools", () => {
108235 const names = mcpTools().map((t) => t.name);
109− for (const n of ["issues", "issue", "ask", "waiting", "answer"]) assert.ok(names.includes(n), n);
236+ for (const n of ["issues", "issue", "search", "ask", "waiting", "answer", "ack", "reply"])
237+ assert.ok(names.includes(n), n);
110238 assert.deepEqual(argvFor("ask", { args: ["alice", "Which login?"], issue: "3", review: true }), [
111239 "ask",
112240 "--issue=3",
Lines 256–534 at 318 (were 128–137 at 0)
128256 ["answer", "3"],
129257 ["issue", "1", "--comment", "a", "--drop"],
130258 ["issues", "extra"],
259+ ["ask", "--withdraw", "x"],
260+ ["ask", "--withdraw", "3", "alice", "q"],
261+ ["ask", "--withdraw", "3", "--issue", "2"],
262+ ["ask", "--withdraw", "3", "--task"],
263+ ["ask", "alice", "q", "--note", "a note without --withdraw"],
264+ ["search"],
265+ ["search", "words", "--limit", "0"],
266+ ["search", "words", "--limit", "51"],
131267 ]) {
132268 const r = await avcs(erin, argv);
133269 assert.equal(r.exit, 1, `${argv.join(" ")}: ${r.out}`);
134270 }
135271 assert.equal(seen.length, before);
136272 });
274+ it("shows a search hit as the issue, then where it matched, without the match markers", () => {
275+ const unknownAuthorship = {
276+ kind: "unknown" as const,
277+ actor: null,
278+ provenance: "unknown" as const,
279+ authorField: null,
280+ };
281+ const issue = {
282+ id: 12,
283+ title: "Pull is slow",
284+ status: "open" as const,
285+ updated: 0,
286+ labels: [],
287+ authorship: { title: unknownAuthorship },
288+ };
289+ assert.deepEqual(
290+ searchLines({
291+ issue,
292+ where: "comment",
293+ comment: 40,
294+ snippet: "the \u0001network\u0002 drops mid-sync",
295+ matchedAuthorship: unknownAuthorship,
296+ }),
297+ [' 12 open "Pull is slow"', ' in comment 40: "the network drops mid-sync"'],
298+ );
299+ assert.deepEqual(
300+ searchLines({
301+ issue,
302+ where: "description",
303+ snippet: "Pages load late.",
304+ meaning: true,
305+ matchedAuthorship: unknownAuthorship,
306+ }),
307+ [' 12 open "Pull is slow"', ' by meaning: "Pages load late."'],
308+ );
309+ assert.deepEqual(
310+ searchLines({ issue, where: "title", snippet: "Pull is slow", matchedAuthorship: unknownAuthorship })[1],
311+ " in the title",
312+ );
313+ });
315+ it("withdraw is one POST to the asker's own withdraw/<ask> route", async () => {
316+ const erin = await folder("erin");
317+ const before = seen.length;
318+ await avcs(erin, ["ask", "--withdraw", "#3", "--note", "overtaken by later decisions"]);
319+ const posts = seen.slice(before).filter((s) => s.startsWith("POST"));
320+ assert.equal(posts.length, 1, posts.join("\n"));
321+ assert.match(posts[0]!, /^POST \/p\/issues\d+\/a\/erin\/withdraw\/3$/);
322+ });
324+ it("ack is one POST to the one asked's ack/<ask> route, and says the ask stays open", async () => {
325+ const fay = await folder("fay");
326+ const before = seen.length;
327+ const r = await main(["ack", "7", "on it after the deploy"], { cwd: fay, env: ENV(), write: () => {} });
328+ assert.equal(r.exit, 0, r.stdout + r.stderr);
329+ assert.equal(
330+ r.stdout,
331+ 'Acknowledged ask 7. desk hears it; abso reply 7 "..." adds more as you go, and the ask stays open until abso answer 7 "...".\n',
332+ );
333+ const posts = seen.slice(before).filter((s) => s.startsWith("POST"));
334+ assert.deepEqual(posts.length, 1, posts.join("\n"));
335+ assert.match(posts[0]!, /^POST \/p\/issues\d+\/a\/fay\/ack\/7$/);
336+ assert.equal((await main(["ack"], { cwd: fay, env: ENV(), write: () => {} })).exit, 1);
337+ });
339+ it("reply is one POST to reply/<ask> with the words, and says whose turn it is", async () => {
340+ const fay = await folder("fay");
341+ const before = seen.length;
342+ const r = await main(["reply", "7", "staging or live?", "--question"], { cwd: fay, env: ENV(), write: () => {} });
343+ assert.equal(r.exit, 0, r.stdout + r.stderr);
344+ const posts = seen.slice(before).filter((s) => s.startsWith("POST"));
345+ assert.equal(posts.length, 1, posts.join("\n"));
346+ assert.match(posts[0]!, /^POST \/p\/issues\d+\/a\/fay\/reply\/7$/);
347+ assert.deepEqual(replies.at(-1), { text: "staging or live?", question: true });
348+ assert.equal(r.stdout, "Replied on ask 7. desk hears it. It waits on desk.\n");
349+ assert.equal((await main(["reply", "7"], { cwd: fay, env: ENV(), write: () => {} })).exit, 1);
350+ });
352+ it("names a server from before ask threads instead of a bare 404", async () => {
353+ const fay = await folder("fay");
354+ for (const argv of [
355+ ["reply", "404", "still there?"],
356+ ["ask", "404"],
357+ ]) {
358+ const r = await main(argv, { cwd: fay, env: ENV(), write: () => {} });
359+ assert.equal(r.exit, 1, argv.join(" "));
360+ assert.match(r.stderr, /doesn't have ask threads yet/, argv.join(" "));
361+ assert.doesNotMatch(r.stderr, /no such issues route/, argv.join(" "));
362+ }
363+ });
365+ it("ask <N> reads one ask with its whole thread, oldest first, and whose turn it is", async () => {
366+ const fay = await folder("fay");
367+ const before = seen.length;
368+ const r = await main(["ask", "7"], { cwd: fay, env: ENV(), write: () => {} });
369+ assert.equal(r.exit, 0, r.stdout + r.stderr);
370+ assert.match(seen.slice(before).join("\n"), /^GET \/p\/issues\d+\/ask\/7$/m);
371+ assert.match(
372+ r.stdout,
373+ /^ {2}ask 7: desk, .* asks fay a question on issue 3 \("Pull is slow"\) \(2 replies; waiting on desk\): "Which way\?"$/m,
374+ );
375+ const ack = r.stdout.indexOf(' fay, Jan 1 1970 00:00 UTC: "ok, let me check"');
376+ const back = r.stdout.indexOf(' fay, Jan 1 1970 00:00 UTC, a question: "staging or live?\\nlive is 906"');
377+ assert.ok(ack > 0 && back > ack, r.stdout);
378+ assert.match(
379+ r.stdout,
380+ /^It waits on desk\. abso reply 7 "\.\.\." adds to it; abso answer 7 "\.\.\." answers and closes it\.$/m,
381+ );
382+ // The asker reads it as their turn, and can't answer it.
383+ const desk = await folder("desk");
384+ const d = await main(["ask", "7"], { cwd: desk, env: ENV(), write: () => {} });
385+ assert.match(d.stdout, /^It waits on you\. abso reply 7 "\.\.\." adds to it\.$/m);
386+ });
388+ it("waiting --asked lists the asks you sent, open first, then the latest answered", async () => {
389+ const fay = await folder("fay");
390+ const before = seen.length;
391+ const r = await main(["waiting", "--asked"], { cwd: fay, env: ENV(), write: () => {} });
392+ assert.equal(r.exit, 0, r.stdout + r.stderr);
393+ assert.match(seen.slice(before).join("\n"), /^GET \/p\/issues\d+\/a\/fay\/asked$/m);
394+ assert.match(r.stdout, /^1 open ask you sent:$/m);
395+ assert.match(r.stdout, /^ {4}last: fay, .*, a question: "staging or live\? \.\.\."$/m);
396+ assert.ok(r.stdout.indexOf("ask 7:") < r.stdout.indexOf("The latest answered:"), r.stdout);
397+ assert.ok(r.stdout.indexOf("The latest answered:") < r.stdout.indexOf("ask 8:"), r.stdout);
398+ assert.match(r.stdout, /^ {4}answer: "yes"$/m);
399+ });
401+ it("an acknowledged ask reads as acknowledged, not answered, with the note under it", () => {
402+ const ask = {
403+ id: 7,
404+ issue: 3,
405+ by: "desk",
406+ of: "fay",
407+ kind: "question",
408+ question: "Which way?",
409+ review: false,
410+ due: null,
411+ recommendation: null,
412+ options: [],
413+ blocks: [],
414+ at: 0,
415+ answer: null,
416+ seen: 0,
417+ ack: { at: 0, note: "on it after the deploy" },
418+ };
419+ const page = {
420+ issue: {
421+ id: 3,
422+ title: "t",
423+ status: "blocked",
424+ parent: null,
425+ opened: { by: "desk", at: 0 },
426+ agent: null,
427+ agents: [],
428+ blockedBy: [],
429+ labels: [],
430+ versions: [],
431+ waitingOn: ["fay"],
432+ closed: null,
433+ description: "",
434+ lines: null,
435+ watchers: [],
436+ },
437+ comments: [],
438+ edits: [],
439+ asks: [ask],
440+ claims: [],
441+ children: [],
442+ } as unknown as IssuePage;
443+ const text = issuePage(page).join("\n");
444+ assert.match(
445+ text,
446+ /\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"/,
447+ );
448+ assert.doesNotMatch(text, /answer:/);
449+ const answered = { ...ask, answer: { by: "fay", words: "This way", at: 0 } };
450+ const later = issuePage({ ...page, asks: [answered] } as unknown as IssuePage).join("\n");
451+ assert.doesNotMatch(later, /acknowledged/, "an answer replaces the ack");
452+ });
137453});
455+describe("abso issue <N> --copy-to <project>", () => {
456+ const text = async (cwd: string, argv: string[]) => {
457+ const r = await main(argv, { cwd, env: ENV(), write: () => {} });
458+ return { exit: r.exit, out: r.stdout + r.stderr };
459+ };
461+ it("a dry run asks the other project's copy route for the plan, and says nothing was written", async () => {
462+ const gil = await folder("gil");
463+ const before = seen.length;
464+ const r = await text(gil, ["issue", "12", "--copy-to", "core", "--dry-run"]);
465+ assert.equal(r.exit, 0, r.out);
466+ assert.deepEqual(seen.slice(before), ["POST /p/core/a/gil/copy"]);
467+ const from = (copies.at(-1) as { from: string }).from;
468+ assert.match(from, /^issues\d+$/);
469+ assert.deepEqual(copies.at(-1), { from, issue: 12, dryRun: true });
470+ assert.equal(
471+ r.out.trimEnd(),
472+ [
473+ `A dry run: nothing was written. Copying ${from} issue 12 into core would make:`,
474+ ` "Pull is slow", done (description edited when copied)`,
475+ " 2 comments (1 edited), 1 answered ask, labelled client",
476+ " not copied: comments 4; asks 2 (open asks, and what --clean left out)",
477+ "Run it again without --dry-run to copy it.",
478+ ].join("\n"),
479+ );
480+ });
482+ it("copies with the cleaned texts --clean gives, by source id", async () => {
483+ const gil = await folder("gil");
484+ writeFileSync(
485+ join(gil, "clean.json"),
486+ JSON.stringify({ description: "Cleaned.", comments: [{ id: 1 }, { id: 3, text: "Cleaned too." }] }),
487+ );
488+ const r = await text(gil, ["issue", "12", "--copy-to", "core", "--clean", "clean.json"]);
489+ assert.equal(r.exit, 0, r.out);
490+ const from = (copies.at(-1) as { from: string }).from;
491+ assert.deepEqual(copies.at(-1), {
492+ description: "Cleaned.",
493+ comments: [{ id: 1 }, { id: 3, text: "Cleaned too." }],
494+ from,
495+ issue: 12,
496+ });
497+ assert.match(
498+ r.out,
499+ new RegExp(`^Copied ${from} issue 12 to core issue 31\\. Its comments and asks keep their authors`),
500+ );
501+ });
503+ it("says a dry run still works when the server refuses the copy", async () => {
504+ const gil = await folder("gil");
505+ const r = await text(gil, ["issue", "403", "--copy-to", "core"]);
506+ assert.equal(r.exit, 1, r.out);
507+ assert.match(r.out, /takes an owner of that project\. --dry-run still shows what would go\./);
508+ });
510+ it("refuses mistakes before any call", async () => {
511+ const gil = await folder("gil");
512+ writeFileSync(join(gil, "bad.json"), JSON.stringify({ from: "elsewhere" }));
513+ const before = seen.length;
514+ for (const [argv, why] of [
515+ [["issue", "12", "--copy-to", "core", "--comment", "x"], /--copy-to goes alone .* not with --comment/],
516+ [["issue", "12", "--dry-run"], /--clean and --dry-run go with --copy-to <project>/],
517+ [["issue", "12", "--copy-to", "core", "--clean", "nope.json"], /--clean nope\.json: no such file/],
518+ [
519+ ["issue", "12", "--copy-to", "core", "--clean", "bad.json"],
520+ /from isn't one of title, description, comments, asks/,
521+ ],
522+ ] as const) {
523+ const r = await text(gil, [...argv]);
524+ assert.notEqual(r.exit, 0, argv.join(" "));
525+ assert.match(r.out, why);
526+ }
527+ const { project } = readConfig(gil);
528+ assert.match(
529+ (await text(gil, ["issue", "12", "--copy-to", project])).out,
530+ /issue 12 is already in issues\d+; --copy-to names another project/,
531+ );
532+ assert.equal(seen.length, before, "nothing reached the Issues server");
533+ });
534+});
MCP
compare on this site's /mcp
CLI
abso diff 0 318 client/test/issues.test.ts --json
JSON
/christopher/abso-core/compare/0..318?file=client%2Ftest%2Fissues.test.ts&format=json