#!/usr/bin/env bash # CHECK-q166 -- the binary-search bounds test binds the module BESIDE itself, # not a directory of the host that ran it. # # The defect (Q166, 2026-11-03): `test_binary_search_bounds.py` landed at # `2829ff0` with `sys.path.insert(0, "/root/.hermes/wizard-outputs/beam")` -- # a directory outside the repository. `tools/import_resolve_check.py` read # `FAULT OUTSIDE_REPO wizard-work/beam/test_binary_search_bounds.py:2` at this # tree, and the repo gate's import-resolve leg went red on it. The file also # shipped with no `test_*` function, so the lane runner read it as # `unittest=0 bare=0` and a wrong bound showed up as an import error against # the file rather than as a named failing cell. # # Four legs: # bind the test names no host directory and does bind its own: the # `HERE` binding and the resolved-module assertion are both present # tool `tools/import_resolve_check.py` reports 0 fault(s) and names this # file nowhere in its faults array -- the leg that caught it # cells a scratch lane holding this test and its module reads rc 0 with # 2 bare case(s): the checks are attributed cells now # poison the same lane with `binary_search_bounds.py` replaced by a # stand-in that answers 0/0/True reads rc 1 and names a bounds # cell, so the green above is the module beside the test # # Exit codes: 0 all legs passed, 1 a fault, 2 could not grade. set -u set -o pipefail cd "$(dirname "${BASH_SOURCE[0]}")" || exit 2 ROOT="$(pwd)" LANE="$ROOT/wizard-work/beam" TEST="$LANE/test_binary_search_bounds.py" MOD="$LANE/binary_search_bounds.py" RUNNER="$LANE/run_lane_tests.py" TOOL="$ROOT/tools/import_resolve_check.py" PY="${PYTHON:-python3}" for f in "$TEST" "$MOD" "$RUNNER" "$TOOL"; do if [ ! -f "$f" ]; then printf 'CANNOT GRADE: missing %s\n' "$f" exit 2 fi done WORK="$(mktemp -d "${TMPDIR:-/tmp}/check-q166.XXXXXX")" || exit 2 trap 'rm -rf "$WORK"' EXIT passed=0 failed=0 row() { printf ' %-8s %s\n' "$1" "$2"; } verdict() { if [ "$2" -eq 0 ]; then passed=$((passed + 1)); else failed=$((failed + 1)); fi; row "$1" "$3"; } # --- leg 1: the binding is beside the test, not on the host ----------------- # Only the code line counts: a quoted path inside the file's docstring is the # history of the defect, and `^sys.path.insert(0, "` matches no such prose. quotedbind="$(grep -c '^sys\.path\.insert(0, "' "$TEST")" hereline="$(grep -c 'sys.path.insert(0, HERE)' "$TEST")" assertline="$(grep -c 'not the module beside this file' "$TEST")" verdict bind \ "$([ "$quotedbind" -eq 0 ] && [ "$hereline" -ge 1 ] && [ "$assertline" -ge 1 ] && echo 0 || echo 1)" \ "quotedBinds=$quotedbind HERE-bind=$hereline resolve-assert=$assertline" # --- leg 2: the tool that caught it reads the file clean -------------------- "$PY" "$TOOL" --json "$WORK/rows.json" --quiet > "$WORK/tool.log" 2>&1; trc=$? named="$(grep -c 'test_binary_search_bounds' "$WORK/rows.json")" verdict tool \ "$([ "$trc" -eq 0 ] && grep -q '"faults": \[\]' "$WORK/rows.json" \ && [ "$named" -eq 0 ] && echo 0 || echo 1)" \ "rc=$trc faults-named=$(printf '%s' "$named") $(tail -1 "$WORK/tool.log")" # --- leg 3: the cells are collected and green beside the module ------------- mkdir -p "$WORK/lane" || exit 2 cp "$TEST" "$MOD" "$WORK/lane/" || exit 2 out="$("$PY" "$RUNNER" --lane "$WORK/lane" 2>&1)"; crc=$? last="$(printf '%s' "$out" | tail -1)" cells="$(printf '%s' "$out" | grep -c '2 bare case(s)')" verdict cells \ "$([ "$crc" -eq 0 ] && [ "$cells" -ge 1 ] && printf '%s' "$last" | grep -q 'lane: OK' && echo 0 || echo 1)" \ "rc=$crc ${last:-}" # --- leg 4: a stand-in beside it reds, so the green is this file ------------ mkdir -p "$WORK/poison" || exit 2 cp "$TEST" "$WORK/poison/" || exit 2 printf 'def bisect_left(a, x):\n return 0\n\n\ndef bisect_right(a, x):\n return 0\n\n\ndef contains(a, x):\n return True\n' > "$WORK/poison/binary_search_bounds.py" || exit 2 out="$("$PY" "$RUNNER" --lane "$WORK/poison" 2>&1)"; prc=$? last="$(printf '%s' "$out" | tail -1)" namedcell="$(printf '%s' "$out" | grep -c 'test_bounds_')" verdict poison \ "$([ "$prc" -eq 1 ] && printf '%s' "$last" | grep -q 'lane: FAULT' \ && [ "$namedcell" -ge 1 ] && echo 0 || echo 1)" \ "rc=$prc (want 1) cells-named=$namedcell ${last:-}" if [ "$failed" -eq 0 ]; then echo "q166: $passed leg(s), 0 fault(s), rc 0" exit 0 fi echo "q166: $passed passed, $failed fault(s), rc 1" exit 1