Versions 0 to 318
new file, 371 lines
4+
16+
21+const seen: { method: string; url: string; headers: Record<string, string | string[] | undefined>; body: Buffer }[] =
24+
33+ const json = (o: unknown) => res.writeHead(200, { "content-type": "application/json" }).end(JSON.stringify(o));
36+ return res.writeHead(400, { "content-type": "application/json" }).end('{"error":"the body is JSON"}');
55+ return json({ ask: { by: "bob", answer: { by: "ann", words: "w", at: 0, attachments: files } } });
66+ answer: { attachments: [{ id: "a00000000000e", name: "answer.png", type: "image/png", size: 13 }] },
72+ // Issue 8 carries an svg-drawn image on itself and again on a comment, plus one more on the comment.
77+ comments: [{ attachments: [logo, { id: "a00000000000c", name: "after.png", type: "image/png", size: 13 }] }],
85+ return res.writeHead(200, { "content-type": "image/png" }).end(`${served[1]}${served[2] ?? ""}`);
89+ // As fake-server.ts: never close an idle kept-alive connection, or under load the client can reuse one as it closes
100+
107+
108+async function avcs(cwd: string, argv: string[]): Promise<{ exit: number; out: string; json?: unknown }> {
116+
121+ const r = await avcs(dir, ["init", "--server", fake.url, "--project", `attach${++n}`, "--agent", "ann"]);
127+
132+ const r = await avcs(dir, ["issue", "new", "The page after the fix", "--attach", "shot.png,after.png"]);
142+ const opened = JSON.parse(calls[2]!.body.toString()) as { title: string; attachments: string[] };
147+
153+ const comment = JSON.parse(seen.at(-1)!.body.toString()) as { text: string; attachments: string[] };
161+
162+ it("says plainly when the server doesn't take attachments yet, and writes nothing", async () => {
165+ const init = await avcs(dir, ["init", "--server", fake.url, "--project", "old", "--agent", "ann"]);
171+ assert.match(r.out, /doesn't take attachments yet, so shot.png wasn't sent and nothing was written/);
178+
187+
188+ it("--save-attachments saves each attachment once, an svg's own file too, outside the folder", async () => {
195+ assert.deepEqual(names, ["a00000000000b-logo.svg", "a00000000000b-shot_one.png", "a00000000000c-after.png"]);
196+ assert.equal(readFileSync(join(out, "images", "a00000000000b-logo.svg"), "utf8"), "a00000000000b/source");
197+ assert.equal(readFileSync(join(out, "images", "a00000000000c-after.png"), "utf8"), "a00000000000c");
210+
228+ const ask = JSON.parse(seen.at(-1)!.body.toString()) as { question: string; attachments: string[] };
235+ const answer = JSON.parse(seen.at(-1)!.body.toString()) as { words: string; attachments: string[] };
244+
248+ const init = await avcs(dir, ["init", "--server", fake.url, "--project", "keepless", "--agent", "ann"]);
260+
267+ assert.deepEqual(readdirSync(out).sort(), ["a00000000000d-question.png", "a00000000000e-answer.png"]);
269+
321+ /attached a0123456789ab: "shot.png", 2 KB, https:\/\/issues.example\/p\/x\/attachments\/a0123456789ab/,
327+ /^Issue [^\n]*\n[^\n]*\n3 files are attached below\. To read them: abso issue \d+ --save-attachments <folder> saves every one there, then open the files\. The links are for people signed in on the website\.\n/,
330+ issuePage({ ...page, issue: { ...page.issue, attachments: [] }, comments: [] } as unknown as IssuePage).join(
338+ /\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/,
364+ const asks = issuePage(asked, { attachmentUrl: (id: string) => `https://i.example/${id}` }).join("\n");
365+ assert.match(asks, /\n5 files are attached below\./, "an ask's question and answer files count too");
368+ /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/,
- MCP
- compare on this site's /mcp
- CLI
- abso diff 0 318 client/test/attach.test.ts --json
- JSON
- /christopher/abso-core/compare/0..318?file=client%2Ftest%2Fattach.test.ts&format=json