#!/bin/sh
# Run all tests and display only failing tests (plus a summary).
# Keeps output focused so commit context isn't bloated.
#
# NOTE: It doesn't matter if you didn't introduce the failing tests —
# they should be handled before committing. A red main branch helps no one.

cd "$(dirname "$0")/../.."

echo "🧪 Running tests (only failures will be shown)..."

# Disable TTY progress bars for clean pre-commit output.
# Use `--reporter=default` which prints only failures + the final summary.
CI=true npx vitest run --reporter=default 2>&1
EXIT_CODE=$?

if [ $EXIT_CODE -ne 0 ]; then
  echo ""
  echo "⛔ Commit blocked: failing tests found."
  echo "   It doesn't matter if you didn't introduce the failing tests —"
  echo "   they should be handled before committing."
fi

exit $EXIT_CODE
