{"draft":null,"from":2,"to":318,"files":[{"path":"client/test/issues.test.ts","added":410,"removed":13,"diff":"--- a/client/test/issues.test.ts\n+++ b/client/test/issues.test.ts\n@@ -12,8 +12,10 @@\n import { tmpdir } from \"node:os\";\n import { join } from \"node:path\";\n import { after, before, describe, it } from \"node:test\";\n-import { readMachineServers } from \"../src/config.ts\";\n-import { issuesServerFor, tokenGoesTo } from \"../src/core.ts\";\n+import { readConfig, readMachineServers } from \"../src/config.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 import { argvFor, mcpTools } from \"../src/mcp.ts\";\n import { type Fake, startFake } from \"./fake-server.ts\";\n@@ -25,14 +27,113 @@\n let issuesUrl: string;\n /** Every call the stand-in Issues server took. */\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 \tfake = await startFake(0, TOKEN);\n \tissues = createServer((req, res) => {\n \t\tseen.push(`${req.method} ${req.url}`);\n-\t\tres.writeHead(500, { \"content-type\": \"application/json\" }).end(JSON.stringify({ error: \"a stand-in\" }));\n+\t\tconst send = (status: number, body: unknown) =>\n+\t\t\tres.writeHead(status, { \"content-type\": \"application/json\" }).end(JSON.stringify(body));\n+\t\tif (req.method === \"POST\" && /\\/copy$/.test(req.url ?? \"\")) {\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 Record<string, unknown>;\n+\t\t\t\tcopies.push(body);\n+\t\t\t\t// Issue 403 stands for a live server refusing an agent's copy.\n+\t\t\t\tif (body.issue === 403 && body.dryRun !== true)\n+\t\t\t\t\treturn send(403, { error: \"copying an issue out of its project takes an owner of that project\" });\n+\t\t\t\tconst skipped = { comments: [4], asks: [2] };\n+\t\t\t\tif (body.dryRun === true)\n+\t\t\t\t\treturn send(200, {\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: \"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+\t\t\t\t\t\t\tcomments: [{ edited: false }, { edited: true }],\n+\t\t\t\t\t\t\tasks: [{ edited: false }],\n+\t\t\t\t\t\t\tskipped,\n+\t\t\t\t\t\t},\n+\t\t\t\t\t});\n+\t\t\t\tsend(200, { ok: true, id: 31, from: { project: body.from, issue: body.issue }, skipped });\n+\t\t\t});\n+\t\t\treturn;\n+\t\t}\n+\t\t// An ack answers with the ask, acknowledged and still open.\n+\t\tconst ack = /\\/a\\/([^/]+)\\/ack\\/(\\d+)$/.exec(req.url ?? \"\");\n+\t\tif (req.method === \"POST\" && ack)\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@@ -75,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; ~\\/\\.avcs\\/servers\\.json or AVCS_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@@ -97,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@@ -106,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\", \"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@@ -128,10 +256,279 @@\n \t\t\t[\"answer\", \"3\"],\n \t\t\t[\"issue\", \"1\", \"--comment\", \"a\", \"--drop\"],\n \t\t\t[\"issues\", \"extra\"],\n+\t\t\t[\"ask\", \"--withdraw\", \"x\"],\n+\t\t\t[\"ask\", \"--withdraw\", \"3\", \"alice\", \"q\"],\n+\t\t\t[\"ask\", \"--withdraw\", \"3\", \"--issue\", \"2\"],\n+\t\t\t[\"ask\", \"--withdraw\", \"3\", \"--task\"],\n+\t\t\t[\"ask\", \"alice\", \"q\", \"--note\", \"a note without --withdraw\"],\n+\t\t\t[\"search\"],\n+\t\t\t[\"search\", \"words\", \"--limit\", \"0\"],\n+\t\t\t[\"search\", \"words\", \"--limit\", \"51\"],\n \t\t]) {\n \t\t\tconst r = await avcs(erin, argv);\n \t\t\tassert.equal(r.exit, 1, `${argv.join(\" \")}: ${r.out}`);\n \t\t}\n \t\tassert.equal(seen.length, before);\n \t});\n+\n+\tit(\"shows a search hit as the issue, then where it matched, without the match markers\", () => {\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({\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(\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+\t\tconst erin = await folder(\"erin\");\n+\t\tconst before = seen.length;\n+\t\tawait avcs(erin, [\"ask\", \"--withdraw\", \"#3\", \"--note\", \"overtaken by later decisions\"]);\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\\/erin\\/withdraw\\/3$/);\n+\t});\n+\n+\tit(\"ack is one POST to the one asked's ack/<ask> route, and says the ask stays open\", async () => {\n+\t\tconst fay = await folder(\"fay\");\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(\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+\t\t\tissue: 3,\n+\t\t\tby: \"desk\",\n+\t\t\tof: \"fay\",\n+\t\t\tkind: \"question\",\n+\t\t\tquestion: \"Which way?\",\n+\t\t\treview: false,\n+\t\t\tdue: null,\n+\t\t\trecommendation: null,\n+\t\t\toptions: [],\n+\t\t\tblocks: [],\n+\t\t\tat: 0,\n+\t\t\tanswer: null,\n+\t\t\tseen: 0,\n+\t\t\tack: { at: 0, note: \"on it after the deploy\" },\n+\t\t};\n+\t\tconst page = {\n+\t\t\tissue: {\n+\t\t\t\tid: 3,\n+\t\t\t\ttitle: \"t\",\n+\t\t\t\tstatus: \"blocked\",\n+\t\t\t\tparent: null,\n+\t\t\t\topened: { by: \"desk\", at: 0 },\n+\t\t\t\tagent: null,\n+\t\t\t\tagents: [],\n+\t\t\t\tblockedBy: [],\n+\t\t\t\tlabels: [],\n+\t\t\t\tversions: [],\n+\t\t\t\twaitingOn: [\"fay\"],\n+\t\t\t\tclosed: null,\n+\t\t\t\tdescription: \"\",\n+\t\t\t\tlines: null,\n+\t\t\t\twatchers: [],\n+\t\t\t},\n+\t\t\tcomments: [],\n+\t\t\tedits: [],\n+\t\t\tasks: [ask],\n+\t\t\tclaims: [],\n+\t\t\tchildren: [],\n+\t\t} as unknown as IssuePage;\n+\t\tconst text = issuePage(page).join(\"\\n\");\n+\t\tassert.match(\n+\t\t\ttext,\n+\t\t\t/\\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\"/,\n+\t\t);\n+\t\tassert.doesNotMatch(text, /answer:/);\n+\t\tconst answered = { ...ask, answer: { by: \"fay\", words: \"This way\", at: 0 } };\n+\t\tconst later = issuePage({ ...page, asks: [answered] } as unknown as IssuePage).join(\"\\n\");\n+\t\tassert.doesNotMatch(later, /acknowledged/, \"an answer replaces the ack\");\n+\t});\n });\n+\n+describe(\"abso issue <N> --copy-to <project>\", () => {\n+\tconst text = async (cwd: string, argv: string[]) => {\n+\t\tconst r = await main(argv, { cwd, env: ENV(), write: () => {} });\n+\t\treturn { exit: r.exit, out: r.stdout + r.stderr };\n+\t};\n+\n+\tit(\"a dry run asks the other project's copy route for the plan, and says nothing was written\", async () => {\n+\t\tconst gil = await folder(\"gil\");\n+\t\tconst before = seen.length;\n+\t\tconst r = await text(gil, [\"issue\", \"12\", \"--copy-to\", \"core\", \"--dry-run\"]);\n+\t\tassert.equal(r.exit, 0, r.out);\n+\t\tassert.deepEqual(seen.slice(before), [\"POST /p/core/a/gil/copy\"]);\n+\t\tconst from = (copies.at(-1) as { from: string }).from;\n+\t\tassert.match(from, /^issues\\d+$/);\n+\t\tassert.deepEqual(copies.at(-1), { from, issue: 12, dryRun: true });\n+\t\tassert.equal(\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`  \"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.\",\n+\t\t\t].join(\"\\n\"),\n+\t\t);\n+\t});\n+\n+\tit(\"copies with the cleaned texts --clean gives, by source id\", async () => {\n+\t\tconst gil = await folder(\"gil\");\n+\t\twriteFileSync(\n+\t\t\tjoin(gil, \"clean.json\"),\n+\t\t\tJSON.stringify({ description: \"Cleaned.\", comments: [{ id: 1 }, { id: 3, text: \"Cleaned too.\" }] }),\n+\t\t);\n+\t\tconst r = await text(gil, [\"issue\", \"12\", \"--copy-to\", \"core\", \"--clean\", \"clean.json\"]);\n+\t\tassert.equal(r.exit, 0, r.out);\n+\t\tconst from = (copies.at(-1) as { from: string }).from;\n+\t\tassert.deepEqual(copies.at(-1), {\n+\t\t\tdescription: \"Cleaned.\",\n+\t\t\tcomments: [{ id: 1 }, { id: 3, text: \"Cleaned too.\" }],\n+\t\t\tfrom,\n+\t\t\tissue: 12,\n+\t\t});\n+\t\tassert.match(\n+\t\t\tr.out,\n+\t\t\tnew RegExp(`^Copied ${from} issue 12 to core issue 31\\\\. Its comments and asks keep their authors`),\n+\t\t);\n+\t});\n+\n+\tit(\"says a dry run still works when the server refuses the copy\", async () => {\n+\t\tconst gil = await folder(\"gil\");\n+\t\tconst r = await text(gil, [\"issue\", \"403\", \"--copy-to\", \"core\"]);\n+\t\tassert.equal(r.exit, 1, r.out);\n+\t\tassert.match(r.out, /takes an owner of that project\\. --dry-run still shows what would go\\./);\n+\t});\n+\n+\tit(\"refuses mistakes before any call\", async () => {\n+\t\tconst gil = await folder(\"gil\");\n+\t\twriteFileSync(join(gil, \"bad.json\"), JSON.stringify({ from: \"elsewhere\" }));\n+\t\tconst before = seen.length;\n+\t\tfor (const [argv, why] of [\n+\t\t\t[[\"issue\", \"12\", \"--copy-to\", \"core\", \"--comment\", \"x\"], /--copy-to goes alone .* not with --comment/],\n+\t\t\t[[\"issue\", \"12\", \"--dry-run\"], /--clean and --dry-run go with --copy-to <project>/],\n+\t\t\t[[\"issue\", \"12\", \"--copy-to\", \"core\", \"--clean\", \"nope.json\"], /--clean nope\\.json: no such file/],\n+\t\t\t[\n+\t\t\t\t[\"issue\", \"12\", \"--copy-to\", \"core\", \"--clean\", \"bad.json\"],\n+\t\t\t\t/from isn't one of title, description, comments, asks/,\n+\t\t\t],\n+\t\t] as const) {\n+\t\t\tconst r = await text(gil, [...argv]);\n+\t\t\tassert.notEqual(r.exit, 0, argv.join(\" \"));\n+\t\t\tassert.match(r.out, why);\n+\t\t}\n+\t\tconst { project } = readConfig(gil);\n+\t\tassert.match(\n+\t\t\t(await text(gil, [\"issue\", \"12\", \"--copy-to\", project])).out,\n+\t\t\t/issue 12 is already in issues\\d+; --copy-to names another project/,\n+\t\t);\n+\t\tassert.equal(seen.length, before, \"nothing reached the Issues server\");\n+\t});\n+});"}],"unmatched":[]}