#!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

ENABLE_GPU=false

usage() {
  cat <<'EOF'
Usage: 00_e2e_test.sh [options]

Options:
  --enable-gpu   启用 GPU 相关拓扑与测试流程
  -h, --help     显示帮助信息
EOF
}

while [[ $# -gt 0 ]]; do
  case "$1" in
    --enable-gpu)
      ENABLE_GPU=true
      shift
      ;;
    -h|--help)
      usage
      exit 0
      ;;
    *)
      echo "Unknown argument: $1" >&2
      usage
      exit 1
      ;;
  esac
done

export ARGUS_SYS_ENABLE_GPU=$ENABLE_GPU

SCRIPTS=(
  "01_bootstrap.sh"
  "02_up.sh"
  "03_wait_ready.sh"
  "04_verify_dns_routing.sh"
  "05_agent_register.sh"
  "06_write_health_and_assert.sh"
  "07_logs_send_and_assert.sh"
  "08_restart_agent_reregister.sh"
  "10_metric_publish.sh"
  "11_metric_node_install.sh"
  "12_metric_gpu_install.sh"
  "13_metric_verify.sh"
  "14_metric_cleanup.sh"
  "09_down.sh"
)

for script in "${SCRIPTS[@]}"; do
  echo "[SYS-E2E] Running $script"
  "$SCRIPT_DIR/$script"
  echo "[SYS-E2E] $script completed"
  echo
done

echo "[SYS-E2E] All tests completed"
