{"draft":null,"from":22,"to":23,"files":[{"path":"client/test/issues.test.ts","added":115,"removed":2,"diff":"--- a/client/test/issues.test.ts\n+++ b/client/test/issues.test.ts\n@@ -12,7 +12,7 @@\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 { readConfig, readMachineServers } from \"../src/config.ts\";\n import { issuesServerFor, tokenGoesTo } from \"../src/core.ts\";\n import { searchLines } from \"../src/issues.ts\";\n import { main } from \"../src/main.ts\";\n@@ -26,13 +26,45 @@\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 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: \"Sync 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\tsend(500, { error: \"a stand-in\" });\n \t});\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@@ -166,3 +198,84 @@\n \t\tassert.match(posts[0]!, /^POST \\/p\\/issues\\d+\\/a\\/erin\\/withdraw\\/3$/);\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`  \"Sync 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":[]}