#!/bin/sh
# hooks/pre-push — opt-in fast-gate runner.
#
# Install (one-time, per checkout):
#   ln -s ../../hooks/pre-push .git/hooks/pre-push
#
# Runs lint + types + `mgf-test-supervisor --tier 0-1
# --skip-quarantined` (tier-0 smoke + tier-1 unit/contract/property
# — the daily-contract subset that catches ~95% of regressions
# while staying under ~5s).
#
# Bypass in genuine emergencies: `git push --no-verify`.
#
# Why mgf-test-supervisor, not scripts/gates: the supervisor is
# budget-aware, skips quarantined tests, and writes structured
# per-test telemetry to `.gates/last-run/`. Full four-gate
# scripts/gates is what CI runs on push to main
# (see `.woodpecker.yml`).
#
# History: pre-2026-05-26 this hook invoked the in-tree
# `scripts/mtest --tier 0-1`. Extraction of mgf-test-supervisor
# v0.1.0/v0.1.1 retired the in-tree copy; the supervisor is now
# a dev dep + the daemon-name probe is wired via
# MGF_TEST_SUPERVISOR_DAEMON_PROCESS_NAME below.

set -e

REPO_ROOT="$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)"

# Anchor the supervisor's discovery at this repo + wire the
# daemon-name override so failure bundles include the broker
# state. Symmetric with the smoke-test env-var pattern.
export MGF_TEST_SUPERVISOR_REPO_ROOT="$REPO_ROOT"
export MGF_TEST_SUPERVISOR_DAEMON_PROCESS_NAME="mgf-hrb-server"

# Quick lint + types — both sub-second, always cheap.
"$REPO_ROOT/.venv/bin/python" -m ruff check src tests
"$REPO_ROOT/.venv/bin/python" -m mypy --strict src

exec "$REPO_ROOT/.venv/bin/python" -m mgf.test_supervisor --tier 0-1 --skip-quarantined
