#!/usr/bin/env bash
# Verification gate for the active build-your-own-x challenge.
# The agent MUST run this before claiming any feature is done.
# It re-runs ALL feature tests so earlier work can't silently regress.
# fail fast: set -e aborts on any unguarded error; guarded commands use `|| rc=$?`.
set -euo pipefail
CHALLENGE_ID="git-python"
WORKSPACE="workspace/${CHALLENGE_ID}"
ROOT="$(cd "$(dirname "$0")" && pwd)"
cd "$ROOT"
echo "== build-your-own-x harness :: verifying [${CHALLENGE_ID}] =="
# --- toolchain check -------------------------------------------------------
if ! command -v python3 >/dev/null 2>&1; then
echo "FAIL: python3 not found on PATH" >&2
exit 1
fi
if ! command -v git >/dev/null 2>&1; then
echo "WARN: real 'git' not found — tests that compare against real git will skip/fail" >&2
fi
# --- workspace check -------------------------------------------------------
if [ ! -d "$WORKSPACE" ]; then
echo "NOTE: $WORKSPACE does not exist yet."
echo " This is expected before the first feature is started."
echo " Create it, add your implementation + tests/, then re-run ./init.sh"
exit 2
fi
cd "$WORKSPACE"
# Ensure pytest is available (don't install silently — just report).
if ! python3 -c "import pytest" >/dev/null 2>&1; then
echo "FAIL: pytest not importable. Install with: python3 -m pip install pytest" >&2
exit 1
fi
# --- run the full feature test suite --------------------------------------
if [ -d tests ]; then
echo "-- running full test suite (all features) --"
RC=0
python3 -m pytest tests -q || RC=$?
if [ "$RC" -eq 0 ]; then
echo "PASS: all feature tests green"
else
echo "FAIL: test suite red (rc=$RC) — fix before marking any feature done" >&2
fi
exit $RC
else
echo "NOTE: no tests/ directory yet in $WORKSPACE."
echo " Add tests/ mirroring feature_list.json 'verify' commands, then re-run."
exit 2
fi