#!/usr/bin/env bash
# pre-push — slicegate. FULL: selftest of every guard (negative cases) + whole-tree check + mutant anchors + duplicate ledger ids.
# fail-CLOSED: a guard RED or unable to run ⇒ push blocked.
ROOT="$(git rev-parse --show-toplevel)"
cd "$ROOT" || exit 1
SLICEGATE_BIN="${SLICEGATE_BIN:-}"
if command -v slicegate >/dev/null 2>&1; then GK=(slicegate)
elif [ -n "$SLICEGATE_BIN" ] && [ -x "$SLICEGATE_BIN" ]; then GK=("$SLICEGATE_BIN")
elif python3 -c "import slicegate" 2>/dev/null; then GK=(python3 -m slicegate)
else echo "pre-push: 🔴 slicegate not found (pip install it, or re-run `slicegate hooks install` from the plugin)"; exit 1; fi
"${GK[@]}" selftest >/dev/null || { "${GK[@]}" selftest; echo "pre-push: 🔴 selftest RED"; exit 1; }
"${GK[@]}" check --full || { echo "pre-push: 🔴 slicegate check --full RED"; exit 1; }
