#!/usr/bin/env bash
# null lane gate -- one command, and the exit code IS the verdict.
#
#   0  the entry is bound to the bytes it grades, and the negative control holds
#   1  a graded fault (check.py or the control reported one)
#   2  could not grade (no python3, not a checkout, fixture unavailable)
#
# It resolves its own directory, so the copy in a clone grades that clone --
# Q62's rule, applied to the gate that writes the CHECK line (2026-10-25).
#
#   bash wizard-work/null/CHECK        # from the repository root
set -u

d=$(dirname "$(readlink -f "$0")")

echo "== check.py: the entry against the remote main =="
python3 "$d/check.py"
a=$?

echo
echo "== q57_mutation.py: the gate's own negative control =="
python3 "$d/q57_mutation.py"
b=$?

if [ "$a" -eq 0 ] && [ "$b" -eq 0 ]; then
    echo
    echo "LANE GATE GREEN"
    exit 0
fi
if [ "$a" -eq 2 ] || [ "$b" -eq 2 ]; then
    echo
    echo "LANE GATE: COULD NOT GRADE (check.py rc=$a, q57_mutation.py rc=$b)"
    exit 2
fi
echo
echo "LANE GATE: FAULT (check.py rc=$a, q57_mutation.py rc=$b)"
exit 1
