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

Compare

+275 −22 in 10 places
Lines 13–21 at 318 (were 13–20 at 32)
1313import { join } from "node:path";
1414import { after, before, describe, it } from "node:test";
1515import { readConfig, readMachineServers } from "../src/config.ts";
16−import { issuesServerFor, tokenGoesTo } from "../src/core.ts";
17−import { searchLines } from "../src/issues.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";
1819import { main } from "../src/main.ts";
1920import { argvFor, mcpTools } from "../src/mcp.ts";
2021import { type Fake, startFake } from "./fake-server.ts";
Lines 29–60 at 318 (were 28–33 at 32)
2829const seen: string[] = [];
2930/** The bodies of the copy requests it took. */
3031const 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+};
3158const dirs: string[] = [];
3259
3360before(async () => {
Lines 78–84 at 318 (were 51–57 at 32)
5178 dryRun: true,
5279 plan: {
5380 from: { project: body.from, issue: body.issue },
54− title: "Sync is slow",
81+ title: "Pull is slow",
5582 edited: ["description"],
5683 labels: ["client"],
5784 closed: { how: "done" },
Lines 91–139 at 318 (were 64–71 at 32)
6491 });
6592 return;
6693 }
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+ });
67132 send(500, { error: "a stand-in" });
68133 });
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;
69137 await new Promise<void>((ok) => issues.listen(0, "127.0.0.1", ok));
70138 issuesUrl = `http://127.0.0.1:${(issues.address() as AddressInfo).port}`;
71139});
Lines 176–217 at 318 (were 108–123 at 32)
108176 assert.equal(r.exit, 1, r.out);
109177 assert.match(r.out, /sends your token only to its own servers and this machine/);
110178 assert.equal(seen.length, before);
111− // A server with no Issues Worker beside it, and none named.
112− const { AVCS_ISSUES_SERVER: _, ...without } = ENV();
113− const none = await avcs(dave, ["waiting"], without);
114− assert.notEqual(none.exit, 0);
115− assert.match(
116− none.out,
117− /has no Issues Worker beside it that abso knows; ~\/\.abso\/servers\.json or ABSO_ISSUES_SERVER names one/,
118− );
119179 });
120180
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+ });
121215 it("finds a server's Issues Worker in this machine's servers.json, and may send it the token", async () => {
122216 const dir = mkdtempSync(join(tmpdir(), "abso-servers-"));
123217 dirs.push(dir);
Lines 224–230 at 318 (were 130–136 at 32)
130224 assert.ok(seen.length > before, "the call went to the Issues Worker servers.json names");
131225 const machine = readMachineServers({ AVCS_SERVERS_FILE: file });
132226 assert.equal(issuesServerFor(fake.url, machine), issuesUrl);
133− assert.equal(issuesServerFor("https://abso.example", machine), undefined);
227+ assert.equal(issuesServerFor("https://abso.example", machine), "https://abso.example/issues");
134228 // abso's own server and its Issues Worker are built in.
135229 assert.ok(tokenGoesTo("https://api.abso.dev"));
136230 assert.ok(tokenGoesTo("https://issues.abso.dev"));
Lines 233–240 at 318 (were 139–145 at 32)
139233
140234 it("are MCP tools", () => {
141235 const names = mcpTools().map((t) => t.name);
142− for (const n of ["issues", "issue", "search", "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);
143238 assert.deepEqual(argvFor("ask", { args: ["alice", "Which login?"], issue: "3", review: true }), [
144239 "ask",
145240 "--issue=3",
Lines 272–315 at 318 (were 177–192 at 32)
177272 });
178273
179274 it("shows a search hit as the issue, then where it matched, without the match markers", () => {
180− const issue = { id: 12, title: "Sync is slow", status: "open" as const, updated: 0, labels: [] };
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+ };
181289 assert.deepEqual(
182− searchLines({ issue, where: "comment", comment: 40, snippet: "the \u0001network\u0002 drops mid-sync" }),
183− [' 12 open "Sync is slow"', ' in comment 40: "the network drops mid-sync"'],
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"'],
184298 );
185− assert.deepEqual(searchLines({ issue, where: "description", snippet: "Pages load late.", meaning: true }), [
186− ' 12 open "Sync is slow"',
187− ' by meaning: "Pages load late."',
188− ]);
189− assert.deepEqual(searchLines({ issue, where: "title", snippet: "Sync is slow" })[1], " in the title");
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+ );
190313 });
191314
192315 it("withdraw is one POST to the asker's own withdraw/<ask> route", async () => {
Lines 320–455 at 318 (were 197–202 at 32)
197320 assert.equal(posts.length, 1, posts.join("\n"));
198321 assert.match(posts[0]!, /^POST \/p\/issues\d+\/a\/erin\/withdraw\/3$/);
199322 });
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+ });
200453});
201454
202455describe("abso issue <N> --copy-to <project>", () => {
Lines 471–477 at 318 (were 218–224 at 32)
218471 r.out.trimEnd(),
219472 [
220473 `A dry run: nothing was written. Copying ${from} issue 12 into core would make:`,
221− ` "Sync is slow", done (description edited when copied)`,
474+ ` "Pull is slow", done (description edited when copied)`,
222475 " 2 comments (1 edited), 1 answered ask, labelled client",
223476 " not copied: comments 4; asks 2 (open asks, and what --clean left out)",
224477 "Run it again without --dry-run to copy it.",
MCP
compare on this site's /mcp
CLI
abso diff 32 318 client/test/issues.test.ts --json
JSON
/christopher/abso-core/compare/32..318?file=client%2Ftest%2Fissues.test.ts&format=json