From dc980333212c5f027132d49319976eb7c1556481 Mon Sep 17 00:00:00 2001 From: Nam Rodriguez Date: Fri, 13 Nov 2026 18:21:01 -0500 Subject: [PATCH] Infrastructure: a closed fix pull request says who closed it, and the fix is offered again On the Infrastructure tab a finding kept the link to its pull request after a person closed it, with the bare word "closed" and no button, so the fix could not be asked for again. - The row says who closed the pull request and when, and that a new one can be opened. - "Open fix PR" shows again for an open finding whose pull request was closed without merging. An open, merged or draft pull request, and a finding that fell back to its runbook, get no button, as before. - `closedWords` takes any pull request record with the closed fields, so both tabs word it the same way. --- dashboard/e2e/infra-security.spec.ts | 50 ++++++++++++++++++- .../src/app/security/infrastructure/page.tsx | 16 ++++-- dashboard/src/lib/infra-security.ts | 11 +++- dashboard/src/lib/security.ts | 2 +- 4 files changed, 73 insertions(+), 6 deletions(-) diff --git a/dashboard/e2e/infra-security.spec.ts b/dashboard/e2e/infra-security.spec.ts index f9d8fbb9..f560829e 100644 --- a/dashboard/e2e/infra-security.spec.ts +++ b/dashboard/e2e/infra-security.spec.ts @@ -1,6 +1,6 @@ import { expect, test, type Page, type Route } from "@playwright/test"; import { shoot } from "./infra-shots"; -import { ACCOUNT_MISSING, INFRA_FEEDS, INFRA_INSIGHTS, INFRA_RESOURCES, infraFinding, infraOverview } from "./infra-data"; +import { ACCOUNT_MISSING, INFRA_FEEDS, INFRA_INSIGHTS, INFRA_RESOURCES, infraFinding, infraOverview, iso } from "./infra-data"; // Infrastructure vulnerabilities: Security › Infrastructure grouped by fix // (pull requests, runbook cards, AWS-managed rows collapsed at the bottom), @@ -139,6 +139,54 @@ test.describe("Infrastructure vulnerabilities", () => { expect(call(db, "POST /api/security/infrastructure/check")).toHaveLength(1); }); + test("a pull request a person closed shows who closed it and when, and the fix is offered again", async ({ page }) => { + const closed = { number: 412, url: "https://github.com/acme/infra/pull/412", state: "closed", closed_at: iso(-3), closed_by: "octo", closed_by_person: true }; + const ng = infraFinding({ id: "f_ng", name: "prod-ng", title: "EKS node group prod-ng runs v20261015 (fixed in v20261031)", tier: "P2", status: "open", pr: closed }); + const db = await mockApi(page, { overview: infraOverview({ findings: [ng] }) }); + await page.goto("/security/infrastructure"); + const row = page.getByRole("list", { name: "Infrastructure findings" }).getByTestId("infra-row"); + await expect(row).toHaveCount(1); + await expect(row.getByTestId("infra-pr")).toHaveAttribute("href", "https://github.com/acme/infra/pull/412"); + await expect(row.getByTestId("infra-pr")).toHaveText(/PR #412\s*closed by octo on \w+ \d+/); + await expect(row.getByTestId("infra-pr-closed")).toHaveText(/PR #412 was closed by octo on \w+ \d+ without merging\. Open a new one when you want the fix/); + // The fix is offered again, and asking starts it. + await expect(row.getByTestId("infra-fix")).toHaveText("Open fix PR"); + await row.getByTestId("infra-fix").click(); + await expect(row).toContainText("Fix run started."); + await expect(row.getByTestId("infra-pr-closed")).toHaveCount(0); + expect(call(db, "POST /api/security/infrastructure/findings/f_ng/fix")).toHaveLength(1); + + // An older server sends no closer: the page says closed, and still offers the fix. + db.overview = infraOverview({ findings: [{ ...ng, pr: { number: 412, url: closed.url, state: "closed" } }] }); + await page.reload(); + await expect(row.getByTestId("infra-pr-closed")).toHaveText(/^PR #412 was closed without merging\./); + await expect(row.getByTestId("infra-fix")).toBeVisible(); + + // Still open, merged, or held as a draft by the replacement check: the link, no button. + for (const state of ["open", "merged", "draft"]) { + db.overview = infraOverview({ findings: [{ ...ng, status: state === "draft" ? "open" : "pr_open", pr: { number: 412, url: closed.url, state }, fix: { ...ng.fix, kind: state === "draft" ? "runbook" : "pr" } }] }); + await page.reload(); + await expect(page.getByTestId("infra-row")).toHaveCount(1); + await expect(page.getByTestId("infra-fix")).toHaveCount(0); + await expect(page.getByTestId("infra-pr-closed")).toHaveCount(0); + } + + // A closed draft on a finding that fell back to its runbook stays a runbook: no button. + db.overview = infraOverview({ findings: [{ ...ng, pr: closed, fix: { ...ng.fix, kind: "runbook" } }] }); + await page.reload(); + await expect(page.getByTestId("infra-row")).toHaveCount(1); + await expect(page.getByTestId("infra-fix")).toHaveCount(0); + await expect(page.getByTestId("infra-pr-closed")).toHaveCount(0); + }); + + test("a member sees who closed the pull request and no button", async ({ page }) => { + const closed = { number: 412, url: "https://github.com/acme/infra/pull/412", state: "closed", closed_at: iso(-3), closed_by: "octo", closed_by_person: true }; + await mockApi(page, { role: "member", overview: infraOverview({ findings: [infraFinding({ id: "f_ng", name: "prod-ng", status: "open", pr: closed })] }) }); + await page.goto("/security/infrastructure"); + await expect(page.getByTestId("infra-pr-closed")).toContainText("An admin can open a new one."); + await expect(page.getByTestId("infra-fix")).toHaveCount(0); + }); + test("an account switched on without the reads warns, naming the feature, with the one-click update", async ({ page }) => { await mockApi(page, { overview: infraOverview({ accounts: [...infraOverview().accounts, ACCOUNT_MISSING] }) }); await page.goto("/security/infrastructure"); diff --git a/dashboard/src/app/security/infrastructure/page.tsx b/dashboard/src/app/security/infrastructure/page.tsx index e2490f83..e21916e9 100644 --- a/dashboard/src/app/security/infrastructure/page.tsx +++ b/dashboard/src/app/security/infrastructure/page.tsx @@ -22,7 +22,7 @@ import { Disclosure } from "@/components/disclosure"; import { AwsIcon } from "@/components/icons"; import { Chip, List, ListRow, ListSkeleton, StatusToggles, Time, type Tone } from "@/components/list"; import { linkButton, primaryButton, smallSecondaryButton } from "@/components/ui"; -import { SECURITY_ADMIN, TIERS, type Tier } from "@/lib/security"; +import { SECURITY_ADMIN, TIERS, closedWords, type Tier } from "@/lib/security"; import { INFRA_STATUS_LOOK, countWords, @@ -284,7 +284,11 @@ function FindingRow({ f, admin, dryRun, defaultOpen }: { f: InfraFinding; admin: } setAsking(false); }; - const prWords = f.pr ? (f.pr.state === "merged" ? "merged, waiting for the new version to run" : f.pr.state) : null; + const closed = f.pr?.state === "closed"; + const prWords = f.pr ? (f.pr.state === "merged" ? "merged, waiting for the new version to run" : closed ? closedWords(f.pr) : f.pr.state) : null; + // A pull request closed without merging is history, not a fix on its way: the fix is offered again. + // (A finding the replacement check moved to its runbook is no longer a "pr" fix, so it gets no button.) + const canAsk = admin && f.fix.kind === "pr" && f.status === "open" && (!f.pr || closed) && !asked; return ( } actions={ - admin && f.fix.kind === "pr" && !f.pr && f.status === "open" && !asked ? ( + canAsk ? ( @@ -329,6 +333,12 @@ function FindingRow({ f, admin, dryRun, defaultOpen }: { f: InfraFinding; admin: details={} detailsFor={`details of ${f.name}`} > + {closed && f.pr && f.status === "open" && f.fix.kind === "pr" && !asked && ( +

+ PR #{f.pr.number} was {closedWords(f.pr)} without merging.{" "} + {admin ? "Open a new one when you want the fix; Coderhelm does not open one by itself for a week after a pull request is closed." : "An admin can open a new one."} +

+ )} {asked &&

{asked}

}
); diff --git a/dashboard/src/lib/infra-security.ts b/dashboard/src/lib/infra-security.ts index 671f227a..677f6e33 100644 --- a/dashboard/src/lib/infra-security.ts +++ b/dashboard/src/lib/infra-security.ts @@ -162,7 +162,16 @@ export interface InfraFinding { tier: Tier | null; fix: InfraFix; status: InfraStatus; - pr: { number: number; url: string; state: "open" | "merged" | "closed" | "draft" } | null; + pr: { + number: number; + url: string; + state: "open" | "merged" | "closed" | "draft"; + /** Closed without merging: when, and who closed it (a GitHub login, or the person who closed its run). Absent while open, and on older servers. */ + closed_at?: string; + closed_by?: string; + /** False when Coderhelm closed it itself. */ + closed_by_person?: boolean; + } | null; inspector?: { exploit_available: boolean; reachable: boolean | null; findings?: number } | null; first_seen_at: string; updated_at: string; diff --git a/dashboard/src/lib/security.ts b/dashboard/src/lib/security.ts index cc227dc5..1d537347 100644 --- a/dashboard/src/lib/security.ts +++ b/dashboard/src/lib/security.ts @@ -551,7 +551,7 @@ export function runsHref(ticket: string): string { } /** "closed by octo on Nov 13": a pull request that closed without merging, with who and when as far as the server knows. */ -export function closedWords(pr: NonNullable): string { +export function closedWords(pr: { closed_at?: string; closed_by?: string; closed_by_person?: boolean }): string { const who = pr.closed_by_person === false ? "Coderhelm" : pr.closed_by; const t = pr.closed_at ? new Date(pr.closed_at).getTime() : NaN; const on = Number.isNaN(t) ? "" : ` on ${new Date(t).toLocaleDateString(undefined, { month: "short", day: "numeric" })}`;