#!/bin/sh
# test — the second rung of the gate ladder. Exits 0 when the tests pass.
#
# BioMCP: `make test` — the Rust suite under nextest, then the contract
# tests (python via uv) and a strict mkdocs build. It takes about ten
# minutes; that is expected, not a hang. As in `lint`, the template's
# "no target means nothing to run" fallback is gone on purpose.
set -eu

# The repo is this script's own home when invoked as a file — prepare and
# the template tests run it from arbitrary working directories, and cwd
# resolution here once made a test suite run itself recursively (the
# 2026-08-06 storm). Only a gate piping it into sh ($0 names no file)
# falls back to the working tree, which is exactly the tree it judges.
case $0 in
*/test) REPO=$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd) ;;
*) REPO=$(git rev-parse --show-toplevel) ;;
esac

# Reentrancy sentinel, scoped to the repo: a check for THIS repo already
# running above us means some path is recursive — fail loudly instead of
# forking a storm (2026-08-06). A different repo (a test fixture) is fine.
if [ "${SDLC_IN_CHECK-}" = "$REPO" ]; then
	echo "refusing: a check for $REPO is already running above us (recursion)" >&2
	exit 2
fi
export SDLC_IN_CHECK="$REPO"

exec make -C "$REPO" test
