feat: a page-speed budget check (Lighthouse CI) that fails a pull request by itself
Back to our planA 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
- 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 assertexits 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 withurls,configPath,budgetPath,runs,uploadArtifacts,temporaryPublicStorage(default off). Pin it to a commit, as with the other actions.- Data out: with
temporaryPublicStorageorlhci 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 makeslhci uploadpost 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; preferassertions(metric andresource-summarykeys) 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.
- Set it up, if it passes.
- A new job
Page-speed budgetin.github/workflows/ci.yml. It runs when the shared perf gate sayspage(orbundle) is due, always on a push tomain, 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.mjswith 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).
- A new job
- 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 auditclean; the package rules indocs/guidelines/security.mdchecked - Not done:
docs/project.mdlists the check, anddocs/roles/qa-reviewer.mdpoints 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.