Skip to content

Universal SEO skill for Claude Code. 26 sub-skills + 19 sub-agents covering technical SEO, E-E-A-T, schema, GEO/AEO, agent readiness (Lighthouse Agentic Browsing, WebMCP, llms.txt), backlinks, local SEO, e-commerce, international SEO, Google APIs, and PDF/Excel reporting. 9 optional extensions for live SEO data.

fix(pagespeed): exit non-zero when every --psi-only call fails

Rudy Celekli6e50675dcd55
diff --git a/scripts/pagespeed_check.py b/scripts/pagespeed_check.py
index 8639615..2c3f629 100644
--- a/scripts/pagespeed_check.py
+++ b/scripts/pagespeed_check.py
@@ -537,9 +537,14 @@ def main():
result = query_crux(args.url, api_key, form_factor=args.form_factor)
elif args.psi_only:
strategies = ["mobile", "desktop"] if args.strategy == "both" else [args.strategy]
- result = {"psi": {}}
+ result = {"psi": {}, "error": None}
for strat in strategies:
- result["psi"][strat] = run_pagespeed(args.url, strategy=strat, api_key=api_key)
+ psi_result = run_pagespeed(args.url, strategy=strat, api_key=api_key)
+ result["psi"][strat] = psi_result
+ if psi_result.get("error"):
+ # Surface the per-strategy failure at the top level so the
+ # exit-code check below sees it, as combined_check already does.
+ result["error"] = psi_result["error"]
else:
result = combined_check(args.url, api_key=api_key, strategy=args.strategy)
diff --git a/tests/test_pagespeed_psi_only_exit.py b/tests/test_pagespeed_psi_only_exit.py
new file mode 100644
index 0000000..e6025a9
--- /dev/null
+++ b/tests/test_pagespeed_psi_only_exit.py
@@ -0,0 +1,47 @@
+"""Exit-code regression for scripts/pagespeed_check.py --psi-only.
+
+--crux-only and the default combined check both surface a failure at the
+top-level ``error`` key, so the final exit check (``sys.exit(1)`` when
+``result.get("error")``) reports a non-zero status to a CI gate. The
+--psi-only branch nested every failure under ``result["psi"][strat]["error"]``
+and never set a top-level error, so the process always exited 0 even when
+every PSI call failed. A pipeline gating on --psi-only got a false success.
+"""
+
+from __future__ import annotations
+
+import json
+import subprocess
+import sys
+from pathlib import Path
+
+import pytest
+
+pytest.importorskip("requests")
+
+ROOT = Path(__file__).resolve().parents[1]
+SCRIPT = ROOT / "scripts" / "pagespeed_check.py"
+
+# A non-http(s) URL is rejected by the URL-safety guard inside run_pagespeed
+# before any network call, so this reproduces a failing PSI run offline.
+_BAD_URL = "ftp://example.com/"
+
+
+def _run(args: list[str]) -> subprocess.CompletedProcess:
+ return subprocess.run(
+ [sys.executable, str(SCRIPT), _BAD_URL, *args],
+ capture_output=True, text=True,
+ )
+
+
+def test_psi_only_exits_nonzero_when_every_psi_call_fails() -> None:
+ proc = _run(["--psi-only", "--strategy", "mobile", "--json"])
+ assert proc.returncode == 1, (proc.returncode, proc.stdout, proc.stderr)
+ payload = json.loads(proc.stdout)
+ assert payload["psi"]["mobile"]["error"] # the failure is still reported
+
+
+def test_crux_only_control_already_exits_nonzero() -> None:
+ # Control: the sibling branch (no API key) exits non-zero today.
+ proc = _run(["--crux-only", "--json"])
+ assert proc.returncode == 1