#!/bin/bash
# CHECK-q87: grade the forge lane gate (Q87, 2026-10-31)
# Seven legs: the gate's own selftest, the shipped CHECK, --strict, and three
# mutants in a throwaway clone (drift, ungraded, causeless) plus a portability
# read from another cwd. See q87_verify.py's header for what each leg asserts.
set -o pipefail
cd "$(dirname "$(readlink -f "$0")")" || { echo "CHECK-q87: cannot cd to the lane" >&2; exit 2; }
command -v python3 >/dev/null || { echo "CHECK-q87: python3 not found -- cannot grade" >&2; exit 2; }
command -v git >/dev/null || { echo "CHECK-q87: git not found -- cannot grade" >&2; exit 2; }
set +e
python3 q87_verify.py --repo "$(dirname "$(readlink -f "$0")")/../.."
rc=$?
set -e
case $rc in
    0) ;;
    1) echo "CHECK-q87: a leg failed -- see the FAIL line above." >&2; exit 1 ;;
    2) echo "CHECK-q87: could not grade -- see the message above." >&2; exit 2 ;;
    *) echo "CHECK-q87: q87_verify.py exited $rc -- internal error (a fault)." >&2; exit 1 ;;
esac
exit 0
