#!/usr/bin/env bash
# Single regression entry point for the bulletproof dispatch chassis (REC-77).
# Aggregates the per-component behavioral tests; fails if any one fails.
set -uo pipefail

HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$HERE/../../../.." && pwd)"
cd "$REPO_ROOT"

FAILED=0
run() {
  local label="$1"; shift
  echo "=== $label ==="
  if "$@"; then
    echo "  OK: $label"
  else
    echo "  FAIL: $label"
    FAILED=1
  fi
}

run "dispatch_status"        env PYTHONPATH=. python3 recoil/pipeline/tools/tests/test_dispatch_status.py
run "dispatch_notify"        bash recoil/pipeline/tools/tests/test_dispatch_notify.sh
run "dispatch_reaper"        bash recoil/pipeline/tools/tests/test_dispatch_reaper.sh
run "terminal_status_trap"   bash recoil/pipeline/tools/tests/test_terminal_status_trap.sh
run "harness_final_step_a"   bash recoil/pipeline/tools/tests/test_harness_final_step_a.sh

echo "--------"
if [ "$FAILED" -ne 0 ]; then
  echo "CHASSIS REGRESSION: FAIL"
  exit 1
fi
echo "CHASSIS REGRESSION: PASS"
