set -u
ROOT="C:/Users/decid/Documents/projects/spt-core"
OUT="C:/Users/decid/AppData/Local/Temp/claude/C--Users-decid-Documents-projects-spt-core/1a98f6c1-6506-4a6a-8b21-46aaadf89acc/scratchpad/disc"
mkdir -p "$OUT"

FILTER='test(concurrent_writes_reconcile_on_elected_node_and_converge) + test(two_tier_sync_lands_and_gate_refuses_server_side) + test(clone_copies_without_trampling_and_stamps_what_it_copied) + test(different_monics_never_conflict_across_instances) + test(reconciled_write_propagates_and_clears_artifacts)'

run_leg () {
  lane="$1"; rep="$2"
  d="$ROOT/.worktrees/hertz-disc-$lane"
  tag="rep${rep}_${lane}"
  echo "LEG_START $tag $(date -u +%H:%M:%SZ)"
  ( cd "$d" && cargo nextest run --test-threads=1 --no-fail-fast -E "$FILTER" ) \
      > "$OUT/$tag.raw" 2>&1
  echo "$?" > "$OUT/$tag.exit"
  echo "LEG_END   $tag $(date -u +%H:%M:%SZ) exit=$(cat "$OUT/$tag.exit")"
}

for rep in 1 2 3; do
  # alternate which arm goes first, so order effects cancel as well as drift
  if [ $((rep % 2)) -eq 1 ]; then order="a-04e32c8c b-f6110c2a"; else order="b-f6110c2a a-04e32c8c"; fi
  for lane in $order; do
    run_leg "$lane" "$rep"
  done
done
echo "ALL LEGS DONE $(date -u +%H:%M:%SZ)"
