Public: anyone can read this; the crew can change it.
A test fails when any board or home banner renders red without a named cause and a one-tap action #15692
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15660-a-test-fails-when-any-board-or-home-bann → main 0 commits fork 3 threads · 3 unresolved
3 files
changed +148
−5
src/web/pages/boards-doctor.ts +3 −2
| @@ -16,8 +16,9 @@ import { fold } from "../figure.ts"; | ||
| 16 | 16 | /** The most runs the card lists. */ |
| 17 | 17 | export const DOCTOR_LISTED = 10; |
| 18 | 18 | |
| 19 | function runRow(repo: string, run: DoctorRun, now: number): Html { | |
| 20 | const tone = run.action === "held" ? "danger" : "default"; | |
| 19 | export function runRow(repo: string, run: DoctorRun, now: number): Html { | |
| 20 | // Red only where the pull it holds is linked; a sealed pull has no link to act on (#15660). | |
| 21 | const tone = run.action === "held" && !run.sealed && run.culprit !== null ? "danger" : "default"; | |
| 21 | 22 | return row({ |
| 22 | 23 | data: { doctor: run.action }, |
| 23 | 24 | title: html`${run.sealed || run.culprit === null ? html`<span class="muted">a sealed pull</span>` : html`<a href="/${repo}/pulls/${String(run.culprit)}">#${String(run.culprit)}</a>`} ${badge(run.action, { tone })}`, |
src/web/pages/boards-gates.ts +5 −3
| @@ -23,7 +23,7 @@ import { badge, row } from "../ui.ts"; | ||
| 23 | 23 | /** The most gates the card lists. */ |
| 24 | 24 | export const GATES_LISTED = 10; |
| 25 | 25 | |
| 26 | interface Listed { | |
| 26 | export interface Listed { | |
| 27 | 27 | readonly repo: string; |
| 28 | 28 | readonly gate: KeptResult; |
| 29 | 29 | readonly sealed: ReadonlySet<number>; |
| @@ -63,10 +63,12 @@ function detail(l: Listed): string | null { | ||
| 63 | 63 | return gate.state === "cut_off" ? gate.reason : null; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | function gateRow(l: Listed, now: number): Html { | |
| 66 | export function gateRow(l: Listed, now: number): Html { | |
| 67 | 67 | const { gate, repo } = l; |
| 68 | 68 | const more = detail(l); |
| 69 | const tone = gate.state === "green" ? "success" : gate.state === "red" ? "danger" : "default"; | |
| 69 | // Red names its cause (`detail`) and its way out (the pull's link). A sealed pull has neither to | |
| 70 | // show, so it reads in the plain tone: the word says the gate failed, and nothing shouts. | |
| 71 | const tone = gate.state === "green" ? "success" : gate.state === "red" && l.sealed.size === 0 ? "danger" : "default"; | |
| 70 | 72 | return row({ |
| 71 | 73 | data: { gate: gate.state }, |
| 72 | 74 | title: html`${gate.pulls.map((n) => |
test/red-has-action.test.ts added +140
| @@ -0,0 +1,140 @@ | ||
| 1 | /** | |
| 2 | * Red on the board or home names its cause and gives one tap to act (#15660). | |
| 3 | * One registry lists every red notice class the home and board modules can | |
| 4 | * draw; each is rendered and must carry a cause string and a link, or not be | |
| 5 | * red at all. A new red marker in those modules that the registry does not | |
| 6 | * list fails the scan, so a red notice with no action cannot be added quietly. | |
| 7 | */ | |
| 8 | import { expect, test } from "bun:test"; | |
| 9 | import { readdirSync, readFileSync } from "node:fs"; | |
| 10 | import { join } from "node:path"; | |
| 11 | import { laneRegion, needLine } from "../src/web/pages/home_flow.ts"; | |
| 12 | import { tableRegion } from "../src/web/pages/home_table.ts"; | |
| 13 | import type { LaneView } from "../src/flow/lanes.ts"; | |
| 14 | import type { TableQuery, TableRow } from "../src/flow/lanes_table.ts"; | |
| 15 | import { gateRow, type Listed } from "../src/web/pages/boards-gates.ts"; | |
| 16 | import { runRow } from "../src/web/pages/boards-doctor.ts"; | |
| 17 | import type { DoctorRun } from "../src/checks/doctor.ts"; | |
| 18 | import type { KeptResult } from "../src/checks/gate_result.ts"; | |
| 19 | ||
| 20 | const PAGES = join(import.meta.dir, "../src/web/pages"); | |
| 21 | const NOW = Date.parse("2026-01-01T00:00:00Z"); | |
| 22 | const RED = /data-(?:tone|variant)="danger"|role="alert"|\bnotice-danger\b|\bbanner\b/; | |
| 23 | const wordsOf = (h: string): string => h.replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim(); | |
| 24 | ||
| 25 | const kept = (over: Partial<KeptResult>): KeptResult => ({ | |
| 26 | id: "g", runId: "r", tipOid: "a", pulls: [7], state: "red", reason: "a check failed", passed: 1, failed: 1, | |
| 27 | failing: [{ name: "adds numbers", errors: ["expected 2"], flaky: false }], startedAt: "2025-12-31T23:00:00Z", | |
| 28 | finishedAt: "2025-12-31T23:59:00Z", durationMs: 1, ...over, | |
| 29 | }); | |
| 30 | const doctor = (over: Partial<DoctorRun>): DoctorRun => ({ | |
| 31 | batch: "a:b", culprit: 7, class: "test", action: "held", probe: "adds numbers", at: "2025-12-31T23:59:00Z", sealed: false, ...over, | |
| 32 | }); | |
| 33 | ||
| 34 | /** What one drawing of a red class is: its markup, the cause it must say, the link it must give. */ | |
| 35 | interface Drawn { readonly out: string; readonly cause: string; readonly link: string } | |
| 36 | ||
| 37 | const LANE = (n: number): LaneView => ({ key: "asked", items: [], all: [], total: n, more: 0 }); | |
| 38 | const STUCK_WORDS = "Nothing has entered or left this lane in half an hour."; | |
| 39 | const STUCK_ROW: TableRow = { | |
| 40 | key: "k", lane: "asked", laneName: "Asked", repo: "a/b", app: "b", number: 7, title: "Fix it", hint: "No builder has picked this up.", | |
| 41 | tone: "stuck", who: "", since: "2025-12-31T23:00:00Z", born: null, href: "/a/b/issues/7", issueId: null, kind: "issue", haystack: "fix it", | |
| 42 | }; | |
| 43 | const NO_QUERY: TableQuery = { q: "", lane: null, app: null, who: null, tone: null, sort: "lane", dir: "asc" }; | |
| 44 | ||
| 45 | /** | |
| 46 | * A red class: how to draw each of its states. The cause and link are named, not guessed from | |
| 47 | * length. | |
| 48 | */ | |
| 49 | const SPECS: Record<string, { draws: Record<string, () => Drawn> }> = { | |
| 50 | "home_flow.ts needLine (danger dot)": { | |
| 51 | draws: { | |
| 52 | broken: () => ({ | |
| 53 | out: String(needLine([{ says: "Release 1 is not serving as it should.", href: "/releases#proof" }], 0)), | |
| 54 | cause: "Release 1 is not serving as it should.", link: 'href="/system"', | |
| 55 | }), | |
| 56 | }, | |
| 57 | }, | |
outdated
|
||
| 58 | "home_flow.ts lane Stuck dot": { | |
| 59 | draws: { | |
| 60 | stuck: () => ({ | |
| 61 | out: String(laneRegion(LANE(3), { tone: "stuck", words: STUCK_WORDS, oldest: null }, null, false, NOW)), | |
| 62 | cause: STUCK_WORDS, link: 'class="lane-name-link" href="/?view=table&lane=asked"', | |
| 63 | }), | |
| 64 | }, | |
| 65 | }, | |
| 66 | "home_table.ts row stuck dot": { | |
| 67 | draws: { | |
| 68 | stuck: () => ({ | |
| 69 | out: String(tableRegion([STUCK_ROW], NO_QUERY, NOW)), | |
| 70 | cause: STUCK_ROW.hint, link: 'href="/a/b/issues/7"', | |
| 71 | }), | |
| 72 | }, | |
| 73 | }, | |
outdated
A per-file line count passes when a marker moves or is swapped. Key the registry on the class, not the count. |
||
| 74 | "boards-gates.ts gate row (red gate)": { | |
| 75 | draws: { | |
| 76 | open: () => ({ | |
| 77 | out: String(gateRow({ repo: "a/b", gate: kept({}), sealed: new Set() } as Listed, NOW)), | |
| 78 | cause: "adds numbers", link: 'href="/a/b/pulls/7"', | |
| 79 | }), | |
| 80 | sealed: () => ({ out: String(gateRow({ repo: "a/b", gate: kept({}), sealed: new Set([7]) } as Listed, NOW)), cause: "", link: "" }), | |
| 81 | }, | |
| 82 | }, | |
| 83 | "boards-doctor.ts run row (held)": { | |
| 84 | draws: { | |
| 85 | open: () => ({ out: String(runRow("a/b", doctor({}), NOW)), cause: "adds numbers", link: 'href="/a/b/pulls/7"' }), | |
| 86 | sealed: () => ({ out: String(runRow("a/b", doctor({ sealed: true, culprit: null }), NOW)), cause: "", link: "" }), | |
| 87 | }, | |
| 88 | }, | |
| 89 | }; | |
| 90 | ||
| 91 | test("every red a spec draws names its cause and gives its link, or is not red", () => { | |
| 92 | for (const [name, spec] of Object.entries(SPECS)) { | |
| 93 | for (const [state, draw] of Object.entries(spec.draws)) { | |
| 94 | const d = draw(); | |
| 95 | if (!RED.test(d.out)) continue; | |
| 96 | expect({ name, state, link: d.link !== "" && d.out.includes(d.link) }).toEqual({ name, state, link: true }); | |
| 97 | expect({ name, state, cause: d.cause !== "" && wordsOf(d.out).includes(d.cause) }).toEqual({ name, state, cause: true }); | |
| 98 | } | |
| 99 | } | |
| 100 | }); | |
| 101 | ||
| 102 | test("each spec really draws red in its first state, so the check above bites", () => { | |
| 103 | for (const [name, spec] of Object.entries(SPECS)) expect({ name, red: RED.test(Object.values(spec.draws)[0]!().out) }).toEqual({ name, red: true }); | |
| 104 | }); | |
| 105 | ||
| 106 | test("a sealed pull's failure is not red: it has no cause to name and no link to give", () => { | |
| 107 | expect(RED.test(SPECS["boards-gates.ts gate row (red gate)"]!.draws["sealed"]!().out)).toBe(false); | |
| 108 | expect(RED.test(SPECS["boards-doctor.ts run row (held)"]!.draws["sealed"]!().out)).toBe(false); | |
| 109 | }); | |
| 110 | ||
| 111 | // The modules the home and board are drawn from. Every source line that makes something red must | |
| 112 | // be one of the lines registered below, each under the class its SPECS entry draws; moving a | |
| 113 | // marker keeps it passing, swapping, adding or duplicating one fails until it has a spec. | |
| 114 | // boards-edit.ts is left out on purpose: its two red markers are the one-time flash after the | |
| 115 | // person's own refused edit (the cause is the message, the tap they just made is the action). | |
| 116 | const SCANNED = (f: string): boolean => /^(board|boards|home)[-_.]/.test(f) && f.endsWith(".ts") && !/(style|client)\.ts$/.test(f) && f !== "boards-edit.ts"; | |
| 117 | const MARKER = /data-tone="danger"|"danger"|role="alert"|notice-danger|"banner"|class="[^"]*\bbanner\b/; | |
| 118 | const CLASSES: Record<string, readonly string[]> = { | |
| 119 | "boards-gates.ts": ['gate.state === "red" && l.sealed.size === 0 ? "danger"'], | |
| 120 | "boards-doctor.ts": ['run.action === "held" && !run.sealed && run.culprit !== null ? "danger"'], | |
| 121 | "home_flow.ts": ['stuck: "danger",', '"attn" : "danger"'], | |
| 122 | "home_table.ts": ['stuck: "danger",'], | |
| 123 | }; | |
| 124 | ||
| 125 | test("no module of the home or board draws a red marker the specs do not list", () => { | |
| 126 | const found: Record<string, string[]> = {}; | |
| 127 | for (const f of readdirSync(PAGES).filter(SCANNED)) { | |
| 128 | const lines = readFileSync(join(PAGES, f), "utf8").split("\n").filter((l) => MARKER.test(l) && !l.trim().startsWith("//") && !l.trim().startsWith("*")); | |
| 129 | const keys = lines.map((l) => (CLASSES[f] ?? []).find((k) => l.includes(k)) ?? l.trim()); | |
| 130 | if (keys.length > 0) found[f] = keys.sort(); | |
| 131 | } | |
| 132 | const expected = Object.fromEntries(Object.entries(CLASSES).map(([f, ks]) => [f, [...ks].sort()])); | |
| 133 | expect(found).toEqual(expected); | |
| 134 | }); | |
| 135 | ||
| 136 | test("the scan fires on a new red notice with no action", () => { | |
| 137 | expect(MARKER.test('<p role="alert">Something failed</p>')).toBe(true); | |
| 138 | expect(MARKER.test('<span class="dot" data-tone="danger"></span>')).toBe(true); | |
| 139 | expect(MARKER.test('<p class="small">fine</p>')).toBe(false); | |
| 140 | }); |
new above
offline
Add the lane Stuck dot and the home_table stuck dot here, drawn by their real renderers. At present they are only counted, never asserted.