{"draft":null,"from":79,"to":318,"files":[{"path":"client/test/issues.test.ts","added":94,"removed":22,"diff":"--- a/client/test/issues.test.ts\n+++ b/client/test/issues.test.ts\n@@ -13,7 +13,7 @@\n import { join } from \"node:path\";\n import { after, before, describe, it } from \"node:test\";\n import { readConfig, readMachineServers } from \"../src/config.ts\";\n-import { issuesServerFor, tokenGoesTo } from \"../src/core.ts\";\n+import { issuesServerFor, tokenGoesTo, tokenGoesToIssues } from \"../src/core.ts\";\n import { issuePage, searchLines } from \"../src/issues.ts\";\n import type { IssuePage } from \"../src/issues-wire.ts\";\n import { main } from \"../src/main.ts\";\n@@ -35,7 +35,7 @@\n const threaded = {\n \tid: 7,\n \tissue: 3,\n-\ttitle: \"Sync is slow\",\n+\ttitle: \"Pull is slow\",\n \tby: \"desk\",\n \tof: \"fay\",\n \tkind: \"question\",\n@@ -78,7 +78,7 @@\n \t\t\t\t\t\tdryRun: true,\n \t\t\t\t\t\tplan: {\n \t\t\t\t\t\t\tfrom: { project: body.from, issue: body.issue },\n-\t\t\t\t\t\t\ttitle: \"Sync is slow\",\n+\t\t\t\t\t\t\ttitle: \"Pull is slow\",\n \t\t\t\t\t\t\tedited: [\"description\"],\n \t\t\t\t\t\t\tlabels: [\"client\"],\n \t\t\t\t\t\t\tclosed: { how: \"done\" },\n@@ -97,6 +97,8 @@\n \t\t\treturn send(200, {\n \t\t\t\task: { id: Number(ack[2]), by: \"desk\", of: ack[1], answer: null, ack: { at: Date.now(), note: \"\" } },\n \t\t\t});\n+\t\t// Ask 404 stands for a server from before ask threads: neither route is there.\n+\t\tif (/\\/(ask|reply)\\/404$/.test(req.url ?? \"\")) return send(404, { error: \"no such issues route\" });\n \t\t// A reply answers with the ask; from the one asked, a question makes it wait on the asker.\n \t\tconst reply = /\\/a\\/([^/]+)\\/reply\\/(\\d+)$/.exec(req.url ?? \"\");\n \t\tif (req.method === \"POST\" && reply) {\n@@ -129,6 +131,9 @@\n \t\t\t});\n \t\tsend(500, { error: \"a stand-in\" });\n \t});\n+\t// As fake-server.ts: never close an idle kept-alive connection, or under load the client can reuse one as it closes\n+\t// and fail with ECONNRESET (abso 410).\n+\tissues.keepAliveTimeout = 0;\n \tawait new Promise<void>((ok) => issues.listen(0, \"127.0.0.1\", ok));\n \tissuesUrl = `http://127.0.0.1:${(issues.address() as AddressInfo).port}`;\n });\n@@ -171,16 +176,42 @@\n \t\tassert.equal(r.exit, 1, r.out);\n \t\tassert.match(r.out, /sends your token only to its own servers and this machine/);\n \t\tassert.equal(seen.length, before);\n-\t\t// A server with no Issues Worker beside it, and none named.\n-\t\tconst { AVCS_ISSUES_SERVER: _, ...without } = ENV();\n-\t\tconst none = await avcs(dave, [\"waiting\"], without);\n-\t\tassert.notEqual(none.exit, 0);\n-\t\tassert.match(\n-\t\t\tnone.out,\n-\t\t\t/has no Issues Worker beside it that abso knows; ~\\/\\.abso\\/servers\\.json or ABSO_ISSUES_SERVER names one/,\n-\t\t);\n \t});\n \n+\tit(\"with no Issues Worker named, uses the server's own /issues, as the open server keeps them\", () => {\n+\t\tassert.equal(issuesServerFor(\"https://abso.example\"), \"https://abso.example/issues\");\n+\t\tassert.equal(issuesServerFor(\"https://Abso.Example/\"), \"https://abso.example/issues\");\n+\t\tassert.equal(issuesServerFor(\"http://localhost:8787\"), \"http://localhost:8787/issues\");\n+\t\tassert.equal(issuesServerFor(\"not a server\"), undefined);\n+\t\t// abso's hosted server keeps its own Issues Worker, and servers.json still comes first.\n+\t\tassert.equal(issuesServerFor(\"https://api.abso.dev\"), \"https://issues.abso.dev\");\n+\t\tconst machine = {\n+\t\t\ttrusted: [],\n+\t\t\tissues: { \"https://staging.abso.example\": \"https://issues-staging.abso.example\" },\n+\t\t};\n+\t\tassert.equal(issuesServerFor(\"https://staging.abso.example\", machine), \"https://issues-staging.abso.example\");\n+\t\t// The token goes to <server>/issues exactly where it goes to <server>.\n+\t\tassert.ok(tokenGoesToIssues(\"https://api.abso.dev/issues\"));\n+\t\tassert.ok(tokenGoesToIssues(\"http://localhost:8787/issues\"));\n+\t\tassert.ok(tokenGoesToIssues(\"https://mine.example/issues\", \"https://mine.example\"));\n+\t\tassert.equal(tokenGoesToIssues(\"https://evil.example/issues\"), false);\n+\t\tassert.equal(tokenGoesToIssues(\"https://api.abso.dev@evil.example/issues\"), false);\n+\t\tassert.equal(tokenGoesToIssues(\"https://api.abso.dev/issues?x=1\"), false);\n+\t\tassert.equal(tokenGoesToIssues(\"http://mine.example/issues\", \"http://mine.example\"), false, \"plain http only here\");\n+\t\t// The server itself still takes no path.\n+\t\tassert.equal(tokenGoesTo(\"https://api.abso.dev/issues\"), false);\n+\t});\n+\n+\tit(\"calls <issues server>/p/<project>/... when the Issues Worker is at a path\", async () => {\n+\t\tconst fay = await folder(\"fay\");\n+\t\tconst before = seen.length;\n+\t\tconst env = { ...ENV(), AVCS_ISSUES_SERVER: `${issuesUrl}/issues` };\n+\t\tconst r = await main([\"ask\", \"7\"], { cwd: fay, env, write: () => {} });\n+\t\tassert.equal(r.exit, 0, r.stdout + r.stderr);\n+\t\tconst { project } = readConfig(fay);\n+\t\tassert.deepEqual(seen.slice(before), [`GET /issues/p/${project}/ask/7`]);\n+\t});\n+\n \tit(\"finds a server's Issues Worker in this machine's servers.json, and may send it the token\", async () => {\n \t\tconst dir = mkdtempSync(join(tmpdir(), \"abso-servers-\"));\n \t\tdirs.push(dir);\n@@ -193,7 +224,7 @@\n \t\tassert.ok(seen.length > before, \"the call went to the Issues Worker servers.json names\");\n \t\tconst machine = readMachineServers({ AVCS_SERVERS_FILE: file });\n \t\tassert.equal(issuesServerFor(fake.url, machine), issuesUrl);\n-\t\tassert.equal(issuesServerFor(\"https://abso.example\", machine), undefined);\n+\t\tassert.equal(issuesServerFor(\"https://abso.example\", machine), \"https://abso.example/issues\");\n \t\t// abso's own server and its Issues Worker are built in.\n \t\tassert.ok(tokenGoesTo(\"https://api.abso.dev\"));\n \t\tassert.ok(tokenGoesTo(\"https://issues.abso.dev\"));\n@@ -241,16 +272,44 @@\n \t});\n \n \tit(\"shows a search hit as the issue, then where it matched, without the match markers\", () => {\n-\t\tconst issue = { id: 12, title: \"Sync is slow\", status: \"open\" as const, updated: 0, labels: [] };\n+\t\tconst unknownAuthorship = {\n+\t\t\tkind: \"unknown\" as const,\n+\t\t\tactor: null,\n+\t\t\tprovenance: \"unknown\" as const,\n+\t\t\tauthorField: null,\n+\t\t};\n+\t\tconst issue = {\n+\t\t\tid: 12,\n+\t\t\ttitle: \"Pull is slow\",\n+\t\t\tstatus: \"open\" as const,\n+\t\t\tupdated: 0,\n+\t\t\tlabels: [],\n+\t\t\tauthorship: { title: unknownAuthorship },\n+\t\t};\n \t\tassert.deepEqual(\n-\t\t\tsearchLines({ issue, where: \"comment\", comment: 40, snippet: \"the \\u0001network\\u0002 drops mid-sync\" }),\n-\t\t\t['   12  open         \"Sync is slow\"', '       in comment 40: \"the network drops mid-sync\"'],\n+\t\t\tsearchLines({\n+\t\t\t\tissue,\n+\t\t\t\twhere: \"comment\",\n+\t\t\t\tcomment: 40,\n+\t\t\t\tsnippet: \"the \\u0001network\\u0002 drops mid-sync\",\n+\t\t\t\tmatchedAuthorship: unknownAuthorship,\n+\t\t\t}),\n+\t\t\t['   12  open         \"Pull is slow\"', '       in comment 40: \"the network drops mid-sync\"'],\n \t\t);\n-\t\tassert.deepEqual(searchLines({ issue, where: \"description\", snippet: \"Pages load late.\", meaning: true }), [\n-\t\t\t'   12  open         \"Sync is slow\"',\n-\t\t\t'       by meaning: \"Pages load late.\"',\n-\t\t]);\n-\t\tassert.deepEqual(searchLines({ issue, where: \"title\", snippet: \"Sync is slow\" })[1], \"       in the title\");\n+\t\tassert.deepEqual(\n+\t\t\tsearchLines({\n+\t\t\t\tissue,\n+\t\t\t\twhere: \"description\",\n+\t\t\t\tsnippet: \"Pages load late.\",\n+\t\t\t\tmeaning: true,\n+\t\t\t\tmatchedAuthorship: unknownAuthorship,\n+\t\t\t}),\n+\t\t\t['   12  open         \"Pull is slow\"', '       by meaning: \"Pages load late.\"'],\n+\t\t);\n+\t\tassert.deepEqual(\n+\t\t\tsearchLines({ issue, where: \"title\", snippet: \"Pull is slow\", matchedAuthorship: unknownAuthorship })[1],\n+\t\t\t\"       in the title\",\n+\t\t);\n \t});\n \n \tit(\"withdraw is one POST to the asker's own withdraw/<ask> route\", async () => {\n@@ -290,6 +349,19 @@\n \t\tassert.equal((await main([\"reply\", \"7\"], { cwd: fay, env: ENV(), write: () => {} })).exit, 1);\n \t});\n \n+\tit(\"names a server from before ask threads instead of a bare 404\", async () => {\n+\t\tconst fay = await folder(\"fay\");\n+\t\tfor (const argv of [\n+\t\t\t[\"reply\", \"404\", \"still there?\"],\n+\t\t\t[\"ask\", \"404\"],\n+\t\t]) {\n+\t\t\tconst r = await main(argv, { cwd: fay, env: ENV(), write: () => {} });\n+\t\t\tassert.equal(r.exit, 1, argv.join(\" \"));\n+\t\t\tassert.match(r.stderr, /doesn't have ask threads yet/, argv.join(\" \"));\n+\t\t\tassert.doesNotMatch(r.stderr, /no such issues route/, argv.join(\" \"));\n+\t\t}\n+\t});\n+\n \tit(\"ask <N> reads one ask with its whole thread, oldest first, and whose turn it is\", async () => {\n \t\tconst fay = await folder(\"fay\");\n \t\tconst before = seen.length;\n@@ -298,7 +370,7 @@\n \t\tassert.match(seen.slice(before).join(\"\\n\"), /^GET \\/p\\/issues\\d+\\/ask\\/7$/m);\n \t\tassert.match(\n \t\t\tr.stdout,\n-\t\t\t/^ {2}ask 7: desk, .* asks fay a question on issue 3 \\(\"Sync is slow\"\\) \\(2 replies; waiting on desk\\): \"Which way\\?\"$/m,\n+\t\t\t/^ {2}ask 7: desk, .* asks fay a question on issue 3 \\(\"Pull is slow\"\\) \\(2 replies; waiting on desk\\): \"Which way\\?\"$/m,\n \t\t);\n \t\tconst ack = r.stdout.indexOf('    fay, Jan 1 1970 00:00 UTC: \"ok, let me check\"');\n \t\tconst back = r.stdout.indexOf('    fay, Jan 1 1970 00:00 UTC, a question: \"staging or live?\\\\nlive is 906\"');\n@@ -399,7 +471,7 @@\n \t\t\tr.out.trimEnd(),\n \t\t\t[\n \t\t\t\t`A dry run: nothing was written. Copying ${from} issue 12 into core would make:`,\n-\t\t\t\t`  \"Sync is slow\", done (description edited when copied)`,\n+\t\t\t\t`  \"Pull is slow\", done (description edited when copied)`,\n \t\t\t\t\"  2 comments (1 edited), 1 answered ask, labelled client\",\n \t\t\t\t\"  not copied: comments 4; asks 2 (open asks, and what --clean left out)\",\n \t\t\t\t\"Run it again without --dry-run to copy it.\","}],"unmatched":[]}