Repository navigation
fix(hooks): make git-push-approval hook work with macOS Bash 3.2 - #222
Conversation
require-push-approval.sh lowercased the tool name with `${1,,}`, a Bash 4
expansion. Stock macOS runs `#!/bin/bash` under Bash 3.2, where it is a
"bad substitution", so the hook never emitted its "ask" decision. Lowercase
with `tr` instead.
Add tests/test_hook_scripts.py: a static scan of every script referenced by
.apm/hooks/*.json for Bash 4+ syntax, plus behaviour checks for both hooks.
The new Hook Scripts workflow runs them with the runner's Bash and again
with a Bash 3.2.57 built by tests/build-bash32.sh.
Closes #217
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 43 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
There was a problem hiding this comment.
🟡 Changes recommended
A relative destination is resolved inside the temporary build tree, causing the helper to delete the copied binary on exit while reporting success and a nonexistent output path.
1 open issue
What changed in this PR
This PR restores the git-push approval hook’s compatibility with stock macOS Bash 3.2 and adds regression checks for the shipped hooks, addressing #217.
Changes:
- Replaces Bash 4-only lowercasing with portable
tr. - Adds static compatibility scans and behavior tests for both hooks.
- Adds a checksum-pinned Bash 3.2 build helper and a dedicated workflow testing both interpreter versions.
| File | Description |
|---|---|
tests/test_hook_scripts.py |
Adds compatibility scans, hook behavior tests, and interpreter version checks. |
tests/build-bash32.sh |
Builds checksum-verified Bash 3.2.57 for compatibility testing. |
scripts/git-push-approval/require-push-approval.sh |
Uses Bash 3.2-compatible tool-name lowercasing. |
.github/workflows/hook-scripts.yml |
Runs hook tests with the runner’s Bash and Bash 3.2. |
Review effort: Balanced
Resolve DEST against the caller's directory before the build changes into the temporary source tree, so a relative destination isn't copied into the tree the EXIT trap deletes. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Closes #217
What
scripts/git-push-approval/require-push-approval.shlowercased the tool name with${1,,}(Bash 4). Stock macOS runs#!/bin/bashas Bash 3.2, where that's abad substitution. It now lowercases withtr.tests/test_hook_scripts.py:.apm/hooks/*.jsonfor Bash 4+ syntax (case modification,declare -A/-n,mapfile,|&,&>>,[[ -v ]],${var@Q}, …);SKIP_PUSH_APPROVAL, guard allow/block), run with$HOOK_BASH.tests/build-bash32.sh(pinned tarball SHA-256).EXPECT_BASH_VERSION=3.2makes the run fail if it isn't 3.2.scripts/tool-guardian/guard-tool.shwas checked: no Bash 4+ syntax, and it passes the behaviour tests under 3.2. No change needed.Behaviour found while reproducing
Under a real Bash 3.2.57, the old hook printed
bad substitutionbut exited 0 with no decision. So on macOSgit pushwasn't gated at all (the issue expected a fail-closed deny). The new behaviour tests catch both outcomes, because they require theaskJSON and exit 0.Notes
markdown-validation.yml, so it doesn't conflict with feat(security): add SkillSpector severity gate with reviewed acceptances #215 / ci(security): add SkillSpector workflow with PR report comment #218, which both edit that workflow. For the same reason,.lefthook.tomlandCONTRIBUTING.mdare unchanged.bash:3.2Docker image. It has busybox tools and nojq, so it would test tool differences rather than Bash syntax.Validation (separate tester contexts)
test_hook_scripts.py: 10/10 pass with Bash 5.2 and with Bash 3.2.57. The version assertion ran.bad substitutionunder 3.2, and the static scan flags its${1,,}line.shellcheck0.11.0 andshfmt3.14.1 report nothing. All lefthook pre-commit checks passed. The commit is signed.