Skip to content

fix(badges): surface git-fetch errors, guard malformed matrix entries, add tests#35

Merged
monsieurleberre merged 2 commits into
devfrom
fix/24-harden-write-badges
Jul 14, 2026
Merged

fix(badges): surface git-fetch errors, guard malformed matrix entries, add tests#35
monsieurleberre merged 2 commits into
devfrom
fix/24-harden-write-badges

Conversation

@monsieurleberre

Copy link
Copy Markdown
Contributor

Closes #24.

No-silent-failure hardening of scripts/write-badges.sh, plus a test suite. (PRs #30/#32 addressed unrelated areas — #30 = badge status-token validation in the Python helpers, #32 = csharp-ci cobertura glob — so all three checklist items were still outstanding and are done here.)

Changes

  • Fetch-error masking — replaced git fetch origin "$badge_branch" || true (which swallowed auth/network failures and silently fell through to the orphan-rebuild path) with an up-front git ls-remote --exit-code origin refs/heads/$badge_branch guard: missing ref (rc 2) → orphan rebuild; any other non-zero (128 auth/network) → loud ::error:: + abort; existing branch → explicit fetch whose real failures now abort.
  • Malformed matrix entries — both loops reject entries missing required fields via a require_field helper (matrix: lang/os/arch/passed; coverage: slug/label), plus a require_json_array guard rejecting non-array input. Prevents the ci-null-null-null.json write.
  • Tests — new test/write-badges_test.sh (33+ checks) against ephemeral bare-repo remotes: filename contract, null-percent skip, fresh/existing/unchanged branch paths, unreachable-origin abort, and every fail-loud guard. Hermetic (local bare origin, GIT_CONFIG_GLOBAL/SYSTEM=/dev/null, no network). Follows the existing plain-bash check/check_rc/check_contains harness (no bats in repo). Wired into the build-and-test self-test job.

Verification

  • shellcheck clean on the committed script; test suite 34/34 green; clean worktree; YAML parses.
  • Pre-open review: SHIP — reviewer independently confirmed ls-remote --exit-code returns exactly 2 for a missing ref (only that treated as benign), refs are safely quoted, guards fire before the filename is built, and tests are substantive/hermetic. One cosmetic non-blocking nit (a harmless git clone stderr warning in test seeding).

write-badges.sh swallowed all git-fetch failures via '|| true' and fell
through to the orphan-rebuild path, and had no guard for malformed matrix
entries (which would write ci-null-null-null.json). Detect an absent badge
branch up front with 'git ls-remote --exit-code' so only that benign case
rebuilds the orphan; let real fetch failures abort. Reject non-array
coverage-data/matrix-data and entries missing required fields with a loud
::error::. Add test/write-badges_test.sh pinning the filename contract,
null-percent skip, and fail-loud paths, wired into build-and-test.

Closes #24
Signed-off-by: monsieurleberre <monsieurleberre@users.noreply.github.com>
@monsieurleberre monsieurleberre merged commit 16606d4 into dev Jul 14, 2026
2 checks passed
@monsieurleberre monsieurleberre deleted the fix/24-harden-write-badges branch July 14, 2026 06:36
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.

Harden write-badges.sh: surface git-fetch errors, guard malformed matrix entries, add tests

1 participant