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. */ 38+ title: "Pull is slow", 42+ question: "Which way?", 45+ recommendation: null, 51+ ack: { at: 0, note: "ok, let me check" }, 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 }, 3158const dirs: string[] = []; Lines 78–84 at 318 (were 51–57 at 32)
5380 from: { project: body.from, issue: body.issue }, 54− title: "Sync is slow",
81+ title: "Pull is slow", 5582 edited: ["description"], 5784 closed: { how: "done" }, Lines 91–139 at 318 (were 64–71 at 32)
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) 98+ ask: { id: Number(ack[2]), by: "desk", of: ack[1], answer: null, ack: { at: Date.now(), note: "" } }, 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) { 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 }; 112+ id: Number(reply[2]), 116+ waitingOn: body.question ? "desk" : reply[1], 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 ?? "")) 129+ { ...threaded, id: 8, replies: [], answer: { by: "fay", words: "yes", at: 0 }, waitingOn: null }, 67132 send(500, { error: "a stand-in" }); 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}`; 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− );
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"); 190+ issues: { "https://staging.abso.example": "https://issues-staging.abso.example" }, 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); 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`]); 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-")); 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)
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 }), [ Lines 272–315 at 318 (were 177–192 at 32)
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, 278+ provenance: "unknown" as const, 283+ title: "Pull is slow", 284+ status: "open" as const, 287+ authorship: { title: unknownAuthorship }, 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"'],
294+ snippet: "the \u0001network\u0002 drops mid-sync", 295+ matchedAuthorship: unknownAuthorship, 297+ [' 12 open "Pull is slow"', ' in comment 40: "the network drops mid-sync"'], 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");
302+ where: "description", 303+ snippet: "Pages load late.", 305+ matchedAuthorship: unknownAuthorship, 307+ [' 12 open "Pull is slow"', ' by meaning: "Pages load late."'], 310+ searchLines({ issue, where: "title", snippet: "Pull is slow", matchedAuthorship: unknownAuthorship })[1], 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$/); 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); 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', 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); 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); 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?"], 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(" ")); 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); 373+ /^ {2}ask 7: desk, .* asks fay a question on issue 3 \("Pull is slow"\) \(2 replies; waiting on desk\): "Which way\?"$/m, 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); 380+ /^It waits on desk\. abso reply 7 "\.\.\." adds to it; abso answer 7 "\.\.\." answers and closes it\.$/m, 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); 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); 401+ it("an acknowledged ask reads as acknowledged, not answered, with the note under it", () => { 408+ question: "Which way?", 411+ recommendation: null, 417+ ack: { at: 0, note: "on it after the deploy" }, 425+ opened: { by: "desk", at: 0 }, 442+ } as unknown as IssuePage; 443+ const text = issuePage(page).join("\n"); 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"/, 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"); 202455describe("abso issue <N> --copy-to <project>", () => { Lines 471–477 at 318 (were 218–224 at 32)
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.",