#!/bin/sh
# lint — the first rung of the gate ladder. Exits 0 when the code is clean.
#
# BioMCP: `make lint` — bin/lint (rustfmt, clippy, cargo deny) plus the
# quality ratchet. The template's "no Makefile target means nothing to lint"
# fallback is deliberately gone: this repo has the target, so a missing one
# is a broken checkout and must fail loudly rather than pass quietly.
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
*/lint) 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" lint
