{"draft":null,"from":34,"to":35,"files":[{"path":"client/test/attach.test.ts","added":114,"removed":0,"diff":"--- a/client/test/attach.test.ts\n+++ b/client/test/attach.test.ts\n@@ -43,6 +43,32 @@\n \t\t\t\t});\n \t\t\tif (req.url!.endsWith(\"/issue\")) return json({ id: 7 });\n \t\t\tif (/\\/issue\\/\\d+\\/comment$/.test(req.url!)) return json({ id: 3 });\n+\t\t\t// An older Issues server keeps no files on asks: it answers without them (project \"keepless\").\n+\t\t\tconst older = req.url!.includes(\"/p/keepless/\");\n+\t\t\tif (req.url!.endsWith(\"/ask\")) {\n+\t\t\t\tconst sent = (JSON.parse(body.toString()) as { attachments?: string[] }).attachments;\n+\t\t\t\treturn json({ id: 9, ...(sent && !older ? { attachments: sent } : {}) });\n+\t\t\t}\n+\t\t\tif (/\\/answer\\/\\d+$/.test(req.url!)) {\n+\t\t\t\tconst sent = (JSON.parse(body.toString()) as { attachments?: string[] }).attachments ?? [];\n+\t\t\t\tconst files = older ? [] : sent.map((id) => ({ id, name: \"x\", type: \"image/png\", size: 1 }));\n+\t\t\t\treturn json({ ask: { by: \"bob\", answer: { by: \"ann\", words: \"w\", at: 0, attachments: files } } });\n+\t\t\t}\n+\t\t\t// Issue 9's ask carries a file on its question and one on its answer.\n+\t\t\tif (req.method === \"GET\" && /\\/issue\\/9$/.test(req.url!))\n+\t\t\t\treturn json({\n+\t\t\t\t\tissue: { id: 9 },\n+\t\t\t\t\tcomments: [],\n+\t\t\t\t\tedits: [],\n+\t\t\t\t\tasks: [\n+\t\t\t\t\t\t{\n+\t\t\t\t\t\t\tattachments: [{ id: \"a00000000000d\", name: \"question.png\", type: \"image/png\", size: 13 }],\n+\t\t\t\t\t\t\tanswer: { attachments: [{ id: \"a00000000000e\", name: \"answer.png\", type: \"image/png\", size: 13 }] },\n+\t\t\t\t\t\t},\n+\t\t\t\t\t],\n+\t\t\t\t\tclaims: [],\n+\t\t\t\t\tchildren: [],\n+\t\t\t\t});\n \t\t\t// Issue 8 carries an svg-drawn image on itself and again on a comment, plus one more on the comment.\n \t\t\tconst logo = { id: \"a00000000000b\", name: \"../shot one.png\", type: \"image/png\", size: 13 };\n \t\t\tif (req.method === \"GET\" && /\\/issue\\/8$/.test(req.url!))\n@@ -179,6 +205,65 @@\n \t\tassert.match(mixed.out, /--save-attachments goes alone/);\n \t});\n \n+\tit(\"goes on an ask and on an answer, and not on a withdrawal\", async () => {\n+\t\tconst dir = await folder();\n+\t\tlet from = seen.length;\n+\t\tconst asked = await avcs(dir, [\n+\t\t\t\"ask\",\n+\t\t\t\"bob\",\n+\t\t\t\"Which looks right?\",\n+\t\t\t\"--issue\",\n+\t\t\t\"7\",\n+\t\t\t\"--attach\",\n+\t\t\t\"shot.png,after.png\",\n+\t\t]);\n+\t\tassert.equal(asked.exit, 0, asked.out);\n+\t\tassert.deepEqual(\n+\t\t\tseen.slice(from).map((c) => `${c.method} ${c.url.replace(/^\\/p\\/[^/]+/, \"\")}`),\n+\t\t\t[\"POST /a/ann/attachments\", \"POST /a/ann/attachments\", \"POST /a/ann/ask\"],\n+\t\t);\n+\t\tconst ask = JSON.parse(seen.at(-1)!.body.toString()) as { question: string; attachments: string[] };\n+\t\tassert.equal(ask.question, \"Which looks right?\");\n+\t\tassert.equal(ask.attachments.length, 2);\n+\t\tassert.deepEqual((asked.json as { attachments: string[] }).attachments, ask.attachments);\n+\t\tfrom = seen.length;\n+\t\tconst answered = await avcs(dir, [\"answer\", \"9\", \"This one\", \"--attach\", \"after.png\"]);\n+\t\tassert.equal(answered.exit, 0, answered.out);\n+\t\tconst answer = JSON.parse(seen.at(-1)!.body.toString()) as { words: string; attachments: string[] };\n+\t\tassert.equal(answer.words, \"This one\");\n+\t\tassert.equal(answer.attachments.length, 1);\n+\t\tassert.equal(seen.length - from, 2);\n+\t\tfrom = seen.length;\n+\t\tconst withdrawn = await avcs(dir, [\"ask\", \"--withdraw\", \"9\", \"--attach\", \"shot.png\"]);\n+\t\tassert.equal(withdrawn.exit, 1);\n+\t\tassert.equal(seen.length, from, \"nothing was sent\");\n+\t});\n+\n+\tit(\"says so when an older Issues server keeps an ask's words but not its files\", async () => {\n+\t\tconst dir = mkdtempSync(join(tmpdir(), \"abso-attach-\"));\n+\t\tdirs.push(dir);\n+\t\tconst init = await avcs(dir, [\"init\", \"--server\", fake.url, \"--project\", \"keepless\", \"--agent\", \"ann\"]);\n+\t\tassert.equal(init.exit, 0, init.out);\n+\t\twriteFileSync(join(dir, \"shot.png\"), Buffer.from([0x89, 0x50, 0x4e, 0x47, 1]));\n+\t\tconst asked = await avcs(dir, [\"ask\", \"bob\", \"Which?\", \"--attach\", \"shot.png\"]);\n+\t\tassert.equal(asked.exit, 0, asked.out);\n+\t\tassert.match(asked.out, /didn't keep the file on ask 9: it is older than this client/);\n+\t\tconst answered = await avcs(dir, [\"answer\", \"9\", \"This\", \"--attach\", \"shot.png\"]);\n+\t\tassert.match(answered.out, /didn't keep the file on your answer to ask 9/);\n+\t\t// A server that keeps them says nothing of the kind.\n+\t\tconst kept = await avcs(await folder(), [\"ask\", \"bob\", \"Which?\", \"--attach\", \"shot.png\"]);\n+\t\tassert.doesNotMatch(kept.out, /didn't keep/);\n+\t});\n+\n+\tit(\"--save-attachments takes the files on an issue's asks and answers too\", async () => {\n+\t\tconst dir = await folder();\n+\t\tconst out = mkdtempSync(join(tmpdir(), \"abso-saved-\"));\n+\t\tdirs.push(out);\n+\t\tconst r = await avcs(dir, [\"issue\", \"9\", \"--save-attachments\", out]);\n+\t\tassert.equal(r.exit, 0, r.out);\n+\t\tassert.deepEqual(readdirSync(out).sort(), [\"a00000000000d-question.png\", \"a00000000000e-answer.png\"]);\n+\t});\n+\n \tit(\"an issue's page lists its attachments and each comment's, with links\", () => {\n \t\tconst page = {\n \t\t\tissue: {\n@@ -238,5 +323,34 @@\n \t\t\ttext,\n \t\t\t/\\n {4}attached a0000000000aa: \"logo.png\", 4 KB, \\S+\\/a0000000000aa\\n {6}drawn from \"logo.svg\", 512 B, https:\\/\\/issues.example\\/p\\/x\\/attachments\\/a0000000000aa\\/source/,\n \t\t);\n+\t\t// An ask lists its question's files under it, and its answer's under the answer.\n+\t\tconst file = (id: string, name: string) => ({ id, name, type: \"image/png\", size: 1024 });\n+\t\tconst asked = {\n+\t\t\t...page,\n+\t\t\tasks: [\n+\t\t\t\t{\n+\t\t\t\t\tid: 4,\n+\t\t\t\t\tissue: 7,\n+\t\t\t\t\tby: \"ann\",\n+\t\t\t\t\tof: \"bob\",\n+\t\t\t\t\tkind: \"question\",\n+\t\t\t\t\tquestion: \"Which?\",\n+\t\t\t\t\tattachments: [file(\"a00000000000d\", \"a.png\")],\n+\t\t\t\t\treview: false,\n+\t\t\t\t\tdue: null,\n+\t\t\t\t\trecommendation: null,\n+\t\t\t\t\toptions: [],\n+\t\t\t\t\tblocks: [],\n+\t\t\t\t\tat: 0,\n+\t\t\t\t\tanswer: { by: \"bob\", words: \"This\", at: 0, attachments: [file(\"a00000000000e\", \"b.png\")] },\n+\t\t\t\t\tseen: null,\n+\t\t\t\t},\n+\t\t\t],\n+\t\t} as unknown as IssuePage;\n+\t\tconst asks = issuePage(asked, { attachmentUrl: (id: string) => `https://i.example/${id}` }).join(\"\\n\");\n+\t\tassert.match(\n+\t\t\tasks,\n+\t\t\t/ask 4: .*\"Which\\?\"\\n {4}attached a00000000000d: \"a.png\", 1 KB, https:\\/\\/i.example\\/a00000000000d\\n {4}answer: \"This\"\\n {6}attached a00000000000e: \"b.png\", 1 KB/,\n+\t\t);\n \t});\n });"}],"unmatched":[]}