set +e
TGT=~/actions-runner/_work/spt-core/spt-core/target
T=attach_survives_target_brain_restart_exactly_once
cd ~/actions-runner/_work/spt-core/spt-core
git worktree add -f --detach /tmp/p1ciso2 9b0025b >/dev/null 2>&1
cd /tmp/p1ciso2
p=0; f=0; h=0
for i in $(seq 1 12); do
  R=$(CARGO_TARGET_DIR=$TGT timeout 90 cargo test -p spt-daemon --test attach $T -- --test-threads=1 2>&1); C=$?
  pkill -9 -f attach- 2>/dev/null
  if [ $C -eq 124 ]; then h=$((h+1)); echo "iso $i: HANG"
  elif echo "$R" | grep -q "test result: ok"; then p=$((p+1)); echo "iso $i: PASS"
  else f=$((f+1)); L=$(echo "$R" | grep -oE "attach.rs:[0-9]+:[0-9]+|output gap[^\"]*" | head -1); echo "iso $i: FAIL($L)"; fi
done
echo "=== ISO-CLEAN RESULT P=$p F=$f H=$h ==="
cd ~/actions-runner/_work/spt-core/spt-core && git worktree remove --force /tmp/p1ciso2 2>/dev/null
echo ISO2-DONE
