feat(hooks): install missing tools instead of warning

setup-hooks.sh now installs shellcheck, jq, and yq if absent rather
than warning and continuing. Follows the same install pattern as
setup-gitleaks.sh (curl + install to TOOL_INSTALL_DIR=/usr/local/bin,
OS/arch detection, pinned versions).

Pinned versions: shellcheck 0.10.0, jq 1.7.1, yq 4.44.3.

The deployed pre-commit hook retains its runtime fallbacks as a safety
net for environments where tools are removed after setup.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TP4EGbBg3XMcyF28Lx78XJ
This commit is contained in:
2026-06-20 22:08:39 +00:00
parent e5a08ebb45
commit 7323aec740
2 changed files with 90 additions and 15 deletions

View File

@@ -165,27 +165,37 @@ for hook_file in "$REPO5/.git/hooks/commit-msg" "$REPO5/.git/hooks/pre-commit" "
fi
done
# --- 7. Hooks contain graceful degradation paths for missing tools ---
# --- 7. Setup installs tools; no "not installed" warnings when tools present ---
echo ""
echo "--- hooks contain graceful degradation for missing tools ---"
echo "--- setup does not warn when tools are available ---"
REPO6="$(make_repo)"
trap 'rm -rf "$REPO6"' EXIT
bash "$SCRIPT" "$REPO6" > /dev/null 2>&1
PRE_COMMIT6="$REPO6/.git/hooks/pre-commit"
output6="$(bash "$SCRIPT" "$REPO6" 2>&1)"
for tool in shellcheck jq yq; do
if grep -q "Warning:.*$tool\|$tool.*not installed\|$tool.*skipped" "$PRE_COMMIT6"; then
pass "pre-commit hook has graceful degradation path for missing: $tool"
if echo "$output6" | grep -qi "$tool not installed\|$tool.*not found"; then
fail "setup warned about missing $tool — should install or already be present"
else
fail "pre-commit hook missing graceful degradation for: $tool"
pass "setup emits no 'not installed' warning for: $tool (present or installed)"
fi
done
echo ""
echo "--- setup always exits 0 (no hard dependency on optional tools) ---"
echo "--- pre-commit hook retains runtime fallback for missing tools ---"
PRE_COMMIT6="$REPO6/.git/hooks/pre-commit"
for tool in shellcheck jq yq; do
if grep -q "Warning:.*$tool\|$tool.*not installed\|$tool.*skipped" "$PRE_COMMIT6"; then
pass "pre-commit hook has runtime fallback for missing: $tool"
else
fail "pre-commit hook missing runtime fallback for: $tool"
fi
done
echo ""
echo "--- setup exits 0 when tools are present ---"
REPO7="$(make_repo)"
trap 'rm -rf "$REPO7"' EXIT
if bash "$SCRIPT" "$REPO7" > /dev/null 2>&1; then
pass "setup exits 0 when all optional tools are present"
pass "setup exits 0 when tools are present"
else
fail "setup exited non-zero unexpectedly"
fi