#!/bin/bash
#
# test_all_builds.sh — run the end-to-end verify across every supported visionOS build.
#  - Niall George Horn; June 2026
#
# verify.sh checks ONE build (whatever setup.sh stages). This script just loops
# it over each version via the COREIK_VERSION env var and tallies the results —
# no new logic, it only orchestrates. Use it to confirm the solver still fires
# after Apple ships a new visionOS (which, reliably, they do).
#
# Heads up: verify.sh is interactive — it waits for you to tap "Enter Immersive
# Space" in the Simulator. So is this. You'll do that once per version.
#
# Versions not installed locally will just report FAIL (setup.sh can't find the
# runtime) and the sweep moves on to the next. Edit VERSIONS when a new build
# becomes supported.
#
# Usage:
#   ./deploy/test_all_builds.sh
#

set -uo pipefail   # deliberately NOT -e: one failing build must not abort the sweep

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

# Supported builds to sweep. 26.2 is the canonical tribunal-demo build; 26.5 is
# current mainline. Add a version here once its offsets are committed.
VERSIONS=(26.2 26.4.1 26.5)

GREEN='\033[0;32m'; RED='\033[0;31m'; BOLD='\033[1m'; CYAN='\033[0;36m'; RESET='\033[0m'

declare -a RESULTS=()
for v in "${VERSIONS[@]}"; do
    echo ""
    echo -e "${BOLD}${CYAN}━━━━━━━━━━ Verifying visionOS ${v} ━━━━━━━━━━${RESET}"
    # Inline env var — verify.sh (and the setup.sh it calls) reads COREIK_VERSION.
    if COREIK_VERSION="$v" "${SCRIPT_DIR}/verify.sh"; then
        RESULTS+=("${GREEN}PASS${RESET}  visionOS ${v}")
    else
        RESULTS+=("${RED}FAIL${RESET}  visionOS ${v}  (not installed, or solver did not fire)")
    fi
done

echo ""
echo -e "${BOLD}${CYAN}━━━━━━━━━━ Cross-build summary ━━━━━━━━━━${RESET}"
for line in "${RESULTS[@]}"; do echo -e "  $line"; done
echo ""
