#!/bin/bash
# CHECK-env-verifiers: grade the lane's two environment verifiers.
#
# Q109. The lane's own CHECK grades artifacts under an absolute /root path and
# runs none of the lane's test_*.py (that blindness is a separate item), so this
# file gives these two verifiers a gate of their own. The cell
# (test_env_verifiers.py) invokes both verifiers as subprocesses with stub
# modules on PYTHONPATH and synthetic Hermes trees, so it grades the tree it
# sits in -- the paths are resolved from the cell's own location.
#
# Exit codes follow the repo's tools/ contract:
#   0 = both verifiers measure what they claim
#   1 = a verifier regression (a cell failed)
#   2 = could not grade (no python3, or the cell does not import/collect)
set -e
set -o pipefail
cd "$(dirname "$(readlink -f "$0")")"

if ! command -v python3 >/dev/null 2>&1; then
    echo "CHECK: python3 not on PATH -- cannot grade." >&2
    exit 2
fi

set +e
python3 -m unittest -q test_env_verifiers >/tmp/.q109-check.out 2>&1
rc=$?
set -e
tail -3 /tmp/.q109-check.out

case $rc in
    0) echo "CHECK: both environment verifiers measure what they claim."; exit 0 ;;
    1) echo "CHECK: verifier contract broken -- a cell failed." >&2; exit 1 ;;
    *) echo "CHECK: unittest exited $rc -- collection error, could not grade." >&2; exit 2 ;;
esac
