Skip to content
SprecherEast
Issue 925

feat: a page-speed budget check (Lighthouse CI) that fails a pull request by itself

Back to our plan
Open
enhancementcitoolingpriority: high

A pull request can make a public page slower and nothing notices. This evaluates Lighthouse CI, Google's free tool that loads each page in a browser and scores it, and, if it passes the evaluation, adds it to CI with budgets set from the baseline, so a slower page turns the PR red on its own.

Problem

docs/roles/qa-reviewer.md mentions running Lighthouse by hand. Nobody does it on every PR, and a target nobody measures isn't a guardrail.

Proposed fix

  1. Evaluate it once, record on this issue (maintained? free for our use? runs in our setup? what data it sends out? fits native first?). What was found so far, to confirm:
    • @lhci/cli (Apache-2.0, GoogleChrome/lighthouse-ci): last npm release 0.16.0, a few days old; pin a version that has been out a few weeks. lhci assert exits with a failing status when an assertion fails. It can start our server itself (--start-server-command) and wait for it.
    • treosh/lighthouse-ci-action (MIT): a wrapper action with urls, configPath, budgetPath, runs, uploadArtifacts, temporaryPublicStorage (default off). Pin it to a commit, as with the other actions.
    • Data out: with temporaryPublicStorage or lhci upload --target=temporary-public-storage, reports go to a public Google Cloud URL for 7 days. Keep it off; keep reports as workflow artifacts only. Setting a GitHub token makes lhci upload post a status check; decide whether that's wanted or whether the job's own result is enough.
    • Native first: Next has no page-speed budget check; this is the official-tool step (Google's).
    • Version caution: Lighthouse 13 replaced many audits with "insight" audits and removed others, so assertions must name audit IDs that exist in the pinned version. Whether budget.json (budgetsFile) still works in the Lighthouse version LHCI ships was not confirmed; prefer assertions (metric and resource-summary keys) if it doesn't.
    • The CI runner's Chrome and Node: Lighthouse 13 needs Node 22.19 or newer; check the workflow's Node version.
  2. Set it up, if it passes.
    • A new job Page-speed budget in .github/workflows/ci.yml. It runs when the shared perf gate says page (or bundle) is due, always on a push to main, and always reports a result (a skipped job counts as passing, the same lesson as the browser-test gate).
    • Collect against the production build from e2e/serve.mjs with the representative seed, over the page list file from the baseline issue, mobile preset, several runs per page, median.
    • Assertions from the baseline file, not invented: for each page, the lab metrics and byte totals with headroom over the measured value and its spread. Write the headroom rule down once, next to the budget file.
    • The job's log ends with the summary line format the gate log issue counts (which budget, which page, measured vs budget).
  3. Not required yet. Making it a required check is the owner's ruleset step, after the gate log shows it fires right.

Acceptance criteria

  • Not done: The evaluation is on this issue, five answers with links, including what could not be confirmed
  • Not done: If it fails the evaluation: the reason and the next candidate are on the issue, and nothing is added
  • Not done: If it passes: the job runs on a PR the gate flags and on main, fails when a page breaks its budget, and passes otherwise (shown with a test PR that makes a page heavier, then reverted)
  • Not done: Budgets read from the committed baseline; no number typed into the workflow
  • Not done: No upload to public storage; reports kept as artifacts
  • Not done: Versions pinned; npm audit clean; the package rules in docs/guidelines/security.md checked
  • Not done: docs/project.md lists the check, and docs/roles/qa-reviewer.md points to it instead of the manual command

Files likely touched

.github/workflows/ci.yml, a Lighthouse CI config file, the budget file next to the baseline, package.json (dev dependency, if not run through the action), docs/project.md, docs/roles/qa-reviewer.md.

Must not touch

The End-to-end tests job and e2e/ specs (reuse e2e/serve.mjs only). The shared detector's rules (they belong to the fast-code rule issue).

Open questions

  • Run Lighthouse in the same job as the build the end-to-end tests make, to save a second build, or keep the jobs apart so one failing doesn't hide the other? Decide and record.
See it on GitHub, opens in a new tab