Lines 13–19 at 318 (were 13–19 at 76)
1313import { join } from "node:path"; 1414import { after, before, describe, it } from "node:test"; 1515import { readConfig, readMachineServers } from "../src/config.ts"; 16−import { issuesServerFor, tokenGoesTo } from "../src/core.ts";
16+import { issuesServerFor, tokenGoesTo, tokenGoesToIssues } from "../src/core.ts"; 1717import { issuePage, searchLines } from "../src/issues.ts"; 1818import type { IssuePage } from "../src/issues-wire.ts"; 1919import { main } from "../src/main.ts"; Lines 35–41 at 318 (were 35–41 at 76)
38− title: "Sync is slow",
38+ title: "Pull is slow", Lines 78–84 at 318 (were 78–84 at 76)
8080 from: { project: body.from, issue: body.issue }, 81− title: "Sync is slow",
81+ title: "Pull is slow", 8282 edited: ["description"], 8484 closed: { how: "done" }, Lines 97–104 at 318 (were 97–102 at 76)
9898 ask: { id: Number(ack[2]), by: "desk", of: ack[1], answer: null, ack: { at: Date.now(), note: "" } }, 100+ // Ask 404 stands for a server from before ask threads: neither route is there. 101+ if (/\/(ask|reply)\/404$/.test(req.url ?? "")) return send(404, { error: "no such issues route" }); 100102 // A reply answers with the ask; from the one asked, a question makes it wait on the asker. 101103 const reply = /\/a\/([^/]+)\/reply\/(\d+)$/.exec(req.url ?? ""); 102104 if (req.method === "POST" && reply) { Lines 131–139 at 318 (were 129–134 at 76)
130132 send(500, { error: "a stand-in" }); 134+ // As fake-server.ts: never close an idle kept-alive connection, or under load the client can reuse one as it closes 135+ // and fail with ECONNRESET (abso 410). 136+ issues.keepAliveTimeout = 0; 132137 await new Promise<void>((ok) => issues.listen(0, "127.0.0.1", ok)); 133138 issuesUrl = `http://127.0.0.1:${(issues.address() as AddressInfo).port}`; Lines 176–217 at 318 (were 171–186 at 76)
171176 assert.equal(r.exit, 1, r.out); 172177 assert.match(r.out, /sends your token only to its own servers and this machine/); 173178 assert.equal(seen.length, before); 174− // A server with no Issues Worker beside it, and none named.
175− const { AVCS_ISSUES_SERVER: _, ...without } = ENV();
176− const none = await avcs(dave, ["waiting"], without);
177− assert.notEqual(none.exit, 0);
178− assert.match(
179− none.out,
180− /has no Issues Worker beside it that abso knows; ~\/\.abso\/servers\.json or ABSO_ISSUES_SERVER names one/,
181− );
181+ it("with no Issues Worker named, uses the server's own /issues, as the open server keeps them", () => { 182+ assert.equal(issuesServerFor("https://abso.example"), "https://abso.example/issues"); 183+ assert.equal(issuesServerFor("https://Abso.Example/"), "https://abso.example/issues"); 184+ assert.equal(issuesServerFor("http://localhost:8787"), "http://localhost:8787/issues"); 185+ assert.equal(issuesServerFor("not a server"), undefined); 186+ // abso's hosted server keeps its own Issues Worker, and servers.json still comes first. 187+ assert.equal(issuesServerFor("https://api.abso.dev"), "https://issues.abso.dev"); 190+ issues: { "https://staging.abso.example": "https://issues-staging.abso.example" }, 192+ assert.equal(issuesServerFor("https://staging.abso.example", machine), "https://issues-staging.abso.example"); 193+ // The token goes to <server>/issues exactly where it goes to <server>. 194+ assert.ok(tokenGoesToIssues("https://api.abso.dev/issues")); 195+ assert.ok(tokenGoesToIssues("http://localhost:8787/issues")); 196+ assert.ok(tokenGoesToIssues("https://mine.example/issues", "https://mine.example")); 197+ assert.equal(tokenGoesToIssues("https://evil.example/issues"), false); 198+ assert.equal(tokenGoesToIssues("https://api.abso.dev@evil.example/issues"), false); 199+ assert.equal(tokenGoesToIssues("https://api.abso.dev/issues?x=1"), false); 200+ assert.equal(tokenGoesToIssues("http://mine.example/issues", "http://mine.example"), false, "plain http only here"); 201+ // The server itself still takes no path. 202+ assert.equal(tokenGoesTo("https://api.abso.dev/issues"), false); 205+ it("calls <issues server>/p/<project>/... when the Issues Worker is at a path", async () => { 206+ const fay = await folder("fay"); 207+ const before = seen.length; 208+ const env = { ...ENV(), AVCS_ISSUES_SERVER: `${issuesUrl}/issues` }; 209+ const r = await main(["ask", "7"], { cwd: fay, env, write: () => {} }); 210+ assert.equal(r.exit, 0, r.stdout + r.stderr); 211+ const { project } = readConfig(fay); 212+ assert.deepEqual(seen.slice(before), [`GET /issues/p/${project}/ask/7`]); 184215 it("finds a server's Issues Worker in this machine's servers.json, and may send it the token", async () => { 185216 const dir = mkdtempSync(join(tmpdir(), "abso-servers-")); Lines 224–230 at 318 (were 193–199 at 76)
193224 assert.ok(seen.length > before, "the call went to the Issues Worker servers.json names"); 194225 const machine = readMachineServers({ AVCS_SERVERS_FILE: file }); 195226 assert.equal(issuesServerFor(fake.url, machine), issuesUrl); 196− assert.equal(issuesServerFor("https://abso.example", machine), undefined);
227+ assert.equal(issuesServerFor("https://abso.example", machine), "https://abso.example/issues"); 197228 // abso's own server and its Issues Worker are built in. 198229 assert.ok(tokenGoesTo("https://api.abso.dev")); 199230 assert.ok(tokenGoesTo("https://issues.abso.dev")); Lines 272–315 at 318 (were 241–256 at 76)
243274 it("shows a search hit as the issue, then where it matched, without the match markers", () => { 244− const issue = { id: 12, title: "Sync is slow", status: "open" as const, updated: 0, labels: [] };
275+ const unknownAuthorship = { 276+ kind: "unknown" as const, 278+ provenance: "unknown" as const, 283+ title: "Pull is slow", 284+ status: "open" as const, 287+ authorship: { title: unknownAuthorship }, 246− searchLines({ issue, where: "comment", comment: 40, snippet: "the \u0001network\u0002 drops mid-sync" }),
247− [' 12 open "Sync is slow"', ' in comment 40: "the network drops mid-sync"'],
294+ snippet: "the \u0001network\u0002 drops mid-sync", 295+ matchedAuthorship: unknownAuthorship, 297+ [' 12 open "Pull is slow"', ' in comment 40: "the network drops mid-sync"'], 249− assert.deepEqual(searchLines({ issue, where: "description", snippet: "Pages load late.", meaning: true }), [
250− ' 12 open "Sync is slow"',
251− ' by meaning: "Pages load late."',
252− ]);
253− assert.deepEqual(searchLines({ issue, where: "title", snippet: "Sync is slow" })[1], " in the title");
302+ where: "description", 303+ snippet: "Pages load late.", 305+ matchedAuthorship: unknownAuthorship, 307+ [' 12 open "Pull is slow"', ' by meaning: "Pages load late."'], 310+ searchLines({ issue, where: "title", snippet: "Pull is slow", matchedAuthorship: unknownAuthorship })[1], 256315 it("withdraw is one POST to the asker's own withdraw/<ask> route", async () => { Lines 349–367 at 318 (were 290–295 at 76)
290349 assert.equal((await main(["reply", "7"], { cwd: fay, env: ENV(), write: () => {} })).exit, 1); 352+ it("names a server from before ask threads instead of a bare 404", async () => { 353+ const fay = await folder("fay"); 354+ for (const argv of [ 355+ ["reply", "404", "still there?"], 358+ const r = await main(argv, { cwd: fay, env: ENV(), write: () => {} }); 359+ assert.equal(r.exit, 1, argv.join(" ")); 360+ assert.match(r.stderr, /doesn't have ask threads yet/, argv.join(" ")); 361+ assert.doesNotMatch(r.stderr, /no such issues route/, argv.join(" ")); 293365 it("ask <N> reads one ask with its whole thread, oldest first, and whose turn it is", async () => { 294366 const fay = await folder("fay"); 295367 const before = seen.length; Lines 370–376 at 318 (were 298–304 at 76)
298370 assert.match(seen.slice(before).join("\n"), /^GET \/p\/issues\d+\/ask\/7$/m); 301− /^ {2}ask 7: desk, .* asks fay a question on issue 3 \("Sync is slow"\) \(2 replies; waiting on desk\): "Which way\?"$/m,
373+ /^ {2}ask 7: desk, .* asks fay a question on issue 3 \("Pull is slow"\) \(2 replies; waiting on desk\): "Which way\?"$/m, 303375 const ack = r.stdout.indexOf(' fay, Jan 1 1970 00:00 UTC: "ok, let me check"'); 304376 const back = r.stdout.indexOf(' fay, Jan 1 1970 00:00 UTC, a question: "staging or live?\\nlive is 906"'); Lines 471–477 at 318 (were 399–405 at 76)
401473 `A dry run: nothing was written. Copying ${from} issue 12 into core would make:`, 402− ` "Sync is slow", done (description edited when copied)`,
474+ ` "Pull is slow", done (description edited when copied)`, 403475 " 2 comments (1 edited), 1 answered ask, labelled client", 404476 " not copied: comments 4; asks 2 (open asks, and what --clean left out)", 405477 "Run it again without --dry-run to copy it.",