Skip to content

fix(performance): report PageSpeed failures as unavailable, not score 0 - #4

Merged
KaiMOdev merged 1 commit into
mainfrom
fix/psi-unavailable-not-zero
May 20, 2026
Merged

KaiMOdev merged 1 commit into
mainfrom
fix/psi-unavailable-not-zero

Conversation

@KaiMOdev

Copy link
Copy Markdown
Owner

Problem

A clean-clone smoke test (fresh git clone → npm install → npm run dev → scan) surfaced this: without a PSI_API_KEY, the anonymous PageSpeed Insights endpoint is rate-limited and fails. runPerformanceChecks then returned score: 0 — indistinguishable from a site that genuinely scores 0. A new user's first scan shows Performance: 0, which reads as a broken tool. During a launch traffic spike, the shared anonymous quota makes this near-certain.

Changes

  • api/checks/performance.js — PSI failure now returns { available: false, score: null }; success returns { available: true }. null means "not measured"; 0 meant "measured, terrible" — now distinct.
  • app/src/SiteAuditApp.jsx — the Speed category card renders a dimmed — (n/a) with an explanatory tooltip instead of 0 when performance is unavailable. (The Performance tab already handled the error banner; the overview card did not.)
  • api/__tests__/performance.test.js (new) — covers the rate-limit, network-error, and success paths.
  • README.md — replaced the stale "pre-existing tests may fail" note; the full suite runs green.

Verification

  • New tests written test-first (RED → GREEN).
  • Full suite: 378 backend tests across 16 suites + frontend Vitest — all green.
  • Production build passes.
  • Live scan with PSI rate-limited: scores.performance: null, performance.available: false — confirmed.

All existing consumers (avgScore, generatePDF) already guard with ?? 0 / > 0, so null is safe.

🤖 Generated with Claude Code

When the PageSpeed Insights API fails (rate limit, network error),
runPerformanceChecks returned score: 0 — indistinguishable from a site
that genuinely scores 0. A fresh user with no PSI_API_KEY sees
"Performance: 0", which reads as a broken tool.

- performance.js: failure path returns { available: false, score: null };
  success returns { available: true }
- SiteAuditApp.jsx: the Speed category card shows a dimmed "— (n/a)" with a
  tooltip instead of "0" when performance data is unavailable
- add api/__tests__/performance.test.js covering failure and success paths
- README: replace the stale "tests may fail" note (the suite runs green)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@KaiMOdev
KaiMOdev merged commit edcb4f4 into main May 20, 2026
1 check passed
@KaiMOdev
KaiMOdev deleted the fix/psi-unavailable-not-zero branch May 20, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant