#!/bin/bash
# Pre-push hook: Run full regression suite with coverage before allowing push
# Install: cp .githooks/pre-push .git/hooks/pre-push && chmod +x .git/hooks/pre-push

set -e

echo "🔒 Running full regression test suite with coverage enforcement..."
echo ""

# Change to repository root
cd "$(git rev-parse --show-toplevel)/codebase/features/status-dashboard/server"

# Check if node_modules exists
if [ ! -d "node_modules" ]; then
    echo "⚠️  node_modules not found. Installing dependencies..."
    pnpm install
fi

# Run full test suite with coverage
echo "Running full test suite with 80% coverage threshold..."
if ! pnpm run test:regression; then
    echo ""
    echo "❌ Regression tests failed or coverage below 80%. Push blocked."
    echo ""
    echo "To fix:"
    echo "  1. Run: pnpm run test:cov"
    echo "  2. Review coverage report in coverage/index.html"
    echo "  3. Add tests to meet 80% threshold"
    echo "  4. Fix any failing tests"
    echo "  5. Try pushing again"
    echo ""
    echo "To bypass (NOT RECOMMENDED - will fail in CI):"
    echo "  git push --no-verify"
    echo ""
    exit 1
fi

echo ""
echo "✅ All regression tests passed with coverage > 80%. Proceeding with push..."
echo ""

exit 0
