#!/usr/bin/env bash
set -euo pipefail

# Local CI for Python projects.
# - Default skips live/real tests.
# - Opt in with: GATE_REAL=1 gate
# - Or pass custom args: GATE_PYTEST_ARGS='-m real' gate

uv run --locked --group dev ruff format --check .
uv run --locked --group dev ruff check .

py_versions=(3.10 3.11 3.12 3.13 3.14)

pytest_args=()
if [ "${GATE_REAL:-}" = "1" ] || [ "${GATE_REAL:-}" = "true" ]; then
    pytest_args+=("--run-live")
    if [ -z "${GATE_PYTEST_ARGS:-}" ]; then
        pytest_args+=("-m" "real")
    fi
else
    pytest_args+=("-m" "not real")
fi
if [ -n "${GATE_PYTEST_ARGS:-}" ]; then
    read -r -a extra_args <<<"${GATE_PYTEST_ARGS}"
    pytest_args+=("${extra_args[@]}")
fi

if [ -d "tests" ]; then
    for py in "${py_versions[@]}"; do
        echo "Testing with Python $py..."
        uv run --isolated --python "$py" --group dev -- pytest -q tests/ "${pytest_args[@]}"
    done
else
    echo "Warning: no tests/ directory; skipping pytest" >&2
fi
