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 22 --json
JSON
/christopher/abso-core/blame/client/test/attach.test.ts?version=22&format=json
191 linespinch 99% · review 1%Last change review in version 16,

191 lines from 4 changes in 3 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";
6import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
7import { 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 });
46 res.writeHead(404).end("{}");
47 });
48 });
49 await new Promise<void>((ok) => issues.listen(0, "127.0.0.1", ok));
50 issuesUrl = `http://127.0.0.1:${(issues.address() as AddressInfo).port}`;
51});
52after(async () => {
53 await fake.close();
54 await new Promise((ok) => issues.close(ok));
55 for (const d of dirs) rmSync(d, { recursive: true, force: true, maxRetries: 5 });
56});
58const ENV = (): Record<string, string> => ({
59 AVCS_TOKEN: TOKEN,
60 AVCS_HOOK_FORCE: "1",
61 AVCS_ISSUES_SERVER: issuesUrl,
62 AVCS_SERVERS_FILE: "no-servers.json",
63});
65async function avcs(cwd: string, argv: string[]): Promise<{ exit: number; out: string; json?: unknown }> {
66 const r = await main([...argv, "--json"], { cwd, env: ENV(), write: () => {} });
67 let json: unknown;
68 try {
69 json = JSON.parse(r.stdout);
70 } catch {}
71 return { exit: r.exit, out: r.stdout + r.stderr, json };
74let n = 0;
75async function folder(): Promise<string> {
76 const dir = mkdtempSync(join(tmpdir(), "abso-attach-"));
77 dirs.push(dir);
78 const r = await avcs(dir, ["init", "--server", fake.url, "--project", `attach${++n}`, "--agent", "ann"]);
79 assert.equal(r.exit, 0, r.out);
80 writeFileSync(join(dir, "shot.png"), Buffer.from([0x89, 0x50, 0x4e, 0x47, 1, 2, 3]));
81 writeFileSync(join(dir, "after.png"), Buffer.from([0x89, 0x50, 0x4e, 0x47, 4, 5]));
82 return dir;
85describe("--attach (abso issue 171)", () => {
86 it("uploads each file, then opens the issue carrying their ids", async () => {
87 const dir = await folder();
88 const from = seen.length;
89 const r = await avcs(dir, ["issue", "new", "The page after the fix", "--attach", "shot.png,after.png"]);
90 assert.equal(r.exit, 0, r.out);
91 const calls = seen.slice(from);
92 assert.deepEqual(
93 calls.map((c) => `${c.method} ${c.url.replace(/^\/p\/[^/]+/, "")}`),
94 ["POST /a/ann/attachments", "POST /a/ann/attachments", "POST /a/ann/issue"],
95 );
96 assert.equal(calls[0]!.headers["x-avcs-name"], "shot.png");
97 assert.equal(calls[0]!.headers["content-type"], "application/octet-stream");
98 assert.deepEqual([...calls[0]!.body], [0x89, 0x50, 0x4e, 0x47, 1, 2, 3]);
99 const opened = JSON.parse(calls[2]!.body.toString()) as { title: string; attachments: string[] };
100 assert.equal(opened.title, "The page after the fix");
101 assert.equal(opened.attachments.length, 2);
102 assert.deepEqual((r.json as { attachments: string[] }).attachments, opened.attachments);
103 });
105 it("goes on a comment too, and nowhere else", async () => {
106 const dir = await folder();
107 const from = seen.length;
108 const r = await avcs(dir, ["issue", "7", "--comment", "after", "--attach", "shot.png"]);
109 assert.equal(r.exit, 0, r.out);
110 const comment = JSON.parse(seen.at(-1)!.body.toString()) as { text: string; attachments: string[] };
111 assert.equal(comment.text, "after");
112 assert.equal(comment.attachments.length, 1);
113 assert.equal(seen.length - from, 2);
114 const alone = await avcs(dir, ["issue", "7", "--attach", "shot.png"]);
115 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).Compare116 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).Compare117 });
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.Compare118
119 it("says plainly when the server doesn't take attachments yet, and writes nothing", async () => {
120 const dir = mkdtempSync(join(tmpdir(), "abso-attach-"));
121 dirs.push(dir);
122 const init = await avcs(dir, ["init", "--server", fake.url, "--project", "old", "--agent", "ann"]);
123 assert.equal(init.exit, 0, init.out);
124 writeFileSync(join(dir, "shot.png"), Buffer.from([0x89, 0x50, 0x4e, 0x47, 1]));
125 const from = seen.length;
126 const r = await avcs(dir, ["issue", "new", "T", "--attach", "shot.png"]);
127 assert.equal(r.exit, 1);
128 assert.match(r.out, /doesn't take attachments yet, so shot.png wasn't sent and nothing was written/);
129 assert.deepEqual(
130 seen.slice(from).map((c) => c.url.replace(/^\/p\/[^/]+/, "")),
131 ["/a/ann/attachments"],
132 "no issue was opened",
133 );
134 });
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).Compare135
136 it("sends nothing when a file is missing", async () => {
137 const dir = await folder();
138 const from = seen.length;
139 const r = await avcs(dir, ["issue", "new", "T", "--attach", "shot.png,nope.png"]);
140 assert.equal(r.exit, 1);
141 assert.match(r.out, /--attach nope.png: no such file/);
142 assert.equal(seen.length, from);
143 });
145 it("an issue's page lists its attachments and each comment's, with links", () => {
146 const page = {
147 issue: {
148 id: 7,
149 title: "T",
150 status: "open",
151 opened: { by: "ann", at: 0 },
152 agent: null,
153 agents: [],
154 blockedBy: [],
155 labels: [],
156 versions: [],
157 waitingOn: [],
158 parent: null,
159 children: 0,
160 updated: 0,
161 closed: null,
162 description: "",
163 lines: null,
164 watchers: [],
165 attachments: [{ id: "a0123456789ab", name: "shot.png", type: "image/png", size: 2048 }],
166 },
167 comments: [
168 {
169 id: 1,
170 by: "bob",
171 kind: "comment",
172 text: "same here",
173 at: 0,
174 attachments: [{ id: "a00000000000f", name: "mine.png", type: "image/png", size: 3 * 1024 * 1024 }],
175 },
176 ],
177 edits: [],
178 asks: [],
179 claims: [],
180 children: [],
181 } as unknown as IssuePage;
182 const text = issuePage(page, {
183 attachmentUrl: (id: string) => `https://issues.example/p/x/attachments/${id}`,
184 }).join("\n");
185 assert.match(
186 text,
187 /attached a0123456789ab: "shot.png", 2 KB, https:\/\/issues.example\/p\/x\/attachments\/a0123456789ab/,
188 );
189 assert.match(text, /\n {4}attached a00000000000f: "mine.png", 3.0 MB/);
190 });
191});