test: orchestrateur run-all-tests.sh (demande démarrage monde, rapport final)

This commit is contained in:
fabres
2026-08-04 21:36:12 +02:00
parent dca201c5e2
commit ac2e2027a0
+197
View File
@@ -0,0 +1,197 @@
#!/usr/bin/env bash
# ============================================================================
# run-all-tests.sh — Orchestrateur de tests TC-01 à TC-31
# Usage: ./run-all-tests.sh [OPTIONS]
# Env: URL, PASS (admin password)
#
# Options:
# --navigate Démarrer le monde (login admin) avant les tests
# --tests LIST Liste de tests à exécuter (ex: "01,02,08-10,15" ou "all")
# --no-report Ne pas afficher le rapport final
# --help Afficher l'aide
# ============================================================================
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/tc-header.sh"
# All available TC scripts (excluding tc-header.sh and run-all-tests.sh)
TC_SCRIPTS=()
for f in "$SCRIPT_DIR"/tc-[0-9][0-9]-*.sh; do
[ -f "$f" ] || continue
TC_SCRIPTS+=("$(basename "$f")")
done
TC_SCRIPTS=($(printf '%s\n' "${TC_SCRIPTS[@]}" | sort))
NAVIGATE=""
TESTS_FILTER=""
SHOW_REPORT=1
usage() {
cat <<EOF
Usage: $0 [OPTIONS]
Options:
--tests LIST Tests à exécuter: "01,02,08-10,15" ou "all" (défaut: all)
--no-report Ne pas afficher le rapport final
--help Cette aide
Le script demande à l'utilisateur de démarrer le monde manuellement
si game.ready n'est pas détecté au démarrage.
Exemples:
$0 --tests all
$0 --tests 01,02,08,10,12,15,16,22,27
$0 --tests 08-16 # TC-08 à TC-16
EOF
}
# ============================================================================
# Parse args
while [ $# -gt 0 ]; do
case "$1" in
--navigate) NAVIGATE="--navigate"; shift ;;
--tests) TESTS_FILTER="$2"; shift 2 ;;
--no-report) SHOW_REPORT=0; shift ;;
--help|-h) usage; exit 0 ;;
*) echo "Unknown option: $1"; usage; exit 1 ;;
esac
done
# ============================================================================
# Expand test filter (e.g. "01,08-10,15" -> list of numbers)
expand_filter() {
local filter="$1" out=()
IFS=',' read -ra parts <<< "$filter"
for part in "${parts[@]}"; do
if [[ "$part" =~ ^([0-9]+)-([0-9]+)$ ]]; then
local from=$((10#${BASH_REMATCH[1]})) to=$((10#${BASH_REMATCH[2]}))
for ((i=from; i<=to; i++)); do out+=("$(printf '%02d' "$i")"); done
elif [[ "$part" =~ ^[0-9]+$ ]]; then
out+=("$(printf '%02d' $((10#$part)))")
fi
done
printf '%s\n' "${out[@]}"
}
# Select tests
if [ -z "$TESTS_FILTER" ] || [ "$TESTS_FILTER" = "all" ]; then
SELECTED=()
for f in "${TC_SCRIPTS[@]}"; do
SELECTED+=("$f")
done
else
SELECTED=()
for num in $(expand_filter "$TESTS_FILTER"); do
for f in "${TC_SCRIPTS[@]}"; do
if [[ "$f" == "tc-${num}-"* ]]; then
SELECTED+=("$f")
break
fi
done
done
fi
[ ${#SELECTED[@]} -eq 0 ] && die "Aucun test sélectionné"
echo ""
echo "╔══════════════════════════════════════════════════════════════════════╗"
echo "║ Rêve de Dragon — Suite de Tests Automatisés ║"
echo "╚══════════════════════════════════════════════════════════════════════╝"
echo ""
echo " Tests sélectionnés (${#SELECTED[@]}):"
for f in "${SELECTED[@]}"; do
echo "$f"
done
echo ""
echo " URL: $URL"
echo ""
# ============================================================================
# Step 1: Ask user to start the world, then wait for game.ready
# ============================================================================
echo "→ Vérification session..."
R=$(jse_wait_ready 3 2)
if [ "$R" != "ready" ]; then
echo ""
echo " ⚠ Le monde n'est pas démarré dans chrome-devtools."
echo ""
echo " Instructions:"
echo " 1. Ouvrez https://localhost:31000 dans le navigateur chrome-devtools"
echo " 2. Sélectionnez le monde 'Reve de Dragon' et connectez-vous"
echo " 3. Attendez que la page /game soit chargée (game.ready=true)"
echo ""
read -p " Appuyez sur ENTRÉE quand le monde est démarré et game.ready=true... "
echo ""
echo "→ Attente de game.ready..."
R=$(jse_wait_ready 120 2)
fi
[ "$R" != "ready" ] && die "Game not ready (timeout 120s)"
echo " ✓ Game ready"
echo ""
# ============================================================================
# Step 2: Run tests
# ============================================================================
RESULTS=()
TOTAL_PASS=0
TOTAL_FAIL=0
TOTAL_ERRORS=0
for script in "${SELECTED[@]}"; do
path="$SCRIPT_DIR/$script"
[ ! -x "$path" ] && { echo "$script non exécutable"; continue; }
echo "────────────────────────────────────────────────────────────────"
echo "$script"
echo "────────────────────────────────────────────────────────────────"
# Run WITHOUT --navigate (we're already logged in)
output=$("$path" 2>&1)
rc=$?
echo "$output" | grep -E '^[║╔╚]|✔|✘|passed|---'
# Parse pass/fail from summary line
summary=$(echo "$output" | grep 'passed' | tail -1)
p=$(echo "$summary" | grep -oP '\d+(?= /)' || echo "0")
f=$(echo "$summary" | grep -oP '(?<=, )\d+(?= failed)' || echo "0")
TOTAL_PASS=$((TOTAL_PASS + p))
TOTAL_FAIL=$((TOTAL_FAIL + f))
[ $rc -ne 0 ] && TOTAL_ERRORS=$((TOTAL_ERRORS + 1))
RESULTS+=("$script|$p|$f|$rc")
echo ""
done
# ============================================================================
# Step 3: Final report
# ============================================================================
if [ "$SHOW_REPORT" -eq 1 ]; then
echo ""
echo "╔══════════════════════════════════════════════════════════════════════╗"
echo "║ RAPPORT FINAL ║"
echo "╠══════════════════════════════════════════════════════════════════════╣"
printf "║ %-40s %4s %4s %4s %-6s ║\n" "Test" "Pass" "Fail" "RC" "Status"
echo "╠══════════════════════════════════════════════════════════════════════╣"
for r in "${RESULTS[@]}"; do
IFS='|' read -r name p f rc <<< "$r"
status="✔"
[ "$f" -gt 0 ] && status="✘"
[ "$rc" -ne 0 ] && status="⚠"
printf "║ %-40s %4s %4s %4s %-6s ║\n" "$name" "$p" "$f" "$rc" "$status"
done
echo "╠══════════════════════════════════════════════════════════════════════╣"
TOTAL=$((TOTAL_PASS + TOTAL_FAIL))
printf "║ %-40s %4s %4s %4s %-6s ║\n" "TOTAL" "$TOTAL_PASS" "$TOTAL_FAIL" "$TOTAL_ERRORS" ""
echo "╠══════════════════════════════════════════════════════════════════════╣"
if [ "$TOTAL_FAIL" -eq 0 ] && [ "$TOTAL_ERRORS" -eq 0 ]; then
echo "║ ✔ TOUS LES TESTS PASSENT ║"
else
printf "║ ✘ %d/%d tests échouent, %d scripts en erreur ║\n" "$TOTAL_FAIL" "$TOTAL" "$TOTAL_ERRORS"
fi
echo "╚══════════════════════════════════════════════════════════════════════╝"
echo ""
fi
[ "$TOTAL_FAIL" -gt 0 ] || [ "$TOTAL_ERRORS" -gt 0 ] && exit 1 || exit 0