Public: anyone can read this; the crew can change it.
The check summary renders a per-look web-vitals table from recorded entries, report-only #3013
scout/forge:scout/3009-the-check-summary-renders-a-per-look-web → main 2 commits fork 2 threads · 2 unresolved
7 files
changed +151
−1
README.md +2
| @@ -1674,6 +1674,8 @@ A check's run page (`/:owner/:name/runs/:id`) opens with three rows, install, ty | ||
| 1674 | 1674 | |
| 1675 | 1675 | Under the rows, once the tests have begun, the run page shows a progress bar of files started out of the banner's count, the passes and failures so far, the file(s) of the live shard running now, and each failure pinned with its first three lines of output (`parseTestsRow`, `src/checks/tests-row.ts`). It reads only the shard runner's lines and `bun test`'s `(fail)` markers; a figure the log does not give is left out. Batched shards (run side by side) report whole when they finish, so they name no running file. The words line and a slot for the pins are always rendered (the slot reserves height only while the run is open, and scrolls past 9em) so the log never shifts; while the run is open the bar is named "Test files started" and is indeterminate (no value) when the count is unknown, and once the run has ended an unknown count shows no bar; only the rows, the bar and the words are a live region, the pins are outside it, and a slot with pins is a focusable labelled region the refetch patches in place. The terminal's checks line appends the same: `tests 2 of 9 files started · 812 passed, 1 failed · failing: <names>` (`testsRowLine`, read in `stepsLine`, withheld from a reader who may not read the log). |
| 1676 | 1676 | |
| 1677 | Below them the run page has a per-look web-vitals table: LCP, CLS and TBT (`webvitals()`, `src/release/webvitals.ts`) each beside its good/poor thresholds and grade, a vital with no recorded entry as `n/a` (never zero), and a look run without a browser as one `skipped: no browser` line (`vitalsRows`, `src/checks/summary.ts`, as plain words; `vitalsTable`, `src/web/studio/vitals.ts`, escapes and renders them inside a horizontally scrolling wrapper). It is report-only: it has no verdict, so nothing in it can turn a check red. No look records entries yet (the browser is #2983's second half), so until then the table renders nothing. | |
| 1678 | ||
| 1677 | 1679 | While the default branch's own last check is red, the forge holds its pulls' checks queued rather than fail each one on the same test (`src/checks/red_main.ts`): the vitals carry one card naming the failing test and how many checks wait, and main going green releases them. A check a person asks for again runs at once, and no check is held more than 20 minutes, so the pull that fixes main can always show green. |
| 1678 | 1680 | |
| 1679 | 1681 | `GET /api/v1/repos/:owner/:name/commits/:oid/check` answers the default branch's own check of one full commit id, `{commit, state, runId, summary, finishedAt}` with `state` `ok`, `failed`, `pending`, `superseded` (every check of it was cancelled, as when main moved on before it ran, and none will follow) or `none`, to whoever may read the repository's runs (`src/checks/commit_check.ts`). It is half of the forge's release gate: the release workflow builds only once it reads `ok` for the tagged commit, and the build boots the image it made (`docs/ops/ROLL.md`, "The gate of record"). |
src/checks/summary.ts +51
| @@ -10,6 +10,7 @@ | ||
| 10 | 10 | import type { CheckDetail, Run } from "../core/runs.ts"; |
| 11 | 11 | import { parseBunTestFailure } from "./bun-test.ts"; |
| 12 | 12 | import { oneLine } from "./words.ts"; |
| 13 | import { webvitals, type Entries } from "../release/webvitals.ts"; | |
| 13 | 14 | |
| 14 | 15 | /** |
| 15 | 16 | * The first line of the block a timed full gate ends its log with |
| @@ -199,3 +200,53 @@ export const stepWord = (state: StepState): string => STEP_WORDS[state]; | ||
| 199 | 200 | export function stepsWords(steps: readonly CheckStep[]): string { |
| 200 | 201 | return steps.map((s) => `${s.name} ${stepWord(s.state)}`).join(" · "); |
| 201 | 202 | } |
| 203 | ||
| 204 | /** One look's recorded entries, or why it has none; plain data from the caller. */ | |
| 205 | export type LookVitals = | |
| 206 | | { readonly look: string; readonly entries: Entries } | |
| 207 | | { readonly look: string; readonly skipped: string }; | |
| 208 | ||
| 209 | /** One cell row of a look's table: words only, escaped where they are rendered. */ | |
| 210 | export interface VitalsRow { | |
| 211 | readonly vital: string; | |
| 212 | /** `n/a` when the page recorded no entry, never zero. */ | |
| 213 | readonly value: string; | |
| 214 | readonly thresholds: string; | |
| 215 | readonly grade: string; | |
| 216 | } | |
| 217 | ||
| 218 | export interface LookRows { | |
| 219 | readonly look: string; | |
| 220 | /** Why the look has no numbers (`no browser`); empty when it has rows. */ | |
| 221 | readonly skipped: string; | |
| 222 | readonly rows: readonly VitalsRow[]; | |
| 223 | } | |
| 224 | ||
| 225 | const VITAL_ROWS = [ | |
| 226 | ["LCP", "lcpMs"], | |
| 227 | ["CLS", "cls"], | |
| 228 | ["TBT", "tbtMs"], | |
| 229 | ] as const; | |
| 230 | ||
| 231 | const shown = (n: number, unit: string): string => `${n}${unit === "" ? "" : ` ${unit}`}`; | |
| 232 | ||
| 233 | /** | |
| 234 | * Each look's LCP, CLS and TBT beside their thresholds and grade. Report-only: | |
| 235 | * it returns words and has no verdict, so nothing in it can turn a check red. | |
| 236 | */ | |
| 237 | export function vitalsRows(looks: readonly LookVitals[]): readonly LookRows[] { | |
| 238 | return looks.map((l) => { | |
| 239 | if ("skipped" in l) return { look: l.look, skipped: l.skipped, rows: [] }; | |
| 240 | const v = webvitals(l.entries); | |
outdated
A five-column table with no table.vitals CSS will overflow at 360px. Add a scroll wrapper or a stacked layout. |
||
| 241 | const rows = VITAL_ROWS.map(([vital, key]): VitalsRow => { | |
| 242 | const x = v[key]; | |
| 243 | return { | |
| 244 | vital, | |
| 245 | value: x.value === null ? "n/a" : shown(x.value, x.unit), | |
| 246 | thresholds: `good ≤ ${shown(x.good, x.unit)}, poor > ${shown(x.poor, x.unit)}`, | |
| 247 | grade: x.grade ?? "n/a", | |
| 248 | }; | |
| 249 | }); | |
| 250 | return { look: l.look, skipped: "", rows }; | |
| 251 | }); | |
| 252 | } |
src/web/studio/run.ts +11 −1
| @@ -8,7 +8,8 @@ | ||
| 8 | 8 | * at `?all=1`. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | import { checkSteps, stepWord } from "../../checks/summary.ts"; | |
| 11 | import { checkSteps, stepWord, type LookVitals } from "../../checks/summary.ts"; | |
| 12 | import { vitalsTable } from "./vitals.ts"; | |
| 12 | 13 | import { parseTestsRow, testsRowWords } from "../../checks/tests-row.ts"; |
| 13 | 14 | import { directionNote } from "../../crew/direct.ts"; |
| 14 | 15 | import { appsRuntime } from "../../apps/runtime.ts"; |
| @@ -43,6 +44,14 @@ import { runWord, servingHistory, wordBadge, type WordCtx } from "./words.ts"; | ||
| 43 | 44 | * running one or takes a queued one back off the board. Nothing for runs |
| 44 | 45 | * that are over, or for readers. |
| 45 | 46 | */ |
| 47 | /** | |
| 48 | * The looks a check recorded vitals for. No browser records them yet (#2983 | |
| 49 | * is the second half), so this is empty and the table renders nothing. | |
| 50 | */ | |
| 51 | function recordedLooks(_run: Run): readonly LookVitals[] { | |
| 52 | return []; | |
| 53 | } | |
| 54 | ||
| 46 | 55 | export function stopForm(ctx: Ctx, repo: Repo, run: Run): Html | null { |
| 47 | 56 | if (run.state !== "running" && run.state !== "queued") return null; |
| 48 | 57 | if (run.kind !== "agent") return null; |
| @@ -309,6 +318,7 @@ export async function runView( | ||
| 309 | 318 | </div>`; |
| 310 | 319 | }, |
| 311 | 320 | )} |
| 321 | ${when(run.kind === "check" && !logHidden, () => vitalsTable(recordedLooks(run)))} | |
| 312 | 322 | <div class="run-live" id="run-live" data-state="${run.state}"> |
| 313 | 323 | ${when( |
| 314 | 324 | // The head above is what makes \`liveRegionsJs\` open the one |
src/web/studio/vitals.ts added +27
| @@ -0,0 +1,27 @@ | ||
| 1 | /** | |
| 2 | * The web-vitals table of a check's run page: `vitalsRows`' plain words | |
| 3 | * (src/checks/summary.ts) as escaped HTML. Report-only, and nothing when no | |
| 4 | * look recorded anything. | |
| 5 | */ | |
| 6 | ||
| 7 | import { vitalsRows, type LookVitals } from "../../checks/summary.ts"; | |
| 8 | import { html, type Html } from "../html.ts"; | |
| 9 | ||
| 10 | export function vitalsTable(looks: readonly LookVitals[]): Html { | |
| 11 | const groups = vitalsRows(looks); | |
| 12 | if (groups.length === 0) return html``; | |
| 13 | return html`<div class="vitals-wrap" tabindex="0" role="region" aria-label="Web vitals per look"> | |
| 14 | <table class="vitals"> | |
| 15 | <thead><tr><th>Look</th><th>Vital</th><th>Value</th><th>Thresholds</th><th>Grade</th></tr></thead> | |
| 16 | <tbody> | |
| 17 | ${groups.map((g) => | |
| 18 | g.skipped !== "" | |
| 19 | ? html`<tr><th scope="row">${g.look}</th><td colspan="4">skipped: ${g.skipped}</td></tr>` | |
| 20 | : g.rows.map( | |
| 21 | (r, i) => html`<tr>${i === 0 ? html`<th scope="row" rowspan="${g.rows.length}">${g.look}</th>` : ""}<td>${r.vital}</td><td>${r.value}</td><td>${r.thresholds}</td><td>${r.grade}</td></tr>`, | |
| 22 | ), | |
| 23 | )} | |
| 24 | </tbody> | |
| 25 | </table> | |
| 26 | </div>`; | |
| 27 | } |
src/web/style/content.ts +3
| @@ -895,6 +895,9 @@ form.inline { display: inline; margin-left: auto; } | ||
| 895 | 895 | .checks-line .ok { display: inline-flex; align-items: center; gap: 4px; color: var(--success); } |
| 896 | 896 | .checks-line .bad { display: inline-flex; align-items: center; gap: 4px; color: var(--danger); } |
| 897 | 897 | .checks-line .now { display: inline-flex; align-items: center; gap: 4px; color: var(--attn); } |
| 898 | .vitals-wrap { margin-top: 12px; overflow-x: auto; max-width: 100%; } | |
| 899 | .vitals { border-collapse: collapse; font-size: 13px; white-space: nowrap; } | |
| 900 | .vitals th, .vitals td { padding: 4px 10px; border-bottom: 1px solid var(--border); text-align: left; } | |
| 898 | 901 | .check-steps { list-style: none; margin: 12px 0 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; } |
| 899 | 902 | .check-steps li { display: flex; justify-content: space-between; gap: 8px; padding: 8px 12px; min-height: 2.5em; border: 1px solid var(--border); border-radius: var(--radius); } |
| 900 | 903 | .tests-bar { display: block; width: 100%; height: 8px; margin-top: 8px; } |
test/check-vitals.test.ts added +55
| @@ -0,0 +1,55 @@ | ||
| 1 | /** The web-vitals table of a check's run page: `vitalsRows` (src/checks/summary.ts) rendered by `vitalsTable` (src/web/studio/vitals.ts); report-only. */ | |
| 2 | ||
| 3 | import { describe, expect, test } from "bun:test"; | |
| 4 | import { vitalsRows } from "../src/checks/summary.ts"; | |
| 5 | import { vitalsTable } from "../src/web/studio/vitals.ts"; | |
| 6 | ||
| 7 | const recorded = { | |
| 8 | look: "home", | |
| 9 | entries: { | |
| 10 | lcp: [{ startTime: 3100, size: 10 }], | |
| 11 | layoutShift: [{ startTime: 100, value: 0.3 }], | |
| 12 | longtask: [{ duration: 150 }], | |
| 13 | }, | |
| 14 | }; | |
| 15 | ||
| 16 | describe("vitalsRows", () => { | |
| 17 | test("numbers, thresholds and grades from recorded entries", () => { | |
| 18 | expect(vitalsRows([recorded])[0]!.rows).toEqual([ | |
| 19 | { vital: "LCP", value: "3100 ms", thresholds: "good ≤ 2500 ms, poor > 4000 ms", grade: "needs-improvement" }, | |
| 20 | { vital: "CLS", value: "0.3", thresholds: "good ≤ 0.1, poor > 0.25", grade: "poor" }, | |
| 21 | { vital: "TBT", value: "100 ms", thresholds: "good ≤ 200 ms, poor > 600 ms", grade: "good" }, | |
| 22 | ]); | |
| 23 | }); | |
| 24 | ||
| 25 | test("a missing LCP is n/a, not zero", () => { | |
| 26 | const lcp = vitalsRows([{ look: "home", entries: {} }])[0]!.rows[0]!; | |
| 27 | expect(lcp).toMatchObject({ vital: "LCP", value: "n/a", grade: "n/a" }); | |
| 28 | }); | |
| 29 | ||
| 30 | test("a look without a browser carries its reason and no rows", () => { | |
| 31 | expect(vitalsRows([{ look: "mobile", skipped: "no browser" }])).toEqual([ | |
| 32 | { look: "mobile", skipped: "no browser", rows: [] }, | |
| 33 | ]); | |
| 34 | }); | |
| 35 | }); | |
| 36 | ||
| 37 | describe("vitalsTable", () => { | |
| 38 | test("renders the rows inside a scroll wrapper", () => { | |
| 39 | const out = vitalsTable([recorded]).text; | |
| 40 | expect(out).toContain('class="vitals-wrap"'); | |
| 41 | expect(out).toContain("<td>LCP</td><td>3100 ms</td><td>good ≤ 2500 ms, poor > 4000 ms</td><td>needs-improvement</td>"); | |
| 42 | }); | |
| 43 | ||
| 44 | test("renders the skipped line", () => { | |
| 45 | expect(vitalsTable([{ look: "mobile", skipped: "no browser" }]).text).toContain("skipped: no browser"); | |
| 46 | }); | |
| 47 | ||
| 48 | test("escapes look names", () => { | |
| 49 | const out = vitalsTable([{ look: "<img src=x>", skipped: "no browser" }]).text; | |
| 50 | expect(out).not.toContain("<img"); | |
| 51 | expect(out).toContain("<img"); | |
| 52 | }); | |
| 53 | ||
| 54 | test("no looks, no markup", () => expect(vitalsTable([]).text).toBe("")); | |
| 55 | }); |
test/studio-runs.test.ts +2
| @@ -821,6 +821,8 @@ describe("working: a run's own page in the studio", () => { | ||
| 821 | 821 | const ended = await (await get(`/alice/engine/runs/${done.id}`, writerCookie)).text(); |
| 822 | 822 | expect(ended).toContain("check-progress"); |
| 823 | 823 | expect(ended).not.toContain("<progress"); |
| 824 | // No look has recorded vitals yet: the run page renders no table, not an empty one. | |
| 825 | expect(ended).not.toContain("vitals"); | |
| 824 | 826 | // A reader the log is hidden from gets none of it. |
| 825 | 827 | const plain = await createRepo(app, alice, { name: "plainb", visibility: "public", description: "x" }); |
| 826 | 828 | if (!plain.ok) throw new Error(String(plain.error)); |
new above
offline
Exported with no caller anywhere in src. Wire it into the check summary renderer, or it is dead code.