Skip to content

fix(policy): make the repository-policy self-test able to fail - #5

Merged
benjiwagner merged 1 commit into
mainfrom
fix/repository-policy-self-test
Jul 20, 2026
Merged

fix(policy): make the repository-policy self-test able to fail#5
benjiwagner merged 1 commit into
mainfrom
fix/repository-policy-self-test

Conversation

@benjiwagner

Copy link
Copy Markdown
Contributor

Summary

  • Route every self_test assertion through expect_error_count / expect_error_count_min, count failures, return nonzero from self_test, and call self_test || exit 1 at the entry point.
  • No change to the validation rules (validate_branch, validate_header, validate_body) themselves.

Context

The ci check in this repository runs only bash -n repository-policy/validate.sh plus bash repository-policy/validate.sh --self-test. A bare [[ ... ]] assertion inside a function does not abort under set -e here, so every assertion in self_test was decorative: the suite reached its final printf and exited 0 regardless of outcome.

Verified against the prior revision 2af0536: rewriting validate_branch so it rejects every valid branch still printed Repository policy self-test passed and exited 0. This repository's own required check has therefore been vacuous since the suite was written, and any future change to the shared policy could regress silently.

This PR was split from an abandoned larger change (former #4) that tried to add a workflow-tamper guard. That guard was dropped after an adversarial review showed a path-scoped guard cannot contain the threat it targeted — the check's behaviour is defined by too many ordinary repository files. This self-test fix is the part worth keeping, and it stands on its own.

Validation

  • bash -n repository-policy/validate.sh passes.
  • bash repository-policy/validate.sh --self-test passes on bash 3.2 (macOS) and 5.x.
  • Negative proof: with validate_branch mutated to reject valid branches, the suite now prints SELF-TEST FAILED: ... and exits 1 — where the same mutation passed silently before.

Impact and rollback

Test-harness only; the validation behaviour enforced on pull requests is unchanged, and this repository's ci check can now actually fail when the validator regresses. Roll back by reverting the squash commit.

Screenshots

Not applicable because this pull request changes a shell test harness only.

A bare `[[ ... ]]` assertion inside a function does not abort under `set -e`
in this script, so every assertion in `self_test` was unenforced: the suite
printed "passed" and exited 0 even when a validator was broken outright.
Verified on the prior revision that breaking `validate_branch` still passed.

Route assertions through `expect_error_count` / `expect_error_count_min`,
count failures, return nonzero from `self_test`, and call `self_test || exit 1`
at the entry point. No change to the validation rules themselves.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@benjiwagner
benjiwagner merged commit 4e7e197 into main Jul 20, 2026
3 checks passed
@benjiwagner
benjiwagner deleted the fix/repository-policy-self-test branch July 20, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant