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

Compare

+203 −22 in 10 places
Lines 13–19 at 318 (were 13–19 at 59)
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";
16+import { issuesServerFor, tokenGoesTo, tokenGoesToIssues } from "../src/core.ts";
1717import { issuePage, searchLines } from "../src/issues.ts";
1818import type { IssuePage } from "../src/issues-wire.ts";
1919import { main } from "../src/main.ts";
Lines 29–60 at 318 (were 29–34 at 59)
2929const seen: string[] = [];
3030/** The bodies of the copy requests it took. */
3131const 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+};
3258const dirs: string[] = [];
3359
3460before(async () => {
Lines 78–84 at 318 (were 52–58 at 59)
5278 dryRun: true,
5379 plan: {
5480 from: { project: body.from, issue: body.issue },
55− title: "Sync is slow",
81+ title: "Pull is slow",
5682 edited: ["description"],
5783 labels: ["client"],
5884 closed: { how: "done" },
Lines 97–139 at 318 (were 71–78 at 59)
7197 return send(200, {
7298 ask: { id: Number(ack[2]), by: "desk", of: ack[1], answer: null, ack: { at: Date.now(), note: "" } },
7399 });
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+ });
74132 send(500, { error: "a stand-in" });
75133 });
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;
76137 await new Promise<void>((ok) => issues.listen(0, "127.0.0.1", ok));
77138 issuesUrl = `http://127.0.0.1:${(issues.address() as AddressInfo).port}`;
78139});
Lines 176–217 at 318 (were 115–130 at 59)
115176 assert.equal(r.exit, 1, r.out);
116177 assert.match(r.out, /sends your token only to its own servers and this machine/);
117178 assert.equal(seen.length, before);
118− // A server with no Issues Worker beside it, and none named.
119− const { AVCS_ISSUES_SERVER: _, ...without } = ENV();
120− const none = await avcs(dave, ["waiting"], without);
121− assert.notEqual(none.exit, 0);
122− assert.match(
123− none.out,
124− /has no Issues Worker beside it that abso knows; ~\/\.abso\/servers\.json or ABSO_ISSUES_SERVER names one/,
125− );
126179 });
127180
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+ });
128215 it("finds a server's Issues Worker in this machine's servers.json, and may send it the token", async () => {
129216 const dir = mkdtempSync(join(tmpdir(), "abso-servers-"));
130217 dirs.push(dir);
Lines 224–230 at 318 (were 137–143 at 59)
137224 assert.ok(seen.length > before, "the call went to the Issues Worker servers.json names");
138225 const machine = readMachineServers({ AVCS_SERVERS_FILE: file });
139226 assert.equal(issuesServerFor(fake.url, machine), issuesUrl);
140− assert.equal(issuesServerFor("https://abso.example", machine), undefined);
227+ assert.equal(issuesServerFor("https://abso.example", machine), "https://abso.example/issues");
141228 // abso's own server and its Issues Worker are built in.
142229 assert.ok(tokenGoesTo("https://api.abso.dev"));
143230 assert.ok(tokenGoesTo("https://issues.abso.dev"));
Lines 233–240 at 318 (were 146–152 at 59)
146233
147234 it("are MCP tools", () => {
148235 const names = mcpTools().map((t) => t.name);
149− 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);
150238 assert.deepEqual(argvFor("ask", { args: ["alice", "Which login?"], issue: "3", review: true }), [
151239 "ask",
152240 "--issue=3",
Lines 272–315 at 318 (were 184–199 at 59)
184272 });
185273
186274 it("shows a search hit as the issue, then where it matched, without the match markers", () => {
187− 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+ };
188289 assert.deepEqual(
189− searchLines({ issue, where: "comment", comment: 40, snippet: "the \u0001network\u0002 drops mid-sync" }),
190− [' 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"'],
191298 );
192− assert.deepEqual(searchLines({ issue, where: "description", snippet: "Pages load late.", meaning: true }), [
193− ' 12 open "Sync is slow"',
194− ' by meaning: "Pages load late."',
195− ]);
196− 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+ );
197313 });
198314
199315 it("withdraw is one POST to the asker's own withdraw/<ask> route", async () => {
Lines 326–403 at 318 (were 210–222 at 59)
210326 const before = seen.length;
211327 const r = await main(["ack", "7", "on it after the deploy"], { cwd: fay, env: ENV(), write: () => {} });
212328 assert.equal(r.exit, 0, r.stdout + r.stderr);
213− assert.equal(r.stdout, 'Acknowledged ask 7. desk hears it; the ask stays open until abso answer 7 "...".\n');
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+ );
214333 const posts = seen.slice(before).filter((s) => s.startsWith("POST"));
215334 assert.deepEqual(posts.length, 1, posts.join("\n"));
216335 assert.match(posts[0]!, /^POST \/p\/issues\d+\/a\/fay\/ack\/7$/);
217336 assert.equal((await main(["ack"], { cwd: fay, env: ENV(), write: () => {} })).exit, 1);
218337 });
219338
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+ });
220401 it("an acknowledged ask reads as acknowledged, not answered, with the note under it", () => {
221402 const ask = {
222403 id: 7,
Lines 471–477 at 318 (were 290–296 at 59)
290471 r.out.trimEnd(),
291472 [
292473 `A dry run: nothing was written. Copying ${from} issue 12 into core would make:`,
293− ` "Sync is slow", done (description edited when copied)`,
474+ ` "Pull is slow", done (description edited when copied)`,
294475 " 2 comments (1 edited), 1 answered ask, labelled client",
295476 " not copied: comments 4; asks 2 (open asks, and what --clean left out)",
296477 "Run it again without --dry-run to copy it.",
MCP
compare on this site's /mcp
CLI
abso diff 59 318 client/test/issues.test.ts --json
JSON
/christopher/abso-core/compare/59..318?file=client%2Ftest%2Fissues.test.ts&format=json