Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b86yyhhudsSLnwNUFY
19 lines
849 B
Bash
Executable File
19 lines
849 B
Bash
Executable File
#!/bin/bash
|
|
# Stop hook. Refuses to let Claude finish while the full suite is red.
|
|
INPUT=$(cat)
|
|
if [ "$(echo "$INPUT" | jq -r '.stop_hook_active')" = "true" ]; then
|
|
exit 0 # we already pushed Claude back once this turn; let it stop and report
|
|
fi
|
|
|
|
ROOT="${CLAUDE_PROJECT_DIR:-$(pwd)}"
|
|
cd "$ROOT" || exit 0
|
|
OUT=$(mvn -B -q test 2>&1)
|
|
if [ $? -ne 0 ]; then
|
|
SUMMARY=$(echo "$OUT" | awk '/^\[ERROR\] (Failures|Errors):/{p=1} p{print} p&&/^\[ERROR\] Tests run:/{exit}' | head -20)
|
|
[ -z "$SUMMARY" ] && SUMMARY=$(echo "$OUT" | grep -E '^\[ERROR\]' | grep -v -E 'Help 1|re-run Maven|For more information|full stack trace|See .*surefire|MojoFailure|^\[ERROR\] *$' | head -8)
|
|
[ -z "$SUMMARY" ] && SUMMARY=$(echo "$OUT" | tail -8)
|
|
jq -n --arg r "The test suite is red. Fix it before finishing:
|
|
$SUMMARY" '{decision: "block", reason: $r}'
|
|
fi
|
|
exit 0
|