fix(compliance): record unreadable alert counts as unknown, not 0

Merged
DO
1mo ago
+351-30

Problem

The health-survey job of compliance-audit-and-improvement.yml read dependabot/alerts, secret-scanning/alerts and code-scanning/alerts and turned any gh error into a count of 0. Until 2026-10-29 ORG_SCORECARD_TOKEN lacked code-scanning read (surfaced by the combsmith/.github#1411 dry run), so every repo's code_scanning_open was silently 0 and the weighted finding_score under-counted. The token is fixed, but the next permission, rate-limit or API failure would be just as silent. The reads also took only the first page, so counts capped at 30.

Change

  • scripts/lib/health-alerts.sh (new) — the alert reads move out of inline YAML (AGENTS.md "Decision Logic Lives in a Pure, Tested Script"):
    • health_alert_error_kind — classifies a failed read. Only GitHub's "no analysis found" / Advanced Security not enabled (code scanning, mirroring alerts_error_kind() in scripts/codeql-audit.sh), "Dependabot alerts are disabled" and "Secret scanning is disabled" mean 0; matched per endpoint. Anything else is an error.
    • health_alert_count — gh api --paginate …?state=open&per_page=100; echoes the count, 0 for the disabled cases, or null plus a ::warning:: on failure. A failure mid-pagination is unknown, never a partial count.
    • health_security_json / health_findings_score — per-repo security object and weighted score.
  • Per-repo JSON: security gains dependabot_read_error, secret_scanning_read_error, code_scanning_read_error and unknown_counts; an unreadable count is null. Report gains top-level repos_with_unknown_alert_counts.
  • Surfacing: step summary lists repos with unreadable counts; has_findings is true when any count is unknown; the Claude analysis prompt says unknown ≠ zero, no per-repo alert issues from a null count, and one deduplicated telemetry-gap issue in this repo instead.
  • health-survey now checks out this repo (actions/checkout v7.0.1, SHA verified via the GitHub API, persist-credentials: false) to source the lib.
  • compliance-audit-tests.yml shellchecks the lib; its bats suite already covers test/scripts/compliance-audit/ and triggers on scripts/lib/**.

Verification

  • bats test/scripts/compliance-audit/health-alerts.bats — 26/26 pass (classification, pagination, stubbed-gh success/403/disabled/mid-pagination failure, JSON shape, score).
  • shellcheck --severity=warning on the lib: clean. actionlint: no new findings (the four SC2129 style notes exist on main). test/workflows/compliance-audit/ fleet-pause suite: pass.
  • Ran the real collect step locally against combsmith/.github-private:
    • live: code_scanning_open: 49 (old code capped at 30), no read errors.
    • with a gh shim returning 403 for code-scanning: code_scanning_open: null, code_scanning_read_error: true, repos_with_unknown_alert_counts: 1, summary lists the repo, has_findings=true.

Not verified live: the exact Dependabot/secret-scanning "disabled" and code-scanning "Advanced Security must be enabled" message texts — no org repo currently has those features off. If GitHub words them differently, the effect is fail-safe: the count shows as unknown, not as 0.

🤖 Generated with Claude Code