#!/usr/bin/env bash
# doyle gate driver for hertz LEAK rider 84e359aa (test/309-legacy-psyche-leak) — sequential takeover of hertz's released pool
set -u
ROOT=/c/Users/decid/Documents/projects/spt-core
WT=$ROOT/.worktrees/hertz-309-er-briefing
G=$ROOT/.spt/preserved/309/gate-leak-84e359aa
P=$G/phases.txt
unset OWL_SESSION_ID SPT_SESSION_ID SPT_ENDPOINT CLAUDE_SESSION_ID SPT_HOME 2>/dev/null
env | grep -Ei '^(OWL|SPT|CLAUDE|CARGO)' > $G/env-after-scrub.txt
phase(){ echo "$(date -u +%H:%M:%SZ) $1 exit=$2" | tee -a $P; }
cd "$WT" || { phase cd 99; exit 99; }
H=$(git rev-parse HEAD); WANT=$(git rev-parse --verify 84e359aa^{commit})
echo "HEAD=$H WANT=$WANT" > $G/subject.txt; git status --short >> $G/subject.txt
[ "$H" = "$WANT" ] || { phase subject-mismatch 98; exit 98; }
[ "$(git status --short | wc -l)" = "0" ] || { phase subject-dirty 97; exit 97; }
phase subject 0
cargo run -q -p xtask -- pool-claim --pool target --label gate-leak > $G/claim.log 2>&1; phase pool-claim $?
traceable-reqs check > $G/checker.log 2>&1; phase checker $?
export CARGO_BUILD_JOBS=2
for i in 1 2 3; do
  cargo nextest run --locked -j 2 -p spt-daemon --lib -E 'test(legacy_psyche_sweep_guard)' --retries 0 --no-fail-fast --status-level all --failure-output immediate-final --no-tests fail > $G/cell-$i.log 2>&1; phase cell-$i $?
done
cargo nextest run --locked -j 2 -p spt-daemon --lib -E 'test(livehost::)' --retries 0 --no-fail-fast --status-level all --failure-output immediate-final --no-tests fail > $G/livehost-unit.log 2>&1; phase livehost-unit $?
cargo run -q -p xtask -- pool-release --pool target > $G/release.log 2>&1; phase pool-release $?
phase DONE 0
