- 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=2&format=json
137 linesFirst import 100%Last change First import in version 0, 1 version changed it
You're reading version 2. The newest is 318, and 12 versions since then changed this file.
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).
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 { main } from "../src/main.ts";
18import { argvFor, mcpTools } from "../src/mcp.ts";
19import { type Fake, startFake } from "./fake-server.ts";
21const TOKEN = "test-token-not-secret";
23let fake: Fake;
24let issues: Server;
25let issuesUrl: string;
26/** Every call the stand-in Issues server took. */
27const seen: string[] = [];
28const dirs: string[] = [];
30before(async () => {
31 fake = await startFake(0, TOKEN);
32 issues = createServer((req, res) => {
33 seen.push(`${req.method} ${req.url}`);
34 res.writeHead(500, { "content-type": "application/json" }).end(JSON.stringify({ error: "a stand-in" }));
35 });
36 await new Promise<void>((ok) => issues.listen(0, "127.0.0.1", ok));
37 issuesUrl = `http://127.0.0.1:${(issues.address() as AddressInfo).port}`;
38});
39after(async () => {
40 await fake.close();
41 await new Promise((ok) => issues.close(ok));
42 for (const d of dirs) rmSync(d, { recursive: true, force: true, maxRetries: 5 });
43});
45const ENV = (): Record<string, string> => ({
46 AVCS_TOKEN: TOKEN,
47 AVCS_HOOK_FORCE: "1",
48 AVCS_ISSUES_SERVER: issuesUrl,
49 AVCS_SERVERS_FILE: "no-servers.json",
50});
52async function avcs(
53 cwd: string,
54 argv: string[],
55 env: Record<string, string> = ENV(),
56): Promise<{ exit: number; out: string }> {
57 const r = await main([...argv, "--json"], { cwd, env, write: () => {} });
58 return { exit: r.exit, out: r.stdout + r.stderr };
59}
61let projects = 0;
62async function folder(agent: string): Promise<string> {
63 const dir = mkdtempSync(join(tmpdir(), "avcs-issues-"));
64 dirs.push(dir);
65 const r = await avcs(dir, ["init", "--server", fake.url, "--project", `issues${++projects}`, "--agent", agent]);
66 assert.equal(r.exit, 0, r.out);
67 return dir;
68}
70describe("issues commands, the client's part (#54)", () => {
71 it("sends the token only to an Issues Worker it trusts", async () => {
72 const dave = await folder("dave");
73 const before = seen.length;
74 const r = await avcs(dave, ["issues"], { ...ENV(), AVCS_ISSUES_SERVER: "https://issues.example.com" });
75 assert.equal(r.exit, 1, r.out);
76 assert.match(r.out, /sends your token only to its own servers and this machine/);
77 assert.equal(seen.length, before);
78 // A server with no Issues Worker beside it, and none named.
79 const { AVCS_ISSUES_SERVER: _, ...without } = ENV();
80 const none = await avcs(dave, ["waiting"], without);
81 assert.notEqual(none.exit, 0);
82 assert.match(
83 none.out,
84 /has no Issues Worker beside it that abso knows; ~\/\.avcs\/servers\.json or AVCS_ISSUES_SERVER names one/,
85 );
86 });
88 it("finds a server's Issues Worker in this machine's servers.json, and may send it the token", async () => {
89 const dir = mkdtempSync(join(tmpdir(), "abso-servers-"));
90 dirs.push(dir);
91 const file = join(dir, "servers.json");
92 writeFileSync(file, JSON.stringify({ servers: { [fake.url]: { issues: issuesUrl } } }));
93 const erin = await folder("erin");
94 const before = seen.length;
95 const { AVCS_ISSUES_SERVER: _, ...without } = ENV();
96 await avcs(erin, ["waiting"], { ...without, AVCS_SERVERS_FILE: file });
97 assert.ok(seen.length > before, "the call went to the Issues Worker servers.json names");
98 const machine = readMachineServers({ AVCS_SERVERS_FILE: file });
99 assert.equal(issuesServerFor(fake.url, machine), issuesUrl);
100 assert.equal(issuesServerFor("https://abso.example", machine), undefined);
101 // abso's own server and its Issues Worker are built in.
102 assert.ok(tokenGoesTo("https://api.abso.dev"));
103 assert.ok(tokenGoesTo("https://issues.abso.dev"));
104 assert.equal(issuesServerFor("https://api.abso.dev/"), "https://issues.abso.dev");
105 });
107 it("are MCP tools", () => {
108 const names = mcpTools().map((t) => t.name);
109 for (const n of ["issues", "issue", "ask", "waiting", "answer"]) assert.ok(names.includes(n), n);
110 assert.deepEqual(argvFor("ask", { args: ["alice", "Which login?"], issue: "3", review: true }), [
111 "ask",
112 "--issue=3",
113 "--review",
114 "--",
115 "alice",
116 "Which login?",
117 ]);
118 });
120 it("refuses usage mistakes before any call", async () => {
121 const erin = await folder("erin");
122 const before = seen.length;
123 for (const argv of [
124 ["issue"],
125 ["issue", "x"],
126 ["ask", "alice"],
127 ["ask", "a", "q", "--review", "--task"],
128 ["answer", "3"],
129 ["issue", "1", "--comment", "a", "--drop"],
130 ["issues", "extra"],
131 ]) {
132 const r = await avcs(erin, argv);
133 assert.equal(r.exit, 1, `${argv.join(" ")}: ${r.out}`);
134 }
135 assert.equal(seen.length, before);
136 });
137});