#!/usr/bin/env bash
# Wave-3 consumer batteries: the 15 test files that parse a token whose emitter
# wave 3 rewrote. Per-file exit codes, each captured to its OWN file — a wrapper's
# status would read 0 over a leg's failure.
set -u
S="C:/Users/decid/AppData/Local/Temp/claude/C--Users-decid-Documents-projects-spt-core/43af483b-6d22-46cb-9d99-8b7713a6ff46/scratchpad"
cd "C:/Users/decid/Documents/projects/spt-core/.worktrees/emit-single-write" || exit 2

# PREBUILD the fixture bins first: `--test` legs never emit them, and the panic
# text of the cell that needs one names this step (banked craft, doyle).
( cargo build -p spt --bins > "$S/w3c_prebuild.raw" 2>&1 )
echo $? > "$S/w3c_prebuild.exit"

run_one() {
  local pkg="$1" name="$2"
  ( cargo nextest run -p "$pkg" --test "$name" > "$S/w3c_${name}.raw" 2>&1 )
  echo $? > "$S/w3c_${name}.exit"
  printf '%s\t%s\t%s\n' "$pkg" "$name" "$(cat "$S/w3c_${name}.exit")" >> "$S/w3c_summary.tsv"
}

: > "$S/w3c_summary.tsv"

for n in inject_control_wedge redispatch redispatch_stall restart_replay_lifetime transport_death_eof; do
  run_one spt-daemon "$n"
done
for n in endpoint_autostart_e2e engine_room_bringup_e2e er_brief_once_per_session_e2e \
         er_briefing_session_scoped_e2e er_inbound_local er_sequestered_cwd_e2e \
         knock_approve_not_hostage_e2e rc_attach_truth shell_relink_force_e2e \
         shell_stale_online_e2e; do
  run_one spt "$n"
done

echo "DONE" > "$S/w3c_all.done"
