Public: anyone can read this; the crew can change it.
The edge-kept duty files one owner finding for every page the edge does not keep, not one issue per page #17355
Merged 36h 36m ago, live in production
mason/forge:mason/17351-the-edge-kept-duty-files-one-owner-findi → main 0 commits fork
4 files
changed +211
−72
docs/features/maintenance-duties.md +1 −1
Diff not shown — a line 2,415 characters wide (limit 2,000). +1 −1
View filesrc/maintain/duties/edge_kept.ts +68 −45
| @@ -2,10 +2,11 @@ | ||
| 2 | 2 | * Is the edge keeping the pages the forge marks shareable (#14663)? Hourly, GET the forge's own |
| 3 | 3 | * public `/` and `/explore` signed out, twice each (no cookie is sent). When the forge marked the |
| 4 | 4 | * answer shareable (`sharedCache`, `http/edge_cache.ts`) and both answers show the edge went to |
| 5 | * the forge, file one issue per page: the page, the header seen, and the one fix (an edge cache | |
| 6 | * rule for signed-out HTML keyed on EDGE_VARY). A forge with no edge header says nothing. The | |
| 7 | * URL is `config.url` only, never a host from a request; two small requests a page an hour. Where | |
| 8 | * the forge's gate refuses the host (`X-Forge-Egress: refused`) the answer is unknown and silent. | |
| 5 | * the forge, file one issue for every page: a box a page with the header seen, and the one fix (an | |
| 6 | * edge cache rule for signed-out HTML keyed on EDGE_VARY). A forge with no edge header says | |
| 7 | * nothing. The URL is `config.url` only, never a host from a request; two small requests a page an | |
| 8 | * hour. Where the forge's gate refuses the host (`X-Forge-Egress: refused`) the answer is unknown | |
| 9 | * and silent. | |
| 9 | 10 | * |
| 10 | 11 | * A forge in a cell (hosted as an app) does not read its own public host at all: the call is a |
| 11 | 12 | * hairpin through the uplink its gate refuses, one refusal a page an hour (#15350), and the local |
| @@ -13,14 +14,14 @@ | ||
| 13 | 14 | */ |
| 14 | 15 | |
| 15 | 16 | import { fileIssueOnce } from "../../checks/flake.ts"; |
| 16 | import { addComment, setAssignee, setIssueState } from "../../core/issues.ts"; | |
| 17 | import { addComment, setAssignee, setIssueState, updateIssueText } from "../../core/issues.ts"; | |
| 17 | 18 | import { getRepo } from "../../core/repos.ts"; |
| 18 | 19 | import { ownRepoPath } from "../../kernel/own_repo.ts"; |
| 19 | 20 | import { cellProxy } from "../../apps/egress.ts"; |
| 20 | 21 | import type { Duty, Finding } from "../duty.ts"; |
| 21 | import { bothKept, edgeHeader, edgeRule, edgeVerdict, findingFor, marked, PATHS, title } from "../edge_kept.ts"; | |
| 22 | import { bothKept, edgeHeader, edgeVerdict, findingBody, findingFor, legacyFindingFor, marked, PATHS, TITLE, tickedPaths, type PageRead } from "../edge_kept.ts"; | |
| 22 | 23 | |
| 23 | export { PATHS, title }; | |
| 24 | export { PATHS, TITLE }; | |
| 24 | 25 | const TIMEOUT_MS = 8_000; |
| 25 | 26 | |
| 26 | 27 | /** One signed-out GET; the test hands in its own. */ |
| @@ -32,13 +33,6 @@ const get: Get = async (url) => { | ||
| 32 | 33 | return res.headers.has("x-forge-egress") || res.status !== 200 ? undefined : res.headers; |
| 33 | 34 | }; |
| 34 | 35 | |
| 35 | const body = (path: string, seen: string): string => | |
| 36 | `A signed-out GET of ${path} was marked shareable by the forge (\`Cache-Control: public, s-maxage\`), but twice in a row the edge did not serve it from its copy (${seen}).\n\n` + | |
| 37 | "This is the owner's to do; a builder has nothing to change here.\n\n" + | |
| 38 | "The one fix is the owner's, outside this repository: set this edge cache rule (copy it as it stands):\n\n" + | |
| 39 | `\`\`\`\n${edgeRule()}\n\`\`\`\n\n` + | |
| 40 | "This issue is filed once per page. The hourly duty `edge-kept` checks again and closes it when both reads of a run are served from the edge."; | |
| 41 | ||
| 42 | 36 | /** Whether this forge runs in a cell (hosted as an app): its way out is its parent's gate. */ |
| 43 | 37 | const inACell = (): boolean => cellProxy() !== undefined; |
| 44 | 38 | |
| @@ -55,61 +49,90 @@ export function edgeKept(read: Get = get, inCell: () => boolean = inACell): Duty | ||
| 55 | 49 | // A finding is the owner's from the moment it exists, whether or not this run reads the edge. |
| 56 | 50 | // One the crew handed a builder is taken back: a builder has nothing to change (#17344). A |
| 57 | 51 | // finding a person assigned to another person is left alone. |
| 58 | if (repo !== undefined) | |
| 59 | for (const path of PATHS) { | |
| 60 | const issue = findingFor(db, repo, path); | |
| 61 | const unowned = issue !== undefined && (issue.assigneeId === null || issue.assigneeIsAgent); | |
| 62 | if (unowned && setAssignee(db, issue.id, repo.ownerId) !== undefined) | |
| 63 | actions.push(`assigned #${String(issue.number)} to the owner, whose fix it is`); | |
| 64 | } | |
| 52 | const own = (issue: ReturnType<typeof findingFor>): void => { | |
| 53 | if (repo === undefined || issue === undefined) return; | |
| 54 | const unowned = issue.assigneeId === null || issue.assigneeIsAgent; | |
| 55 | if (unowned && setAssignee(db, issue.id, repo.ownerId) !== undefined) actions.push(`assigned #${String(issue.number)} to the owner, whose fix it is`); | |
| 56 | }; | |
| 57 | if (repo !== undefined) { | |
| 58 | own(findingFor(db, repo)); | |
| 59 | for (const path of PATHS) own(legacyFindingFor(db, repo, path)); | |
| 60 | } | |
| 65 | 61 | const url = app?.config.url; |
| 66 | 62 | if (url === undefined || url === "") return { findings: [], actions: [...actions, "skipped: this forge does not know its public origin (FORGE_URL)"] }; |
| 67 | 63 | const origin = new URL(url); |
| 68 | 64 | if (inCell()) return { findings: [], actions: [...actions, `skipped: this forge runs in a cell and does not call its own host ${origin.host}; the edge goes unread (#15350)`] }; |
| 65 | const reads: PageRead[] = []; | |
| 66 | const judged = new Map<string, boolean>(); | |
| 67 | let probe: Finding["probe"] | undefined; | |
| 68 | const before = repo === undefined ? undefined : findingFor(db, repo); | |
| 69 | const prior = before === undefined ? new Set<string>() : tickedPaths(before.body); | |
| 69 | 70 | for (const path of PATHS) { |
| 70 | 71 | const at = new URL(path, origin).href; |
| 72 | // A page this run could not judge keeps the box it had. | |
| 73 | const unjudged = (why: string): void => { | |
| 74 | actions.push(`${path}: ${why}`); | |
| 75 | reads.push({ path, kept: prior.has(path), seen: why }); | |
| 76 | }; | |
| 71 | 77 | let first: Headers | undefined; |
| 72 | 78 | let second: Headers | undefined; |
| 73 | 79 | try { |
| 74 | 80 | first = await read(at); |
| 75 | 81 | second = first === undefined ? undefined : await read(at); |
| 76 | 82 | } catch (e) { |
| 77 | actions.push(`${path}: not read: ${e instanceof Error ? e.name : "error"}`); | |
| 83 | unjudged(`not read: ${e instanceof Error ? e.name : "error"}`); | |
| 78 | 84 | continue; |
| 79 | 85 | } |
| 80 | 86 | if (first === undefined || second === undefined) { |
| 81 | actions.push(`${path}: no plain 200 answer; nothing judged`); | |
| 87 | unjudged("no plain 200 answer; nothing judged"); | |
| 82 | 88 | continue; |
| 83 | 89 | } |
| 84 | 90 | if (!marked(second)) { |
| 85 | actions.push(`${path}: the forge did not mark it shareable; nothing judged`); | |
| 91 | unjudged("the forge did not mark it shareable; nothing judged"); | |
| 86 | 92 | continue; |
| 87 | 93 | } |
| 88 | 94 | const verdict = edgeVerdict(first, second); |
| 89 | 95 | const seen = edgeHeader(second) ?? "no edge header"; |
| 90 | 96 | actions.push(`${path}: ${verdict} (${seen})`); |
| 91 | if (verdict === "kept" && repo !== undefined && bothKept(first, second)) { | |
| 92 | const issue = findingFor(db, repo, path); | |
| 93 | if (issue !== undefined) { | |
| 94 | addComment(db, { issueId: issue.id, authorId: repo.ownerId, body: `Both reads of ${path} were served from the edge (${seen}); the rule is in. Closing this finding.` }); | |
| 95 | setIssueState(db, issue.id, "closed"); | |
| 96 | actions.push(`${path}: closed issue #${String(issue.number)}, the edge keeps it`); | |
| 97 | } | |
| 98 | } | |
| 99 | if (verdict !== "not") continue; | |
| 100 | const summary = `${path} is marked shareable but the edge did not keep it (${seen})`; | |
| 101 | const probe = { kind: "measurement", what: `GET ${origin.origin}${path} twice, signed out: 1 is not served from the edge`, number: 1, at: now.toISOString() } as const; | |
| 102 | if (repo === undefined) { | |
| 103 | actions.push(`${path}: not kept, but this forge's own repository is not here to file it in`); | |
| 104 | continue; | |
| 105 | } | |
| 106 | const filed = fileIssueOnce(db, bus, repo, { title: title(path), body: body(path, seen), assigneeId: repo.ownerId }); | |
| 107 | if (filed.opened) { | |
| 108 | findings.push({ summary: `${summary}; filed ${owner}/${name}#${String(filed.number)}`, probe }); | |
| 109 | actions.push(`filed issue #${String(filed.number)}`); | |
| 110 | } else if (filed.number === 0) actions.push(`${path}: not kept, and the issue could not be filed`); | |
| 111 | else actions.push(`already filed as issue #${String(filed.number)}`); | |
| 97 | const kept = bothKept(first, second); | |
| 98 | judged.set(path, kept); | |
| 99 | reads.push({ path, kept, seen }); | |
| 100 | if (verdict === "not" && probe === undefined) probe = { kind: "measurement", what: `GET ${origin.origin}${path} twice, signed out: 1 is not served from the edge`, number: 1, at: now.toISOString() }; | |
| 112 | 101 | } |
| 102 | if (repo !== undefined) { | |
| 103 | const everyKept = judged.size === PATHS.length && [...judged.values()].every(Boolean); | |
| 104 | let single = before; | |
| 105 | if (before !== undefined && everyKept) { | |
| 106 | addComment(db, { issueId: before.id, authorId: repo.ownerId, body: `Both reads of every page were served from the edge (${reads.map((r) => `${r.path}: ${r.seen}`).join("; ")}); the rule is in. Closing this finding.` }); | |
| 107 | setIssueState(db, before.id, "closed"); | |
| 108 | actions.push(`closed issue #${String(before.number)}, the edge keeps every page`); | |
| 109 | single = undefined; | |
| 110 | } else if (before !== undefined) { | |
| 111 | const text = findingBody(reads); | |
| 112 | if (text !== before.body && updateIssueText(db, before.id, { body: text }).ok) actions.push(`updated the boxes in issue #${String(before.number)}`); | |
| 113 | else actions.push(`already filed as issue #${String(before.number)}`); | |
| 114 | } else if (probe !== undefined) { | |
| 115 | const filed = fileIssueOnce(db, bus, repo, { title: TITLE, body: findingBody(reads), assigneeId: repo.ownerId }); | |
| 116 | if (filed.opened) { | |
| 117 | const notKept = reads.filter((r) => !r.kept).map((r) => `${r.path} (${r.seen})`).join(", "); | |
| 118 | findings.push({ summary: `${notKept} are marked shareable but the edge did not keep them; filed ${owner}/${name}#${String(filed.number)}`, probe }); | |
| 119 | actions.push(`filed issue #${String(filed.number)}`); | |
| 120 | single = findingFor(db, repo); | |
| 121 | } else actions.push("the not-kept pages could not be filed"); | |
| 122 | } | |
| 123 | for (const path of PATHS) { | |
| 124 | const old = legacyFindingFor(db, repo, path); | |
| 125 | if (old === undefined) continue; | |
| 126 | if (single === undefined && !everyKept) { | |
| 127 | actions.push(`left per-page issue #${String(old.number)} open: this run judged no page kept and could not name the single finding`); | |
| 128 | continue; | |
| 129 | } | |
| 130 | const named = single === undefined ? "the edge keeps every page now, so there is no finding to name" : `it is now filed once for every page as #${String(single.number)}`; | |
| 131 | addComment(db, { issueId: old.id, authorId: repo.ownerId, body: `This per-page finding is folded: ${named}. Closing it.` }); | |
| 132 | setIssueState(db, old.id, "closed"); | |
| 133 | actions.push(`closed per-page issue #${String(old.number)}${single === undefined ? "" : `, folded into #${String(single.number)}`}`); | |
| 134 | } | |
| 135 | } else if (probe !== undefined) actions.push("not kept, but this forge's own repository is not here to file it in"); | |
| 113 | 136 | return { findings, actions }; |
| 114 | 137 | }, |
| 115 | 138 | }; |
src/maintain/edge_kept.ts +49 −10
| @@ -50,7 +50,13 @@ export function edgeVerdict(first: Headers, second: Headers): Kept { | ||
| 50 | 50 | /** The pages the duty reads. */ |
| 51 | 51 | export const PATHS = ["/", "/explore"] as const; |
| 52 | 52 | |
| 53 | export const title = (path: string): string => `The edge is not keeping ${path}, which the forge marks shareable`; | |
| 53 | /** | |
| 54 | * The one finding's title: the same on every run, since `fileIssueOnce` matches the exact title. | |
| 55 | */ | |
| 56 | export const TITLE = "The edge is not keeping the pages the forge marks shareable"; | |
| 57 | ||
| 58 | /** The title the duty once filed for each page; open ones are folded into the one finding. */ | |
| 59 | export const legacyTitle = (path: string): string => `The edge is not keeping ${path}, which the forge marks shareable`; | |
| 54 | 60 | |
| 55 | 61 | /** |
| 56 | 62 | * The edge cache rule the owner sets, as one copyable block; the key list is EDGE_VARY, never |
| @@ -69,22 +75,55 @@ export function edgeRule(): string { | ||
| 69 | 75 | /** Both reads of a run were served from the edge's copy: the only reading that closes a finding. */ |
| 70 | 76 | export const bothKept = (first: Headers, second: Headers): boolean => edgeKept(first) === "kept" && edgeKept(second) === "kept"; |
| 71 | 77 | |
| 72 | /** The one way to find the open finding for a page in a repository; undefined when none. */ | |
| 73 | export function findingFor(db: Database, repo: { id: string }, path: string): ReturnType<typeof getIssue> { | |
| 74 | const row = db.query<{ number: number }, [string, string]>("SELECT number FROM issue WHERE repo_id = ?1 AND title = ?2 AND state = 'open' LIMIT 1").get(repo.id, title(path)); | |
| 78 | /** One page's line in the finding: ticked when both reads were served from the edge. */ | |
| 79 | export interface PageRead { | |
| 80 | readonly path: string; | |
| 81 | readonly kept: boolean; | |
| 82 | /** The header seen, or what stopped the read. */ | |
| 83 | readonly seen: string; | |
| 84 | } | |
| 85 | ||
| 86 | const box = (r: PageRead): string => `- [${r.kept ? "x" : " "}] \`${r.path}\`: ${r.seen}`; | |
| 87 | ||
| 88 | /** The finding's text: the rule exactly as the owner copies it, and a box for each page. */ | |
| 89 | export function findingBody(reads: readonly PageRead[]): string { | |
| 90 | return ( | |
| 91 | "Signed-out GETs of these pages are marked shareable by the forge (`Cache-Control: public, s-maxage`), but the edge did not serve them from its copy. A box is ticked when both reads of that page were served from the edge; the header seen is beside it.\n\n" + | |
| 92 | `${reads.map(box).join("\n")}\n\n` + | |
| 93 | "This is the owner's to do; a builder has nothing to change here.\n\n" + | |
| 94 | "The one fix is the owner's, outside this repository: set this edge cache rule (copy it as it stands):\n\n" + | |
| 95 | `\`\`\`\n${edgeRule()}\n\`\`\`\n\n` + | |
| 96 | "This is the one finding for every page, filed once. The hourly duty `edge-kept` checks again, updates the boxes, and closes it when every page is served from the edge." | |
| 97 | ); | |
| 98 | } | |
| 99 | ||
| 100 | /** The paths a finding's body shows ticked. */ | |
| 101 | export function tickedPaths(body: string): Set<string> { | |
| 102 | return new Set([...body.matchAll(/^- \[x\] `([^`]+)`/gm)].map((m) => m[1]!)); | |
| 103 | } | |
| 104 | ||
| 105 | /** The one way to find the open finding in a repository; undefined when none. */ | |
| 106 | export function findingFor(db: Database, repo: { id: string }): ReturnType<typeof getIssue> { | |
| 107 | return openByTitle(db, repo, TITLE); | |
| 108 | } | |
| 109 | ||
| 110 | /** An open per-page finding from before the single one, for one page; undefined when none. */ | |
| 111 | export function legacyFindingFor(db: Database, repo: { id: string }, path: string): ReturnType<typeof getIssue> { | |
| 112 | return openByTitle(db, repo, legacyTitle(path)); | |
| 113 | } | |
| 114 | ||
| 115 | function openByTitle(db: Database, repo: { id: string }, wanted: string): ReturnType<typeof getIssue> { | |
| 116 | const row = db.query<{ number: number }, [string, string]>("SELECT number FROM issue WHERE repo_id = ?1 AND title = ?2 AND state = 'open' LIMIT 1").get(repo.id, wanted); | |
| 75 | 117 | return row === null ? undefined : getIssue(db, repo.id, row.number); |
| 76 | 118 | } |
| 77 | 119 | |
| 78 | 120 | /** |
| 79 | * The open finding for any page in this forge's own repository, for a link; undefined when none. | |
| 121 | * The open finding in this forge's own repository, for a link; undefined when none. | |
| 80 | 122 | */ |
| 81 | 123 | export function openFinding(db: Database): { number: number; repo: string } | undefined { |
| 82 | 124 | const [owner = "", name = ""] = ownRepoPath().split("/"); |
| 83 | 125 | const repo = getRepo(db, owner, name); |
| 84 | 126 | if (repo === undefined) return undefined; |
| 85 | for (const path of PATHS) { | |
| 86 | const issue = findingFor(db, repo, path); | |
| 87 | if (issue !== undefined) return { number: issue.number, repo: `${owner}/${name}` }; | |
| 88 | } | |
| 89 | return undefined; | |
| 127 | const issue = findingFor(db, repo); | |
| 128 | return issue === undefined ? undefined : { number: issue.number, repo: `${owner}/${name}` }; | |
| 90 | 129 | } |
test/maintain-edge-kept.test.ts +93 −16
| @@ -6,8 +6,8 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 6 | 6 | import { startMaintain } from "../src/maintain/runner.ts"; |
| 7 | 7 | import { latest } from "../src/maintain/runs.ts"; |
| 8 | 8 | import { duties } from "../src/maintain/registry.ts"; |
| 9 | import { edgeKept as edgeDuty, PATHS, title, type Get } from "../src/maintain/duties/edge_kept.ts"; | |
| 10 | import { edgeKept, edgeRule, edgeVerdict, marked, openFinding } from "../src/maintain/edge_kept.ts"; | |
| 9 | import { edgeKept as edgeDuty, PATHS, TITLE, type Get } from "../src/maintain/duties/edge_kept.ts"; | |
| 10 | import { edgeKept, edgeRule, edgeVerdict, legacyTitle, marked, openFinding } from "../src/maintain/edge_kept.ts"; | |
| 11 | 11 | import { EDGE_VARY, sharedCache } from "../src/http/edge_cache.ts"; |
| 12 | 12 | import { createUser, getUserById } from "../src/core/users.ts"; |
| 13 | 13 | import { serve } from "../src/http/server.ts"; |
| @@ -15,7 +15,7 @@ import { Session } from "../src/tui/session.ts"; | ||
| 15 | 15 | import { dutyLines } from "../src/tui/screens/dutyswitch.ts"; |
| 16 | 16 | import { createRepo } from "../src/actions/repos.ts"; |
| 17 | 17 | import { createAgent } from "../src/actions/crew.ts"; |
| 18 | import { getIssue } from "../src/core/issues.ts"; | |
| 18 | import { createIssue, getIssue } from "../src/core/issues.ts"; | |
| 19 | 19 | import { getRepo } from "../src/core/repos.ts"; |
| 20 | 20 | import { agentFor } from "../src/crew/dispatch.ts"; |
| 21 | 21 | import { ownRepoPath } from "../src/kernel/own_repo.ts"; |
| @@ -83,16 +83,16 @@ test("in a cell it never reads its own public host, and says the edge went unrea | ||
| 83 | 83 | expect(r.actions).toEqual(["skipped: this forge runs in a cell and does not call its own host forge.example; the edge goes unread (#15350)"]); |
| 84 | 84 | }); |
| 85 | 85 | |
| 86 | test("not kept files one issue per page, and a second run adds nothing", async () => { | |
| 86 | test("not kept files one issue for every page, and a second run adds nothing", async () => { | |
| 87 | 87 | const { app, once } = await run(shareable({ "cf-cache-status": "DYNAMIC" })); |
| 88 | 88 | const first = await once(); |
| 89 | expect(first.findings.length).toBe(2); | |
| 89 | expect(first.findings.length).toBe(1); | |
| 90 | 90 | expect(first.findings[0]!.summary).toContain("cf-cache-status: DYNAMIC"); |
| 91 | 91 | const second = await once(); |
| 92 | 92 | expect(second.findings).toEqual([]); |
| 93 | const n = app.db.query("SELECT COUNT(*) AS n FROM issue WHERE title = ?1").get(title("/")) as { n: number }; | |
| 93 | const n = app.db.query("SELECT COUNT(*) AS n FROM issue WHERE title = ?1").get(TITLE) as { n: number }; | |
| 94 | 94 | expect(n.n).toBe(1); |
| 95 | const body = app.db.query("SELECT body FROM issue WHERE title = ?1").get(title("/")) as { body: string }; | |
| 95 | const body = app.db.query("SELECT body FROM issue WHERE title = ?1").get(TITLE) as { body: string }; | |
| 96 | 96 | for (const v of EDGE_VARY.split(",")) expect(body.body).toContain(`- ${v.trim()}`); |
| 97 | 97 | expect(body.body).toContain("respect origin"); |
| 98 | 98 | expect(body.body).toContain("```"); |
| @@ -103,7 +103,7 @@ test("a new filing is assigned to the owner, says so, and the crew starts no run | ||
| 103 | 103 | await once(); |
| 104 | 104 | const [owner = "", name = ""] = ownRepoPath().split("/"); |
| 105 | 105 | const repo = getRepo(app.db, owner, name)!; |
| 106 | const row = app.db.query("SELECT number FROM issue WHERE title = ?1").get(title("/")) as { number: number }; | |
| 106 | const row = app.db.query("SELECT number FROM issue WHERE title = ?1").get(TITLE) as { number: number }; | |
| 107 | 107 | const issue = getIssue(app.db, repo.id, row.number)!; |
| 108 | 108 | expect(issue.assigneeId).toBe(repo.ownerId); |
| 109 | 109 | expect(issue.body).toContain("owner's to do; a builder has nothing to change here"); |
| @@ -115,10 +115,10 @@ test("an open filing with no assignee is assigned to the owner, once, with an ac | ||
| 115 | 115 | await once(); |
| 116 | 116 | const [owner = "", name = ""] = ownRepoPath().split("/"); |
| 117 | 117 | const repo = getRepo(app.db, owner, name)!; |
| 118 | app.db.query("UPDATE issue SET assignee_id = NULL WHERE title = ?1").run(title("/")); | |
| 118 | app.db.query("UPDATE issue SET assignee_id = NULL WHERE title = ?1").run(TITLE); | |
| 119 | 119 | const r = await once(); |
| 120 | 120 | expect(r.actions.some((a) => a.includes("to the owner, whose fix it is"))).toBe(true); |
| 121 | const row = app.db.query("SELECT number FROM issue WHERE title = ?1").get(title("/")) as { number: number }; | |
| 121 | const row = app.db.query("SELECT number FROM issue WHERE title = ?1").get(TITLE) as { number: number }; | |
| 122 | 122 | expect(getIssue(app.db, repo.id, row.number)?.assigneeId).toBe(repo.ownerId); |
| 123 | 123 | expect((await once()).actions.some((a) => a.includes("to the owner, whose fix it is"))).toBe(false); |
| 124 | 124 | }); |
| @@ -129,7 +129,7 @@ test("an unassigned finding is the owner's even when the run skips (no FORGE_URL | ||
| 129 | 129 | const { app, once } = await run(shareable({ "cf-cache-status": "DYNAMIC" })); |
| 130 | 130 | await once(); |
| 131 | 131 | const repo = getRepo(app.db, owner, name)!; |
| 132 | const num = (app.db.query("SELECT number FROM issue WHERE title = ?1").get(title("/")) as { number: number }).number; | |
| 132 | const num = (app.db.query("SELECT number FROM issue WHERE title = ?1").get(TITLE) as { number: number }).number; | |
| 133 | 133 | app.db.query("UPDATE issue SET assignee_id = NULL WHERE repo_id = ?1").run(repo.id); |
| 134 | 134 | const skipped = edgeDuty(async () => undefined, () => inCell); |
| 135 | 135 | const r = await skipped.run({ db: app.db, bus: app.bus, now: new Date(), app: { ...app, config: { ...app.config, url } } as App }); |
| @@ -145,7 +145,7 @@ test("an unassigned finding is the owner's even when the run skips (no FORGE_URL | ||
| 145 | 145 | app.db.query("UPDATE issue SET assignee_id = ?1").run(other.value.id); |
| 146 | 146 | const r = await once(); |
| 147 | 147 | expect(r.actions.some((a) => a.includes("to the owner"))).toBe(false); |
| 148 | expect(app.db.query("SELECT COUNT(*) AS n FROM issue WHERE assignee_id = ?1").get(other.value.id)).toEqual({ n: 2 }); | |
| 148 | expect(app.db.query("SELECT COUNT(*) AS n FROM issue WHERE assignee_id = ?1").get(other.value.id)).toEqual({ n: 1 }); | |
| 149 | 149 | expect(repo.ownerId).not.toBe(other.value.id); |
| 150 | 150 | }); |
| 151 | 151 | |
| @@ -157,7 +157,7 @@ test("a finding the crew's picker handed a builder is the owner's again on the n | ||
| 157 | 157 | const root = getUserById(app.db, repo.ownerId)!; |
| 158 | 158 | const made = await createAgent(app, root, { username: "builder" }); |
| 159 | 159 | if (!made.ok) throw new Error(String(made.error)); |
| 160 | const num = (app.db.query("SELECT number FROM issue WHERE title = ?1").get(title("/")) as { number: number }).number; | |
| 160 | const num = (app.db.query("SELECT number FROM issue WHERE title = ?1").get(TITLE) as { number: number }).number; | |
| 161 | 161 | // What production showed: the picker put a builder's name on it over the owner's. |
| 162 | 162 | app.db.query("UPDATE issue SET assignee_id = ?1 WHERE repo_id = ?2").run(made.value.user.id, repo.id); |
| 163 | 163 | const skipped = edgeDuty(async () => undefined, () => true); |
| @@ -198,14 +198,14 @@ test("a run through the maintainer lands its action lines where /maintenance run | ||
| 198 | 198 | const row = latest(app.db, 10).find((r) => r.duty === "edge-kept"); |
| 199 | 199 | expect(row?.outcome).toBe("ok"); |
| 200 | 200 | expect(row?.actions.some((a) => a.startsWith("/: not (cf-cache-status: DYNAMIC)"))).toBe(true); |
| 201 | expect(row?.findings.length).toBe(2); | |
| 201 | expect(row?.findings.length).toBe(1); | |
| 202 | 202 | }); |
| 203 | 203 | |
| 204 | 204 | test("a page kept on both reads closes the open finding with a comment naming the header; the action says kept (#17016)", async () => { |
| 205 | 205 | let edge = "DYNAMIC"; |
| 206 | 206 | const { app, once } = await run(async () => h({ "cache-control": "public, s-maxage=60", "cf-cache-status": edge })); |
| 207 | 207 | await once(); |
| 208 | const state = () => (app.db.query("SELECT state FROM issue WHERE title = ?1").get(title("/")) as { state: string }).state; | |
| 208 | const state = () => (app.db.query("SELECT state FROM issue WHERE title = ?1").get(TITLE) as { state: string }).state; | |
| 209 | 209 | expect(state()).toBe("open"); |
| 210 | 210 | edge = "HIT"; |
| 211 | 211 | const r = await once(); |
| @@ -219,7 +219,7 @@ test("a page still not kept, or kept on one read only, leaves the finding open", | ||
| 219 | 219 | const { app, once } = await run(shareable({ "cf-cache-status": "DYNAMIC" })); |
| 220 | 220 | await once(); |
| 221 | 221 | await once(); |
| 222 | const state = () => (app.db.query("SELECT state FROM issue WHERE title = ?1").get(title("/")) as { state: string }).state; | |
| 222 | const state = () => (app.db.query("SELECT state FROM issue WHERE title = ?1").get(TITLE) as { state: string }).state; | |
| 223 | 223 | expect(state()).toBe("open"); |
| 224 | 224 | const heads = [cf("MISS"), cf("HIT")].map((x) => new Headers({ "cache-control": "public, s-maxage=60", "cf-cache-status": x.get("cf-cache-status")! })); |
| 225 | 225 | let i = 0; |
| @@ -265,3 +265,80 @@ test("/maintenance and the terminal link the open finding, and stop once it is c | ||
| 265 | 265 | servers.stop(); |
| 266 | 266 | } |
| 267 | 267 | }); |
| 268 | ||
| 269 | const heads = (edge: Record<string, string>): Headers => h({ "cache-control": "public, s-maxage=60", ...edge }); | |
| 270 | const byPath = (kept: (path: string) => boolean): Get => async (u) => heads({ "cf-cache-status": kept(new URL(u).pathname) ? "HIT" : "DYNAMIC" }); | |
| 271 | const issues = (app: App) => app.db.query("SELECT title, body, state, assignee_id FROM issue ORDER BY number").all() as { title: string; body: string; state: string; assignee_id: string }[]; | |
| 272 | ||
| 273 | test("two unkept paths give one issue with two unticked boxes, assigned to the owner, rule text intact", async () => { | |
| 274 | const { app, once } = await run(byPath(() => false)); | |
| 275 | await once(); | |
| 276 | const all = issues(app); | |
| 277 | expect(all.length).toBe(1); | |
| 278 | expect(all[0]!.title).toBe(TITLE); | |
| 279 | expect(all[0]!.body).toContain("- [ ] `/`: cf-cache-status: DYNAMIC"); | |
| 280 | expect(all[0]!.body).toContain("- [ ] `/explore`: cf-cache-status: DYNAMIC"); | |
| 281 | expect(all[0]!.body).toContain(edgeRule()); | |
| 282 | const repo = getRepo(app.db, ...(ownRepoPath().split("/") as [string, string]))!; | |
| 283 | expect(all[0]!.assignee_id).toBe(repo.ownerId); | |
| 284 | await once(); | |
| 285 | expect(issues(app).length).toBe(1); | |
| 286 | }); | |
| 287 | ||
| 288 | test("one kept and one unkept gives one ticked box and one unticked, updated in place; all kept closes it with one comment", async () => { | |
| 289 | let keptPaths = ["/"]; | |
| 290 | const { app, once } = await run(byPath((p) => keptPaths.includes(p))); | |
| 291 | await once(); | |
| 292 | expect(issues(app).length).toBe(1); | |
| 293 | expect(issues(app)[0]!.body).toContain("- [x] `/`: cf-cache-status: HIT"); | |
| 294 | expect(issues(app)[0]!.body).toContain("- [ ] `/explore`: cf-cache-status: DYNAMIC"); | |
| 295 | keptPaths = ["/explore"]; | |
| 296 | const r = await once(); | |
| 297 | expect(issues(app).length).toBe(1); | |
| 298 | expect(issues(app)[0]!.body).toContain("- [ ] `/`: cf-cache-status: DYNAMIC"); | |
| 299 | expect(issues(app)[0]!.body).toContain("- [x] `/explore`: cf-cache-status: HIT"); | |
| 300 | expect(r.actions.some((a) => a.startsWith("updated the boxes in issue #"))).toBe(true); | |
| 301 | keptPaths = ["/", "/explore"]; | |
| 302 | const done = await once(); | |
| 303 | expect(issues(app).length).toBe(1); | |
| 304 | expect(issues(app)[0]!.state).toBe("closed"); | |
| 305 | expect((app.db.query("SELECT COUNT(*) AS n FROM comment").get() as { n: number }).n).toBe(1); | |
| 306 | expect(done.actions.some((a) => a.includes("the edge keeps every page"))).toBe(true); | |
| 307 | }); | |
| 308 | ||
| 309 | test("open per-page findings are closed with a comment naming the single finding, on the first run", async () => { | |
| 310 | const { app, once } = await run(byPath(() => false)); | |
| 311 | const repo = getRepo(app.db, ...(ownRepoPath().split("/") as [string, string]))!; | |
| 312 | for (const path of PATHS) createIssue(app.db, { repoId: repo.id, authorId: repo.ownerId, title: legacyTitle(path), body: "old" }); | |
| 313 | await once(); | |
| 314 | const all = issues(app); | |
| 315 | expect(all.map((i) => i.state)).toEqual(["closed", "closed", "open"]); | |
| 316 | const single = (app.db.query("SELECT number FROM issue WHERE title = ?1").get(TITLE) as { number: number }).number; | |
| 317 | const comments = app.db.query("SELECT body FROM comment").all() as { body: string }[]; | |
| 318 | expect(comments.length).toBe(2); | |
| 319 | for (const c of comments) expect(c.body).toContain(`#${String(single)}`); | |
| 320 | await once(); | |
| 321 | expect((app.db.query("SELECT COUNT(*) AS n FROM comment").get() as { n: number }).n).toBe(2); | |
| 322 | }); | |
| 323 | ||
| 324 | test("a legacy per-page finding stays open when the run judged nothing, with an action line saying so", async () => { | |
| 325 | const { app, once } = await run(async () => undefined); | |
| 326 | const repo = getRepo(app.db, ...(ownRepoPath().split("/") as [string, string]))!; | |
| 327 | for (const path of PATHS) createIssue(app.db, { repoId: repo.id, authorId: repo.ownerId, title: legacyTitle(path), body: "old" }); | |
| 328 | const r = await once(); | |
| 329 | expect(issues(app).map((i) => i.state)).toEqual(["open", "open"]); | |
| 330 | expect((app.db.query("SELECT COUNT(*) AS n FROM comment").get() as { n: number }).n).toBe(0); | |
| 331 | expect(r.actions.filter((a) => a.startsWith("left per-page issue #")).length).toBe(2); | |
| 332 | }); | |
| 333 | ||
| 334 | test("a page this run could not judge keeps the box it had", async () => { | |
| 335 | let blind = false; | |
| 336 | const kept = byPath((p) => p === "/"); | |
| 337 | const { app, once } = await run(async (u) => (blind && new URL(u).pathname === "/" ? undefined : kept(u))); | |
| 338 | await once(); | |
| 339 | expect(issues(app)[0]!.body).toContain("- [x] `/`:"); | |
| 340 | blind = true; | |
| 341 | await once(); | |
| 342 | expect(issues(app)[0]!.body).toContain("- [x] `/`:"); | |
| 343 | expect(issues(app)[0]!.body).toContain("- [ ] `/explore`:"); | |
| 344 | }); |
new above
offline