#!/bin/bash
# Full local coverage gate for pull requests, merges, releases, and
# verification-infrastructure changes. CI keeps a separate workflow.
# ruff lint, ruff format, mypy, version sync, pytest with coverage.
set -euo pipefail
cd "$(dirname "$0")/.."

if [ -z "${BRIGADE_VERIFY_LOCK_HELD:-}" ]; then
  if [ -n "${BRIGADE_VERIFY_LOCK_PYTHON:-}" ]; then
    lock_python=$BRIGADE_VERIFY_LOCK_PYTHON
  else
    lock_python=${PY:-.venv/bin}/python
  fi
  exec "$lock_python" scripts/verify_lock.py "$@"
fi

PY=${PY:-.venv/bin}
"$PY/python" scripts/verify_env.py
"$PY/ruff" check .
"$PY/ruff" format --check .
"$PY/mypy"
# Version sync covers __init__.py, template JSONs, and the recorded demo assets.
# Run `python scripts/version_sync.py --write` to fix drift in one shot.
"$PY/python" scripts/version_sync.py --check
"$PY/python" scripts/managed_snapshot.py --check
"$PY/python" scripts/template_profile_snapshot.py --check
"$PY/pytest" -q --cov=brigade --cov-report=term --cov-fail-under=78
