#!/usr/bin/env bash
#
# Pre-push gate — mirrors .github/workflows/ci.yml so a red CI is caught locally,
# before the push leaves your machine. Enable once per clone with:
#
#     git config core.hooksPath .githooks
#
# Bypass a single push (not recommended) with:  git push --no-verify
#
set -euo pipefail

cd "$(git rev-parse --show-toplevel)"

step() {
    printf '\n\033[1m── %s ──\033[0m\n' "$*"
    if ! "$@"; then
        printf '\n\033[31m✗ pre-push blocked: `%s` failed.\033[0m\n' "$*"
        printf '  Fix it, then push again. Formatting drift? run: uv run ruff format .\n'
        printf '  To bypass this one push: git push --no-verify\n\n'
        exit 1
    fi
}

echo "pre-push: running the CI gate..."
step uv run ruff check .
step uv run ruff format --check .
step uv run pyright
step uv run pytest -q

printf '\n\033[32m✓ pre-push gate passed.\033[0m\n'
