set -u
REPO=/home/reavus/projects/spt-core/spt-core; RIG=$REPO/.worktrees/hertz-185a-rig; T=$RIG/target
echo "PRE-REGISTERED: reclaim within +/-0.1% of alloc - escaped. $(date -u +%T.%3N)"
w(){ echo "WRITERS@$(date -u +%T): $(ps -eo comm= | grep -cE '^(cargo|rustc|cargo-nextest|Runner.Worker)$') load $(cut -d' ' -f1 /proc/loadavg)"; }
w
echo "OUTBOUND: $(stat -c %F $T) symlink=$([ -L $T ] && echo YES || echo no)"; [ -L $T ] && exit 3
AP=$(du -sb --apparent-size $T | cut -f1); AL=$(du -sB1 $T | cut -f1)
read EN EB < <(find $T -type f -links +1 -printf '%i %n %s\n' | sort | uniq -c | awk '$1 < $3 { n++; b += $4 } END { print n+0, b+0 }')
echo "SIZES apparent=$AP allocated=$AL escaped=$EN/$EB population=$(find $T -type f -links +1 | wc -l) maxn=$(find $T -type f -printf '%n\n' | sort -n | tail -1)"
echo "INBOUND symlinks=$(find /home/reavus -xdev -type l -lname "*hertz-185a-rig/target*" 2>/dev/null | wc -l) mounts=$(findmnt -rn -o TARGET | grep -c hertz-185a-rig) open=$(lsof +D $T 2>/dev/null | tail -n +2 | wc -l)"
w; sync; F0=$(df -B1 --output=avail / | tail -1 | tr -d ' ')
rm -rf $T; sync; sleep 5; F1=$(df -B1 --output=avail / | tail -1 | tr -d ' '); w
E=$((AL-EB)); D=$((F1-F0)); echo "EXPECTED=$E RECLAIM=$D GAP=$((D-E)) PCT=$(awk -v d=$D -v e=$E 'BEGIN{printf "%.4f",(d-e)*100/e}')"
cd $REPO && git worktree remove $RIG && echo "wt removed" && git branch -D hertz/185a >/dev/null && echo "branch ref dropped"
rm -rf /tmp/hertz-185a-rt /tmp/hertz-185a /tmp/hertz-185a.bundle /tmp/hertz-185a-b.bundle /tmp/rc185.bak /tmp/rc.bak; git worktree list | grep -c hertz
