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
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/client/test/issues.test.ts?version=22&format=json
168 linesFirst import 80% · devops 11% · infra-split 8% · review 1%Last change devops in version 20, 4 versions changed it

You're reading version 22. The newest is 318, and 9 versions since then changed this file. Go to the newestCompare with 318

1// The Issues commands (#54) as far as the client alone decides them: which
2// Issues Worker a folder talks to, whether the token may go there, the MCP
3// tools, and the usage mistakes refused before any call. The Issues server
4// here is a stand-in that only counts calls; the commands against the real
5// store are issues/test/client-commands.test.ts, on the platform side (abso
6// issue 141).
7
8import assert from "node:assert/strict";
9import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
10import { createServer, type Server } from "node:http";
11import type { AddressInfo } from "node:net";
12import { tmpdir } from "node:os";
13import { join } from "node:path";
14import { after, before, describe, it } from "node:test";
15import { readMachineServers } from "../src/config.ts";
16import { issuesServerFor, tokenGoesTo } from "../src/core.ts";
17import { searchLines } from "../src/issues.ts";
18import { main } from "../src/main.ts";
19import { argvFor, mcpTools } from "../src/mcp.ts";
20import { type Fake, startFake } from "./fake-server.ts";
22const TOKEN = "test-token-not-secret";
24let fake: Fake;
25let issues: Server;
26let issuesUrl: string;
27/** Every call the stand-in Issues server took. */
28const seen: string[] = [];
29const dirs: string[] = [];
31before(async () => {
32 fake = await startFake(0, TOKEN);
33 issues = createServer((req, res) => {
34 seen.push(`${req.method} ${req.url}`);
35 res.writeHead(500, { "content-type": "application/json" }).end(JSON.stringify({ error: "a stand-in" }));
36 });
37 await new Promise<void>((ok) => issues.listen(0, "127.0.0.1", ok));
38 issuesUrl = `http://127.0.0.1:${(issues.address() as AddressInfo).port}`;
39});
40after(async () => {
41 await fake.close();
42 await new Promise((ok) => issues.close(ok));
43 for (const d of dirs) rmSync(d, { recursive: true, force: true, maxRetries: 5 });
44});
46const ENV = (): Record<string, string> => ({
47 AVCS_TOKEN: TOKEN,
48 AVCS_HOOK_FORCE: "1",
49 AVCS_ISSUES_SERVER: issuesUrl,
50 AVCS_SERVERS_FILE: "no-servers.json",
51});
53async function avcs(
54 cwd: string,
55 argv: string[],
56 env: Record<string, string> = ENV(),
57): Promise<{ exit: number; out: string }> {
58 const r = await main([...argv, "--json"], { cwd, env, write: () => {} });
59 return { exit: r.exit, out: r.stdout + r.stderr };
62let projects = 0;
63async function folder(agent: string): Promise<string> {
64 const dir = mkdtempSync(join(tmpdir(), "avcs-issues-"));
65 dirs.push(dir);
66 const r = await avcs(dir, ["init", "--server", fake.url, "--project", `issues${++projects}`, "--agent", agent]);
67 assert.equal(r.exit, 0, r.out);
68 return dir;
71describe("issues commands, the client's part (#54)", () => {
72 it("sends the token only to an Issues Worker it trusts", async () => {
73 const dave = await folder("dave");
74 const before = seen.length;
75 const r = await avcs(dave, ["issues"], { ...ENV(), AVCS_ISSUES_SERVER: "https://issues.example.com" });
76 assert.equal(r.exit, 1, r.out);
77 assert.match(r.out, /sends your token only to its own servers and this machine/);
78 assert.equal(seen.length, before);
79 // A server with no Issues Worker beside it, and none named.
80 const { AVCS_ISSUES_SERVER: _, ...without } = ENV();
81 const none = await avcs(dave, ["waiting"], without);
82 assert.notEqual(none.exit, 0);
83 assert.match(
84 none.out,
85 /has no Issues Worker beside it that abso knows; ~\/\.abso\/servers\.json or AVCS_ISSUES_SERVER names one/,
86 );
87 });
89 it("finds a server's Issues Worker in this machine's servers.json, and may send it the token", async () => {
90 const dir = mkdtempSync(join(tmpdir(), "abso-servers-"));
91 dirs.push(dir);
92 const file = join(dir, "servers.json");
93 writeFileSync(file, JSON.stringify({ servers: { [fake.url]: { issues: issuesUrl } } }));
94 const erin = await folder("erin");
95 const before = seen.length;
96 const { AVCS_ISSUES_SERVER: _, ...without } = ENV();
97 await avcs(erin, ["waiting"], { ...without, AVCS_SERVERS_FILE: file });
98 assert.ok(seen.length > before, "the call went to the Issues Worker servers.json names");
99 const machine = readMachineServers({ AVCS_SERVERS_FILE: file });
100 assert.equal(issuesServerFor(fake.url, machine), issuesUrl);
101 assert.equal(issuesServerFor("https://abso.example", machine), undefined);
102 // abso's own server and its Issues Worker are built in.
103 assert.ok(tokenGoesTo("https://api.abso.dev"));
104 assert.ok(tokenGoesTo("https://issues.abso.dev"));
105 assert.equal(issuesServerFor("https://api.abso.dev/"), "https://issues.abso.dev");
106 });
108 it("are MCP tools", () => {
109 const names = mcpTools().map((t) => t.name);
110 for (const n of ["issues", "issue", "search", "ask", "waiting", "answer"]) assert.ok(names.includes(n), n);
111 assert.deepEqual(argvFor("ask", { args: ["alice", "Which login?"], issue: "3", review: true }), [
112 "ask",
113 "--issue=3",
114 "--review",
115 "--",
116 "alice",
117 "Which login?",
118 ]);
119 });
121 it("refuses usage mistakes before any call", async () => {
122 const erin = await folder("erin");
123 const before = seen.length;
124 for (const argv of [
125 ["issue"],
126 ["issue", "x"],
127 ["ask", "alice"],
128 ["ask", "a", "q", "--review", "--task"],
129 ["answer", "3"],
130 ["issue", "1", "--comment", "a", "--drop"],
131 ["issues", "extra"],
132 ["ask", "--withdraw", "x"],
133 ["ask", "--withdraw", "3", "alice", "q"],
134 ["ask", "--withdraw", "3", "--issue", "2"],
135 ["ask", "--withdraw", "3", "--task"],
136 ["ask", "alice", "q", "--note", "a note without --withdraw"],
137 ["search"],
138 ["search", "words", "--limit", "0"],
139 ["search", "words", "--limit", "51"],
140 ]) {
141 const r = await avcs(erin, argv);
142 assert.equal(r.exit, 1, `${argv.join(" ")}: ${r.out}`);
143 }
144 assert.equal(seen.length, before);
145 });
147 it("shows a search hit as the issue, then where it matched, without the match markers", () => {
148 const issue = { id: 12, title: "Sync is slow", status: "open" as const, updated: 0, labels: [] };
149 assert.deepEqual(
150 searchLines({ issue, where: "comment", comment: 40, snippet: "the \u0001network\u0002 drops mid-sync" }),
151 [' 12 open "Sync is slow"', ' in comment 40: "the network drops mid-sync"'],
152 );
153 assert.deepEqual(searchLines({ issue, where: "description", snippet: "Pages load late.", meaning: true }), [
154 ' 12 open "Sync is slow"',
155 ' by meaning: "Pages load late."',
156 ]);
157 assert.deepEqual(searchLines({ issue, where: "title", snippet: "Sync is slow" })[1], " in the title");
158 });
160 it("withdraw is one POST to the asker's own withdraw/<ask> route", async () => {
161 const erin = await folder("erin");
162 const before = seen.length;
163 await avcs(erin, ["ask", "--withdraw", "#3", "--note", "overtaken by later decisions"]);
164 const posts = seen.slice(before).filter((s) => s.startsWith("POST"));
165 assert.equal(posts.length, 1, posts.join("\n"));
166 assert.match(posts[0]!, /^POST \/p\/issues\d+\/a\/erin\/withdraw\/3$/);
167 });
168});