Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
blame on this site's /mcp
CLI
abso blame client/test/attach.test.ts --version 34 --json
JSON
/christopher/abso-core/blame/client/test/attach.test.ts?version=34&format=json
242 linespinch 100% · review 1%Last change pinch in version 29,

242 lines from 6 changes in 5 versions.

pinch5abso issue new and abso issue N --comment take --attach <file,file> (abso issue 171). Each file goes up to the Issues Worker first (POST /p/:project/a/:agent/attachments, the bytes as the body and the name URI-encoded in X-Avcs-Name), and the write carries the ids the uploads answered. Nothing is sent if a file is missing or over 10 MB. --attach anywhere else is refused. The issue's page lists each attachment under the issue or comment carrying it: id, name, size and its link. The wire types gain Attachment and attachments?. MCP's issue tool takes attach too, since its parameters come from the flags. The server side is abso 621 (off until Cloud binds the bucket). Tests: client/test/attach.test.ts, against a stand-in Issues server. Checked: biome ci, npm run check (698 pass).Compare1// --attach (abso issue 171): images go up to the Issues Worker before the
2// write that carries them, and the issue's page lists them. The Issues server
3// here is a stand-in that keeps what it was sent.
4
5import assert from "node:assert/strict";
pinch29Client: abso issue N --save-attachments <dir> saves each attachment on an issue and its comments once (an SVG's own file beside its drawing), outside the abso folder unless the place is ignored; MCP confines the folder like attach. abso export now stamps its folder with .abso-export, one line of JSON in a file with no extension, so the exported project's own formatter and linter pass it by; a folder stamped .abso-export.json or .avcs-export.json still counts as an export.Compare6import { mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
pinch5abso issue new and abso issue N --comment take --attach <file,file> (abso issue 171). Each file goes up to the Issues Worker first (POST /p/:project/a/:agent/attachments, the bytes as the body and the name URI-encoded in X-Avcs-Name), and the write carries the ids the uploads answered. Nothing is sent if a file is missing or over 10 MB. --attach anywhere else is refused. The issue's page lists each attachment under the issue or comment carrying it: id, name, size and its link. The wire types gain Attachment and attachments?. MCP's issue tool takes attach too, since its parameters come from the flags. The server side is abso 621 (off until Cloud binds the bucket). Tests: client/test/attach.test.ts, against a stand-in Issues server. Checked: biome ci, npm run check (698 pass).Compare7import { createServer, type Server } from "node:http";
8import type { AddressInfo } from "node:net";
9import { tmpdir } from "node:os";
10import { join } from "node:path";
11import { after, before, describe, it } from "node:test";
12import { issuePage } from "../src/issues.ts";
13import type { IssuePage } from "../src/issues-wire.ts";
14import { main } from "../src/main.ts";
15import { type Fake, startFake } from "./fake-server.ts";
17const TOKEN = "test-token-not-secret";
18let fake: Fake;
19let issues: Server;
20let issuesUrl: string;
21const seen: { method: string; url: string; headers: Record<string, string | string[] | undefined>; body: Buffer }[] =
22 [];
23const dirs: string[] = [];
25before(async () => {
26 fake = await startFake(0, TOKEN);
27 issues = createServer((req, res) => {
28 const parts: Buffer[] = [];
29 req.on("data", (c: Buffer) => parts.push(c));
30 req.on("end", () => {
31 const body = Buffer.concat(parts);
32 seen.push({ method: req.method!, url: req.url!, headers: req.headers, body });
33 const json = (o: unknown) => res.writeHead(200, { "content-type": "application/json" }).end(JSON.stringify(o));
pinch15--attach says plainly when the Issues server doesn't take attachments yet A server from before attachments has no upload route. It answered 400 'the body is JSON', or 404, and the client printed that as it came, which told nobody what had happened. Now the client says the server doesn't take attachments yet, that the file wasn't sent and nothing was written, and to leave --attach off or link the image instead. A server that has the route but nowhere to keep files (501) gets the same message. A test checks the message and that no issue is opened.Compare34 // A server from before attachments: it reads every POST body as JSON.
35 if (req.url!.includes("/p/old") && req.url!.endsWith("/attachments"))
36 return res.writeHead(400, { "content-type": "application/json" }).end('{"error":"the body is JSON"}');
pinch5abso issue new and abso issue N --comment take --attach <file,file> (abso issue 171). Each file goes up to the Issues Worker first (POST /p/:project/a/:agent/attachments, the bytes as the body and the name URI-encoded in X-Avcs-Name), and the write carries the ids the uploads answered. Nothing is sent if a file is missing or over 10 MB. --attach anywhere else is refused. The issue's page lists each attachment under the issue or comment carrying it: id, name, size and its link. The wire types gain Attachment and attachments?. MCP's issue tool takes attach too, since its parameters come from the flags. The server side is abso 621 (off until Cloud binds the bucket). Tests: client/test/attach.test.ts, against a stand-in Issues server. Checked: biome ci, npm run check (698 pass).Compare37 if (req.url!.endsWith("/attachments"))
38 return json({
39 id: `a${String(seen.length).padStart(12, "0")}`,
40 name: "x",
41 type: "image/png",
42 size: body.length,
43 });
44 if (req.url!.endsWith("/issue")) return json({ id: 7 });
45 if (/\/issue\/\d+\/comment$/.test(req.url!)) return json({ id: 3 });
pinch29Client: abso issue N --save-attachments <dir> saves each attachment on an issue and its comments once (an SVG's own file beside its drawing), outside the abso folder unless the place is ignored; MCP confines the folder like attach. abso export now stamps its folder with .abso-export, one line of JSON in a file with no extension, so the exported project's own formatter and linter pass it by; a folder stamped .abso-export.json or .avcs-export.json still counts as an export.Compare46 // Issue 8 carries an svg-drawn image on itself and again on a comment, plus one more on the comment.
47 const logo = { id: "a00000000000b", name: "../shot one.png", type: "image/png", size: 13 };
48 if (req.method === "GET" && /\/issue\/8$/.test(req.url!))
49 return json({
50 issue: { id: 8, attachments: [{ ...logo, source: { name: "logo.svg", size: 20 } }] },
51 comments: [{ attachments: [logo, { id: "a00000000000c", name: "after.png", type: "image/png", size: 13 }] }],
52 edits: [],
53 asks: [],
54 claims: [],
55 children: [],
56 });
57 const served = /\/attachments\/(a[0-9a-f]{12})(\/source)?$/.exec(req.url!);
58 if (req.method === "GET" && served)
59 return res.writeHead(200, { "content-type": "image/png" }).end(`${served[1]}${served[2] ?? ""}`);
pinch5abso issue new and abso issue N --comment take --attach <file,file> (abso issue 171). Each file goes up to the Issues Worker first (POST /p/:project/a/:agent/attachments, the bytes as the body and the name URI-encoded in X-Avcs-Name), and the write carries the ids the uploads answered. Nothing is sent if a file is missing or over 10 MB. --attach anywhere else is refused. The issue's page lists each attachment under the issue or comment carrying it: id, name, size and its link. The wire types gain Attachment and attachments?. MCP's issue tool takes attach too, since its parameters come from the flags. The server side is abso 621 (off until Cloud binds the bucket). Tests: client/test/attach.test.ts, against a stand-in Issues server. Checked: biome ci, npm run check (698 pass).Compare60 res.writeHead(404).end("{}");
61 });
62 });
63 await new Promise<void>((ok) => issues.listen(0, "127.0.0.1", ok));
64 issuesUrl = `http://127.0.0.1:${(issues.address() as AddressInfo).port}`;
65});
66after(async () => {
67 await fake.close();
68 await new Promise((ok) => issues.close(ok));
69 for (const d of dirs) rmSync(d, { recursive: true, force: true, maxRetries: 5 });
70});
72const ENV = (): Record<string, string> => ({
73 AVCS_TOKEN: TOKEN,
74 AVCS_HOOK_FORCE: "1",
75 AVCS_ISSUES_SERVER: issuesUrl,
76 AVCS_SERVERS_FILE: "no-servers.json",
77});
79async function avcs(cwd: string, argv: string[]): Promise<{ exit: number; out: string; json?: unknown }> {
80 const r = await main([...argv, "--json"], { cwd, env: ENV(), write: () => {} });
81 let json: unknown;
82 try {
83 json = JSON.parse(r.stdout);
84 } catch {}
85 return { exit: r.exit, out: r.stdout + r.stderr, json };
88let n = 0;
89async function folder(): Promise<string> {
90 const dir = mkdtempSync(join(tmpdir(), "abso-attach-"));
91 dirs.push(dir);
92 const r = await avcs(dir, ["init", "--server", fake.url, "--project", `attach${++n}`, "--agent", "ann"]);
93 assert.equal(r.exit, 0, r.out);
94 writeFileSync(join(dir, "shot.png"), Buffer.from([0x89, 0x50, 0x4e, 0x47, 1, 2, 3]));
95 writeFileSync(join(dir, "after.png"), Buffer.from([0x89, 0x50, 0x4e, 0x47, 4, 5]));
96 return dir;
99describe("--attach (abso issue 171)", () => {
100 it("uploads each file, then opens the issue carrying their ids", async () => {
101 const dir = await folder();
102 const from = seen.length;
103 const r = await avcs(dir, ["issue", "new", "The page after the fix", "--attach", "shot.png,after.png"]);
104 assert.equal(r.exit, 0, r.out);
105 const calls = seen.slice(from);
106 assert.deepEqual(
107 calls.map((c) => `${c.method} ${c.url.replace(/^\/p\/[^/]+/, "")}`),
108 ["POST /a/ann/attachments", "POST /a/ann/attachments", "POST /a/ann/issue"],
109 );
110 assert.equal(calls[0]!.headers["x-avcs-name"], "shot.png");
111 assert.equal(calls[0]!.headers["content-type"], "application/octet-stream");
112 assert.deepEqual([...calls[0]!.body], [0x89, 0x50, 0x4e, 0x47, 1, 2, 3]);
113 const opened = JSON.parse(calls[2]!.body.toString()) as { title: string; attachments: string[] };
114 assert.equal(opened.title, "The page after the fix");
115 assert.equal(opened.attachments.length, 2);
116 assert.deepEqual((r.json as { attachments: string[] }).attachments, opened.attachments);
117 });
119 it("goes on a comment too, and nowhere else", async () => {
120 const dir = await folder();
121 const from = seen.length;
122 const r = await avcs(dir, ["issue", "7", "--comment", "after", "--attach", "shot.png"]);
123 assert.equal(r.exit, 0, r.out);
124 const comment = JSON.parse(seen.at(-1)!.body.toString()) as { text: string; attachments: string[] };
125 assert.equal(comment.text, "after");
126 assert.equal(comment.attachments.length, 1);
127 assert.equal(seen.length - from, 2);
128 const alone = await avcs(dir, ["issue", "7", "--attach", "shot.png"]);
129 assert.equal(alone.exit, 1);
review16The client says abso, not avcs, in everything a person reads: the hints after an issue view and abso issue new, the help for issue, issues, ask, answer and waiting, the 'abso:' prefix on notices from run, publish --check, the queue and serve, the 'News from abso' header, the MCP server's name and the claude mcp add example, and the view mod's status line. Only printed words changed: file and folder names (avcs.json, .avcs/, ~/.avcs/token), environment variables and wire headers are as they were, and the tests were updated to the new words (704 pass, biome ci clean).Compare130 assert.match(alone.out, /--attach goes with abso issue new or --comment/);
pinch5abso issue new and abso issue N --comment take --attach <file,file> (abso issue 171). Each file goes up to the Issues Worker first (POST /p/:project/a/:agent/attachments, the bytes as the body and the name URI-encoded in X-Avcs-Name), and the write carries the ids the uploads answered. Nothing is sent if a file is missing or over 10 MB. --attach anywhere else is refused. The issue's page lists each attachment under the issue or comment carrying it: id, name, size and its link. The wire types gain Attachment and attachments?. MCP's issue tool takes attach too, since its parameters come from the flags. The server side is abso 621 (off until Cloud binds the bucket). Tests: client/test/attach.test.ts, against a stand-in Issues server. Checked: biome ci, npm run check (698 pass).Compare131 });
pinch15--attach says plainly when the Issues server doesn't take attachments yet A server from before attachments has no upload route. It answered 400 'the body is JSON', or 404, and the client printed that as it came, which told nobody what had happened. Now the client says the server doesn't take attachments yet, that the file wasn't sent and nothing was written, and to leave --attach off or link the image instead. A server that has the route but nowhere to keep files (501) gets the same message. A test checks the message and that no issue is opened.Compare132
133 it("says plainly when the server doesn't take attachments yet, and writes nothing", async () => {
134 const dir = mkdtempSync(join(tmpdir(), "abso-attach-"));
135 dirs.push(dir);
136 const init = await avcs(dir, ["init", "--server", fake.url, "--project", "old", "--agent", "ann"]);
137 assert.equal(init.exit, 0, init.out);
138 writeFileSync(join(dir, "shot.png"), Buffer.from([0x89, 0x50, 0x4e, 0x47, 1]));
139 const from = seen.length;
140 const r = await avcs(dir, ["issue", "new", "T", "--attach", "shot.png"]);
141 assert.equal(r.exit, 1);
142 assert.match(r.out, /doesn't take attachments yet, so shot.png wasn't sent and nothing was written/);
143 assert.deepEqual(
144 seen.slice(from).map((c) => c.url.replace(/^\/p\/[^/]+/, "")),
145 ["/a/ann/attachments"],
146 "no issue was opened",
147 );
148 });
pinch5abso issue new and abso issue N --comment take --attach <file,file> (abso issue 171). Each file goes up to the Issues Worker first (POST /p/:project/a/:agent/attachments, the bytes as the body and the name URI-encoded in X-Avcs-Name), and the write carries the ids the uploads answered. Nothing is sent if a file is missing or over 10 MB. --attach anywhere else is refused. The issue's page lists each attachment under the issue or comment carrying it: id, name, size and its link. The wire types gain Attachment and attachments?. MCP's issue tool takes attach too, since its parameters come from the flags. The server side is abso 621 (off until Cloud binds the bucket). Tests: client/test/attach.test.ts, against a stand-in Issues server. Checked: biome ci, npm run check (698 pass).Compare149
150 it("sends nothing when a file is missing", async () => {
151 const dir = await folder();
152 const from = seen.length;
153 const r = await avcs(dir, ["issue", "new", "T", "--attach", "shot.png,nope.png"]);
154 assert.equal(r.exit, 1);
155 assert.match(r.out, /--attach nope.png: no such file/);
156 assert.equal(seen.length, from);
pinch29Client: abso issue N --save-attachments <dir> saves each attachment on an issue and its comments once (an SVG's own file beside its drawing), outside the abso folder unless the place is ignored; MCP confines the folder like attach. abso export now stamps its folder with .abso-export, one line of JSON in a file with no extension, so the exported project's own formatter and linter pass it by; a folder stamped .abso-export.json or .avcs-export.json still counts as an export.Compare157 });
159 it("--save-attachments saves each attachment once, an svg's own file too, outside the folder", async () => {
160 const dir = await folder();
161 const out = mkdtempSync(join(tmpdir(), "abso-saved-"));
162 dirs.push(out);
163 const r = await avcs(dir, ["issue", "8", "--save-attachments", join(out, "images")]);
164 assert.equal(r.exit, 0, r.out);
165 const names = readdirSync(join(out, "images")).sort();
166 assert.deepEqual(names, ["a00000000000b-logo.svg", "a00000000000b-shot_one.png", "a00000000000c-after.png"]);
167 assert.equal(readFileSync(join(out, "images", "a00000000000b-logo.svg"), "utf8"), "a00000000000b/source");
168 assert.equal(readFileSync(join(out, "images", "a00000000000c-after.png"), "utf8"), "a00000000000c");
169 assert.equal((r.json as { files: unknown[] }).files.length, 3);
170 // Into the folder only where abso leaves files out, or they'd be recorded as edits.
171 const inside = await avcs(dir, ["issue", "8", "--save-attachments", "images"]);
172 assert.equal(inside.exit, 1);
173 assert.match(inside.out, /inside this abso folder/);
174 assert.equal((await avcs(dir, ["issue", "8", "--save-attachments", "."])).exit, 1);
175 writeFileSync(join(dir, ".absoignore"), "saved/\n");
176 assert.equal((await avcs(dir, ["issue", "8", "--save-attachments", "saved"])).exit, 0);
177 const mixed = await avcs(dir, ["issue", "8", "--save-attachments", out, "--comment", "x"]);
178 assert.equal(mixed.exit, 1);
179 assert.match(mixed.out, /--save-attachments goes alone/);
pinch5abso issue new and abso issue N --comment take --attach <file,file> (abso issue 171). Each file goes up to the Issues Worker first (POST /p/:project/a/:agent/attachments, the bytes as the body and the name URI-encoded in X-Avcs-Name), and the write carries the ids the uploads answered. Nothing is sent if a file is missing or over 10 MB. --attach anywhere else is refused. The issue's page lists each attachment under the issue or comment carrying it: id, name, size and its link. The wire types gain Attachment and attachments?. MCP's issue tool takes attach too, since its parameters come from the flags. The server side is abso 621 (off until Cloud binds the bucket). Tests: client/test/attach.test.ts, against a stand-in Issues server. Checked: biome ci, npm run check (698 pass).Compare180 });
182 it("an issue's page lists its attachments and each comment's, with links", () => {
183 const page = {
184 issue: {
185 id: 7,
186 title: "T",
187 status: "open",
188 opened: { by: "ann", at: 0 },
189 agent: null,
190 agents: [],
191 blockedBy: [],
192 labels: [],
193 versions: [],
194 waitingOn: [],
195 parent: null,
196 children: 0,
197 updated: 0,
198 closed: null,
199 description: "",
200 lines: null,
201 watchers: [],
202 attachments: [{ id: "a0123456789ab", name: "shot.png", type: "image/png", size: 2048 }],
203 },
204 comments: [
205 {
206 id: 1,
207 by: "bob",
208 kind: "comment",
209 text: "same here",
210 at: 0,
pinch24abso issue N lists an SVG attachment's own file. A server that takes SVG attachments draws each one as a PNG, and keeps the SVG only as a download. The issue page now shows that download under the image: 'drawn from "logo.svg", 512 B, <link>/source'. The --attach help says svg is taken, up to 1 MB, on servers that take it.Compare211 attachments: [
212 { id: "a00000000000f", name: "mine.png", type: "image/png", size: 3 * 1024 * 1024 },
213 {
214 id: "a0000000000aa",
215 name: "logo.png",
216 type: "image/png",
217 size: 4096,
218 source: { name: "logo.svg", size: 512 },
219 },
220 ],
pinch5abso issue new and abso issue N --comment take --attach <file,file> (abso issue 171). Each file goes up to the Issues Worker first (POST /p/:project/a/:agent/attachments, the bytes as the body and the name URI-encoded in X-Avcs-Name), and the write carries the ids the uploads answered. Nothing is sent if a file is missing or over 10 MB. --attach anywhere else is refused. The issue's page lists each attachment under the issue or comment carrying it: id, name, size and its link. The wire types gain Attachment and attachments?. MCP's issue tool takes attach too, since its parameters come from the flags. The server side is abso 621 (off until Cloud binds the bucket). Tests: client/test/attach.test.ts, against a stand-in Issues server. Checked: biome ci, npm run check (698 pass).Compare221 },
222 ],
223 edits: [],
224 asks: [],
225 claims: [],
226 children: [],
227 } as unknown as IssuePage;
228 const text = issuePage(page, {
229 attachmentUrl: (id: string) => `https://issues.example/p/x/attachments/${id}`,
230 }).join("\n");
231 assert.match(
232 text,
233 /attached a0123456789ab: "shot.png", 2 KB, https:\/\/issues.example\/p\/x\/attachments\/a0123456789ab/,
234 );
235 assert.match(text, /\n {4}attached a00000000000f: "mine.png", 3.0 MB/);
pinch24abso issue N lists an SVG attachment's own file. A server that takes SVG attachments draws each one as a PNG, and keeps the SVG only as a download. The issue page now shows that download under the image: 'drawn from "logo.svg", 512 B, <link>/source'. The --attach help says svg is taken, up to 1 MB, on servers that take it.Compare236 // An SVG is listed as its PNG, with its own file as a download beside it.
237 assert.match(
238 text,
239 /\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/,
240 );
pinch5abso issue new and abso issue N --comment take --attach <file,file> (abso issue 171). Each file goes up to the Issues Worker first (POST /p/:project/a/:agent/attachments, the bytes as the body and the name URI-encoded in X-Avcs-Name), and the write carries the ids the uploads answered. Nothing is sent if a file is missing or over 10 MB. --attach anywhere else is refused. The issue's page lists each attachment under the issue or comment carrying it: id, name, size and its link. The wire types gain Attachment and attachments?. MCP's issue tool takes attach too, since its parameters come from the flags. The server side is abso 621 (off until Cloud binds the bucket). Tests: client/test/attach.test.ts, against a stand-in Issues server. Checked: biome ci, npm run check (698 pass).Compare241 });
242});