SEO checks: one file per check, so PRs adding checks stop conflicting

Merged
LU
3d ago
+2657-2001

PRs that add an SEO check kept conflicting with each other: each took the next free number and appended to the same four places in check_seo_html.py and its test file. #1093 and #1207 both claim check 14 on main, and here on rebrand-doors the newsletter check ran twice, once as "12" (colliding with the resource-subsets check) and once as "19".

Now each check is its own module, scripts/seo_checks/<name>.py: a docstring (its first line is the summary title) and a check(site) function. Its tests go in scripts/tests/test_seo_<name>.py. The runner loads every module in that folder in name order, so adding a check means adding two files and editing nothing shared. The numbers are gone, so the summary and FAIL headings now show module names in alphabetical order. The command line, exit code and report-only output are unchanged, so deploy.yaml, rebrand-preview.yaml and rehearse_launch.py need no change.

The runner refuses to start if the folder is empty or a module lacks a docstring or check, and a runner test confirms every module file is loaded, so a check can't silently drop out.

Audit of checks and tests

  • Removed: the duplicate newsletter run (old 12 and 19).
  • Moved in from rebrand-doors: every check added there since this branch started (old 25–37) is its own module with tests, and the changed citation_targets rules (data-cite, data-reference, truncated data-source) are included. There are now 37 checks.
  • Kept: the FLoRA citation check. This PR first dropped it because it looked for one hard-coded DOI; rebrand-doors now accepts any DOI next to the dataset citation, so that reason no longer applies.
  • Tests replaced: the runner test that built a fake whole site just so main() returned 0. Stub checks now cover it. The breadcrumb-links test now runs the check, not just the parser.
  • Tests added: for checks that had none (retired newsletter script, related card pictures, extension move), and for the crash guards.
  • Crash guards: a bare class, href or data-cite, a breadcrumb name that is not text, and malformed mainEntity data no longer abort the run. Results on valid input are the same.
  • Overlaps checked, all kept:
    • homepage_assets catches the highlight.js stylesheet, which conditional_assets doesn't look at.
    • search_heading catches the search overlay's <h1> (on every page via baseof.html) on pages with no heading of their own, where single_h1 can't.
    • homepage_share_image requires 1200×630 and summary_large_image, which share_image_metadata doesn't.

Verification

  • Built the merged branch with Hugo (3,774 pages checked). Old and new runners give the same result (all pass, exit 0), and the report-only output is identical.
  • Injected 68 faults, at least one for each of the 37 checks, into a copy of the build. Old and new code flag exactly the same items every time. With one fault per check at once, both command lines exit 1 with the same 37 failing checks and items.
  • python3 -m unittest discover -s scripts/tests passes with CI's dependencies (365 tests, 107 of them SEO tests; 90 before, minus the fake-site test, plus 18), and so does the disciplines parser test. script-tests.yaml runs both on every PR.

If a PR adds a check in the old layout

Move its check_* function into scripts/seo_checks/<name>.py as check(site) with a docstring, and its tests to scripts/tests/test_seo_<name>.py.

Created with Claude Opus 5.5 in Claude Code (T3 Code); options reviewed by GPT-6.2 Sol in Codex.