{"draft":null,"from":71,"to":318,"files":[{"path":"client/test/issues.test.ts","added":203,"removed":22,"diff":"--- a/client/test/issues.test.ts\n+++ b/client/test/issues.test.ts\n@@ -13,7 +13,7 @@\n import { join } from \"node:path\";\n import { after, before, describe, it } from \"node:test\";\n import { readConfig, readMachineServers } from \"../src/config.ts\";\n-import { issuesServerFor, tokenGoesTo } from \"../src/core.ts\";\n+import { issuesServerFor, tokenGoesTo, tokenGoesToIssues } from \"../src/core.ts\";\n import { issuePage, searchLines } from \"../src/issues.ts\";\n import type { IssuePage } from \"../src/issues-wire.ts\";\n import { main } from \"../src/main.ts\";\n@@ -29,6 +29,32 @@\n const seen: string[] = [];\n /** The bodies of the copy requests it took. */\n const copies: Record<string, unknown>[] = [];\n+/** The bodies of the replies it took. */\n+const replies: { text: string; question?: boolean }[] = [];\n+/** An open ask of fay's from desk with a thread: fay's ack, then a question back, so it waits on desk. */\n+const threaded = {\n+\tid: 7,\n+\tissue: 3,\n+\ttitle: \"Pull is slow\",\n+\tby: \"desk\",\n+\tof: \"fay\",\n+\tkind: \"question\",\n+\tquestion: \"Which way?\",\n+\treview: false,\n+\tdue: null,\n+\trecommendation: null,\n+\toptions: [],\n+\tblocks: [],\n+\tat: 0,\n+\tanswer: null,\n+\tseen: 0,\n+\tack: { at: 0, note: \"ok, let me check\" },\n+\treplies: [\n+\t\t{ id: 1, by: \"fay\", text: \"ok, let me check\", at: 0 },\n+\t\t{ id: 2, by: \"fay\", text: \"staging or live?\\nlive is 906\", at: 0, question: true },\n+\t],\n+\twaitingOn: \"desk\",\n+};\n const dirs: string[] = [];\n \n before(async () => {\n@@ -52,7 +78,7 @@\n \t\t\t\t\t\tdryRun: true,\n \t\t\t\t\t\tplan: {\n \t\t\t\t\t\t\tfrom: { project: body.from, issue: body.issue },\n-\t\t\t\t\t\t\ttitle: \"Sync is slow\",\n+\t\t\t\t\t\t\ttitle: \"Pull is slow\",\n \t\t\t\t\t\t\tedited: [\"description\"],\n \t\t\t\t\t\t\tlabels: [\"client\"],\n \t\t\t\t\t\t\tclosed: { how: \"done\" },\n@@ -71,8 +97,43 @@\n \t\t\treturn send(200, {\n \t\t\t\task: { id: Number(ack[2]), by: \"desk\", of: ack[1], answer: null, ack: { at: Date.now(), note: \"\" } },\n \t\t\t});\n+\t\t// Ask 404 stands for a server from before ask threads: neither route is there.\n+\t\tif (/\\/(ask|reply)\\/404$/.test(req.url ?? \"\")) return send(404, { error: \"no such issues route\" });\n+\t\t// A reply answers with the ask; from the one asked, a question makes it wait on the asker.\n+\t\tconst reply = /\\/a\\/([^/]+)\\/reply\\/(\\d+)$/.exec(req.url ?? \"\");\n+\t\tif (req.method === \"POST\" && reply) {\n+\t\t\tlet raw = \"\";\n+\t\t\treq.on(\"data\", (c: Buffer) => (raw += c.toString(\"utf8\")));\n+\t\t\treq.on(\"end\", () => {\n+\t\t\t\tconst body = JSON.parse(raw) as { text: string; question?: boolean };\n+\t\t\t\treplies.push(body);\n+\t\t\t\tsend(200, {\n+\t\t\t\t\task: {\n+\t\t\t\t\t\tid: Number(reply[2]),\n+\t\t\t\t\t\tby: \"desk\",\n+\t\t\t\t\t\tof: reply[1],\n+\t\t\t\t\t\tanswer: null,\n+\t\t\t\t\t\twaitingOn: body.question ? \"desk\" : reply[1],\n+\t\t\t\t\t},\n+\t\t\t\t});\n+\t\t\t});\n+\t\t\treturn;\n+\t\t}\n+\t\t// One ask with its thread, and the asks an agent sent.\n+\t\tconst one = /\\/ask\\/(\\d+)$/.exec(req.url ?? \"\");\n+\t\tif (req.method === \"GET\" && one) return send(200, { ask: { ...threaded, id: Number(one[1]) } });\n+\t\tif (req.method === \"GET\" && /\\/a\\/[^/]+\\/asked$/.test(req.url ?? \"\"))\n+\t\t\treturn send(200, {\n+\t\t\t\tasks: [\n+\t\t\t\t\tthreaded,\n+\t\t\t\t\t{ ...threaded, id: 8, replies: [], answer: { by: \"fay\", words: \"yes\", at: 0 }, waitingOn: null },\n+\t\t\t\t],\n+\t\t\t});\n \t\tsend(500, { error: \"a stand-in\" });\n \t});\n+\t// As fake-server.ts: never close an idle kept-alive connection, or under load the client can reuse one as it closes\n+\t// and fail with ECONNRESET (abso 410).\n+\tissues.keepAliveTimeout = 0;\n \tawait new Promise<void>((ok) => issues.listen(0, \"127.0.0.1\", ok));\n \tissuesUrl = `http://127.0.0.1:${(issues.address() as AddressInfo).port}`;\n });\n@@ -115,16 +176,42 @@\n \t\tassert.equal(r.exit, 1, r.out);\n \t\tassert.match(r.out, /sends your token only to its own servers and this machine/);\n \t\tassert.equal(seen.length, before);\n-\t\t// A server with no Issues Worker beside it, and none named.\n-\t\tconst { AVCS_ISSUES_SERVER: _, ...without } = ENV();\n-\t\tconst none = await avcs(dave, [\"waiting\"], without);\n-\t\tassert.notEqual(none.exit, 0);\n-\t\tassert.match(\n-\t\t\tnone.out,\n-\t\t\t/has no Issues Worker beside it that abso knows; ~\\/\\.abso\\/servers\\.json or ABSO_ISSUES_SERVER names one/,\n-\t\t);\n \t});\n \n+\tit(\"with no Issues Worker named, uses the server's own /issues, as the open server keeps them\", () => {\n+\t\tassert.equal(issuesServerFor(\"https://abso.example\"), \"https://abso.example/issues\");\n+\t\tassert.equal(issuesServerFor(\"https://Abso.Example/\"), \"https://abso.example/issues\");\n+\t\tassert.equal(issuesServerFor(\"http://localhost:8787\"), \"http://localhost:8787/issues\");\n+\t\tassert.equal(issuesServerFor(\"not a server\"), undefined);\n+\t\t// abso's hosted server keeps its own Issues Worker, and servers.json still comes first.\n+\t\tassert.equal(issuesServerFor(\"https://api.abso.dev\"), \"https://issues.abso.dev\");\n+\t\tconst machine = {\n+\t\t\ttrusted: [],\n+\t\t\tissues: { \"https://staging.abso.example\": \"https://issues-staging.abso.example\" },\n+\t\t};\n+\t\tassert.equal(issuesServerFor(\"https://staging.abso.example\", machine), \"https://issues-staging.abso.example\");\n+\t\t// The token goes to <server>/issues exactly where it goes to <server>.\n+\t\tassert.ok(tokenGoesToIssues(\"https://api.abso.dev/issues\"));\n+\t\tassert.ok(tokenGoesToIssues(\"http://localhost:8787/issues\"));\n+\t\tassert.ok(tokenGoesToIssues(\"https://mine.example/issues\", \"https://mine.example\"));\n+\t\tassert.equal(tokenGoesToIssues(\"https://evil.example/issues\"), false);\n+\t\tassert.equal(tokenGoesToIssues(\"https://api.abso.dev@evil.example/issues\"), false);\n+\t\tassert.equal(tokenGoesToIssues(\"https://api.abso.dev/issues?x=1\"), false);\n+\t\tassert.equal(tokenGoesToIssues(\"http://mine.example/issues\", \"http://mine.example\"), false, \"plain http only here\");\n+\t\t// The server itself still takes no path.\n+\t\tassert.equal(tokenGoesTo(\"https://api.abso.dev/issues\"), false);\n+\t});\n+\n+\tit(\"calls <issues server>/p/<project>/... when the Issues Worker is at a path\", async () => {\n+\t\tconst fay = await folder(\"fay\");\n+\t\tconst before = seen.length;\n+\t\tconst env = { ...ENV(), AVCS_ISSUES_SERVER: `${issuesUrl}/issues` };\n+\t\tconst r = await main([\"ask\", \"7\"], { cwd: fay, env, write: () => {} });\n+\t\tassert.equal(r.exit, 0, r.stdout + r.stderr);\n+\t\tconst { project } = readConfig(fay);\n+\t\tassert.deepEqual(seen.slice(before), [`GET /issues/p/${project}/ask/7`]);\n+\t});\n+\n \tit(\"finds a server's Issues Worker in this machine's servers.json, and may send it the token\", async () => {\n \t\tconst dir = mkdtempSync(join(tmpdir(), \"abso-servers-\"));\n \t\tdirs.push(dir);\n@@ -137,7 +224,7 @@\n \t\tassert.ok(seen.length > before, \"the call went to the Issues Worker servers.json names\");\n \t\tconst machine = readMachineServers({ AVCS_SERVERS_FILE: file });\n \t\tassert.equal(issuesServerFor(fake.url, machine), issuesUrl);\n-\t\tassert.equal(issuesServerFor(\"https://abso.example\", machine), undefined);\n+\t\tassert.equal(issuesServerFor(\"https://abso.example\", machine), \"https://abso.example/issues\");\n \t\t// abso's own server and its Issues Worker are built in.\n \t\tassert.ok(tokenGoesTo(\"https://api.abso.dev\"));\n \t\tassert.ok(tokenGoesTo(\"https://issues.abso.dev\"));\n@@ -146,7 +233,8 @@\n \n \tit(\"are MCP tools\", () => {\n \t\tconst names = mcpTools().map((t) => t.name);\n-\t\tfor (const n of [\"issues\", \"issue\", \"search\", \"ask\", \"waiting\", \"answer\"]) assert.ok(names.includes(n), n);\n+\t\tfor (const n of [\"issues\", \"issue\", \"search\", \"ask\", \"waiting\", \"answer\", \"ack\", \"reply\"])\n+\t\t\tassert.ok(names.includes(n), n);\n \t\tassert.deepEqual(argvFor(\"ask\", { args: [\"alice\", \"Which login?\"], issue: \"3\", review: true }), [\n \t\t\t\"ask\",\n \t\t\t\"--issue=3\",\n@@ -184,16 +272,44 @@\n \t});\n \n \tit(\"shows a search hit as the issue, then where it matched, without the match markers\", () => {\n-\t\tconst issue = { id: 12, title: \"Sync is slow\", status: \"open\" as const, updated: 0, labels: [] };\n+\t\tconst unknownAuthorship = {\n+\t\t\tkind: \"unknown\" as const,\n+\t\t\tactor: null,\n+\t\t\tprovenance: \"unknown\" as const,\n+\t\t\tauthorField: null,\n+\t\t};\n+\t\tconst issue = {\n+\t\t\tid: 12,\n+\t\t\ttitle: \"Pull is slow\",\n+\t\t\tstatus: \"open\" as const,\n+\t\t\tupdated: 0,\n+\t\t\tlabels: [],\n+\t\t\tauthorship: { title: unknownAuthorship },\n+\t\t};\n \t\tassert.deepEqual(\n-\t\t\tsearchLines({ issue, where: \"comment\", comment: 40, snippet: \"the \\u0001network\\u0002 drops mid-sync\" }),\n-\t\t\t['   12  open         \"Sync is slow\"', '       in comment 40: \"the network drops mid-sync\"'],\n+\t\t\tsearchLines({\n+\t\t\t\tissue,\n+\t\t\t\twhere: \"comment\",\n+\t\t\t\tcomment: 40,\n+\t\t\t\tsnippet: \"the \\u0001network\\u0002 drops mid-sync\",\n+\t\t\t\tmatchedAuthorship: unknownAuthorship,\n+\t\t\t}),\n+\t\t\t['   12  open         \"Pull is slow\"', '       in comment 40: \"the network drops mid-sync\"'],\n \t\t);\n-\t\tassert.deepEqual(searchLines({ issue, where: \"description\", snippet: \"Pages load late.\", meaning: true }), [\n-\t\t\t'   12  open         \"Sync is slow\"',\n-\t\t\t'       by meaning: \"Pages load late.\"',\n-\t\t]);\n-\t\tassert.deepEqual(searchLines({ issue, where: \"title\", snippet: \"Sync is slow\" })[1], \"       in the title\");\n+\t\tassert.deepEqual(\n+\t\t\tsearchLines({\n+\t\t\t\tissue,\n+\t\t\t\twhere: \"description\",\n+\t\t\t\tsnippet: \"Pages load late.\",\n+\t\t\t\tmeaning: true,\n+\t\t\t\tmatchedAuthorship: unknownAuthorship,\n+\t\t\t}),\n+\t\t\t['   12  open         \"Pull is slow\"', '       by meaning: \"Pages load late.\"'],\n+\t\t);\n+\t\tassert.deepEqual(\n+\t\t\tsearchLines({ issue, where: \"title\", snippet: \"Pull is slow\", matchedAuthorship: unknownAuthorship })[1],\n+\t\t\t\"       in the title\",\n+\t\t);\n \t});\n \n \tit(\"withdraw is one POST to the asker's own withdraw/<ask> route\", async () => {\n@@ -210,13 +326,78 @@\n \t\tconst before = seen.length;\n \t\tconst r = await main([\"ack\", \"7\", \"on it after the deploy\"], { cwd: fay, env: ENV(), write: () => {} });\n \t\tassert.equal(r.exit, 0, r.stdout + r.stderr);\n-\t\tassert.equal(r.stdout, 'Acknowledged ask 7. desk hears it; the ask stays open until abso answer 7 \"...\".\\n');\n+\t\tassert.equal(\n+\t\t\tr.stdout,\n+\t\t\t'Acknowledged ask 7. desk hears it; abso reply 7 \"...\" adds more as you go, and the ask stays open until abso answer 7 \"...\".\\n',\n+\t\t);\n \t\tconst posts = seen.slice(before).filter((s) => s.startsWith(\"POST\"));\n \t\tassert.deepEqual(posts.length, 1, posts.join(\"\\n\"));\n \t\tassert.match(posts[0]!, /^POST \\/p\\/issues\\d+\\/a\\/fay\\/ack\\/7$/);\n \t\tassert.equal((await main([\"ack\"], { cwd: fay, env: ENV(), write: () => {} })).exit, 1);\n \t});\n \n+\tit(\"reply is one POST to reply/<ask> with the words, and says whose turn it is\", async () => {\n+\t\tconst fay = await folder(\"fay\");\n+\t\tconst before = seen.length;\n+\t\tconst r = await main([\"reply\", \"7\", \"staging or live?\", \"--question\"], { cwd: fay, env: ENV(), write: () => {} });\n+\t\tassert.equal(r.exit, 0, r.stdout + r.stderr);\n+\t\tconst posts = seen.slice(before).filter((s) => s.startsWith(\"POST\"));\n+\t\tassert.equal(posts.length, 1, posts.join(\"\\n\"));\n+\t\tassert.match(posts[0]!, /^POST \\/p\\/issues\\d+\\/a\\/fay\\/reply\\/7$/);\n+\t\tassert.deepEqual(replies.at(-1), { text: \"staging or live?\", question: true });\n+\t\tassert.equal(r.stdout, \"Replied on ask 7. desk hears it. It waits on desk.\\n\");\n+\t\tassert.equal((await main([\"reply\", \"7\"], { cwd: fay, env: ENV(), write: () => {} })).exit, 1);\n+\t});\n+\n+\tit(\"names a server from before ask threads instead of a bare 404\", async () => {\n+\t\tconst fay = await folder(\"fay\");\n+\t\tfor (const argv of [\n+\t\t\t[\"reply\", \"404\", \"still there?\"],\n+\t\t\t[\"ask\", \"404\"],\n+\t\t]) {\n+\t\t\tconst r = await main(argv, { cwd: fay, env: ENV(), write: () => {} });\n+\t\t\tassert.equal(r.exit, 1, argv.join(\" \"));\n+\t\t\tassert.match(r.stderr, /doesn't have ask threads yet/, argv.join(\" \"));\n+\t\t\tassert.doesNotMatch(r.stderr, /no such issues route/, argv.join(\" \"));\n+\t\t}\n+\t});\n+\n+\tit(\"ask <N> reads one ask with its whole thread, oldest first, and whose turn it is\", async () => {\n+\t\tconst fay = await folder(\"fay\");\n+\t\tconst before = seen.length;\n+\t\tconst r = await main([\"ask\", \"7\"], { cwd: fay, env: ENV(), write: () => {} });\n+\t\tassert.equal(r.exit, 0, r.stdout + r.stderr);\n+\t\tassert.match(seen.slice(before).join(\"\\n\"), /^GET \\/p\\/issues\\d+\\/ask\\/7$/m);\n+\t\tassert.match(\n+\t\t\tr.stdout,\n+\t\t\t/^ {2}ask 7: desk, .* asks fay a question on issue 3 \\(\"Pull is slow\"\\) \\(2 replies; waiting on desk\\): \"Which way\\?\"$/m,\n+\t\t);\n+\t\tconst ack = r.stdout.indexOf('    fay, Jan 1 1970 00:00 UTC: \"ok, let me check\"');\n+\t\tconst back = r.stdout.indexOf('    fay, Jan 1 1970 00:00 UTC, a question: \"staging or live?\\\\nlive is 906\"');\n+\t\tassert.ok(ack > 0 && back > ack, r.stdout);\n+\t\tassert.match(\n+\t\t\tr.stdout,\n+\t\t\t/^It waits on desk\\. abso reply 7 \"\\.\\.\\.\" adds to it; abso answer 7 \"\\.\\.\\.\" answers and closes it\\.$/m,\n+\t\t);\n+\t\t// The asker reads it as their turn, and can't answer it.\n+\t\tconst desk = await folder(\"desk\");\n+\t\tconst d = await main([\"ask\", \"7\"], { cwd: desk, env: ENV(), write: () => {} });\n+\t\tassert.match(d.stdout, /^It waits on you\\. abso reply 7 \"\\.\\.\\.\" adds to it\\.$/m);\n+\t});\n+\n+\tit(\"waiting --asked lists the asks you sent, open first, then the latest answered\", async () => {\n+\t\tconst fay = await folder(\"fay\");\n+\t\tconst before = seen.length;\n+\t\tconst r = await main([\"waiting\", \"--asked\"], { cwd: fay, env: ENV(), write: () => {} });\n+\t\tassert.equal(r.exit, 0, r.stdout + r.stderr);\n+\t\tassert.match(seen.slice(before).join(\"\\n\"), /^GET \\/p\\/issues\\d+\\/a\\/fay\\/asked$/m);\n+\t\tassert.match(r.stdout, /^1 open ask you sent:$/m);\n+\t\tassert.match(r.stdout, /^ {4}last: fay, .*, a question: \"staging or live\\? \\.\\.\\.\"$/m);\n+\t\tassert.ok(r.stdout.indexOf(\"ask 7:\") < r.stdout.indexOf(\"The latest answered:\"), r.stdout);\n+\t\tassert.ok(r.stdout.indexOf(\"The latest answered:\") < r.stdout.indexOf(\"ask 8:\"), r.stdout);\n+\t\tassert.match(r.stdout, /^ {4}answer: \"yes\"$/m);\n+\t});\n+\n \tit(\"an acknowledged ask reads as acknowledged, not answered, with the note under it\", () => {\n \t\tconst ask = {\n \t\t\tid: 7,\n@@ -290,7 +471,7 @@\n \t\t\tr.out.trimEnd(),\n \t\t\t[\n \t\t\t\t`A dry run: nothing was written. Copying ${from} issue 12 into core would make:`,\n-\t\t\t\t`  \"Sync is slow\", done (description edited when copied)`,\n+\t\t\t\t`  \"Pull is slow\", done (description edited when copied)`,\n \t\t\t\t\"  2 comments (1 edited), 1 answered ask, labelled client\",\n \t\t\t\t\"  not copied: comments 4; asks 2 (open asks, and what --clean left out)\",\n \t\t\t\t\"Run it again without --dry-run to copy it.\","}],"unmatched":[]}