Files
ObsiGate/scripts/run-e2e-local.sh
T
bruno 7d70e0fb75
CI / lint (push) Failing after 1m51s
CI / test (push) Skipped
CI / build (push) Skipped
CI / e2e (push) Skipped
CI / security (push) Failing after 1m33s
fix: harnais E2E local anti-blocage BUG-080
2026-09-27 09:08:58 -04:00

131 lines
4.8 KiB
Bash

#!/usr/bin/env bash
# =============================================================================
# ObsiGate — E2E locaux (Playwright) dans les mêmes conditions que le CI
# =============================================================================
# Démarre le backend nativement (uvicorn, Python 3.11 via uv) avec :
# - auth désactivée (OBSIGATE_AUTH_ENABLED=false, comme le CI)
# - fixtures TestVault/TestDir (comme le CI)
# - port 2029 (BASE_URL par défaut de playwright.config.ts)
# puis exécute la suite Playwright complète (projet chromium-desktop)
# et nettoie tout à la sortie.
#
# Usage :
# ./scripts/run-e2e-local.sh # suite complète (desktop)
# ./scripts/run-e2e-local.sh --headed # avec navigateur visible
# ./scripts/run-e2e-local.sh -g "reset panes" # filtre Playwright
#
# Prérequis : uv, Node.js. Le venv .venv-e2e est créé automatiquement.
# =============================================================================
set -euo pipefail
cd "$(dirname "$0")/.."
PORT="${E2E_PORT:-2029}"
BASE_URL="http://127.0.0.1:$PORT"
SERVER_LOG="data/e2e-server.log"
# BUG-080 : garde-fous anti-blocage (un run E2E ne doit jamais pendre toute la nuit).
E2E_TIMEOUT_SEC="${E2E_TIMEOUT_SEC:-900}"
E2E_BROWSER_INSTALL_TIMEOUT_SEC="${E2E_BROWSER_INSTALL_TIMEOUT_SEC:-600}"
# Exécute "$@" avec un timeout dur (exit 124 comme `timeout`), sans timeout si
# la commande `timeout` est absente (ex. macOS sans coreutils).
run_with_timeout() {
local limit="$1"; shift
if command -v timeout &>/dev/null; then
timeout "$limit" "$@"
else
echo "[WARN] commande 'timeout' absente : $1 sans limite de ${limit}s" >&2
"$@"
fi
}
# ----- Prérequis -----
if ! command -v uv &>/dev/null; then
echo "[ERR] uv introuvable. Installez-le : https://docs.astral.sh/uv/" >&2
exit 1
fi
if ! command -v npx &>/dev/null; then
echo "[ERR] npx introuvable. Installez Node.js." >&2
exit 1
fi
# ----- Venv Python 3.11 (créé une seule fois) -----
if [[ -x ".venv-e2e/Scripts/python.exe" ]]; then
PYTHON=".venv-e2e/Scripts/python.exe"
elif [[ -x ".venv-e2e/bin/python" ]]; then
PYTHON=".venv-e2e/bin/python"
else
echo "[INFO] Création du venv .venv-e2e (Python 3.11)..."
uv venv .venv-e2e --python 3.11
PYTHON=".venv-e2e/Scripts/python.exe"
[[ -x "$PYTHON" ]] || PYTHON=".venv-e2e/bin/python"
uv pip install --python "$PYTHON" -r backend/requirements.txt
fi
# ----- Port déjà occupé ? -----
if curl -sf "$BASE_URL/api/health" >/dev/null 2>&1; then
echo "[ERR] Quelque chose répond déjà sur $BASE_URL." >&2
echo " Arrêtez-le ou choisissez un autre port : E2E_PORT=2030 $0" >&2
exit 1
fi
# ----- Démarrage du serveur (mêmes conditions que le CI e2e) -----
echo "[INFO] Démarrage d'ObsiGate sur $BASE_URL (auth désactivée)..."
mkdir -p data
# Sous MSYS/git-bash, les env vars ne sont PAS converties : un chemin
# '/c/dev/...' est illisible pour le python natif Windows → vaults vides.
if command -v cygpath &>/dev/null; then
VP="$(cygpath -w "$PWD/test_vault")"
DP="$(cygpath -w "$PWD/test_dir")"
else
VP="$PWD/test_vault"
DP="$PWD/test_dir"
fi
OBSIGATE_AUTH_ENABLED=false \
VAULT_1_NAME=TestVault \
VAULT_1_PATH="$VP" \
DIR_1_NAME=TestDir \
DIR_1_PATH="$DP" \
"$PYTHON" -m uvicorn backend.main:app --host 127.0.0.1 --port "$PORT" \
>"$SERVER_LOG" 2>&1 &
SERVER_PID=$!
cleanup() {
echo "[INFO] Arrêt du serveur (PID $SERVER_PID)..."
kill "$SERVER_PID" 2>/dev/null || true
wait "$SERVER_PID" 2>/dev/null || true
}
trap cleanup EXIT
# ----- Attente du health check (30 s max, comme le CI) -----
for _ in $(seq 1 30); do
if curl -sf "$BASE_URL/api/health" >/dev/null 2>&1; then
echo "[OK] Serveur prêt."
break
fi
if ! kill -0 "$SERVER_PID" 2>/dev/null; then
echo "[ERR] Le serveur a quitté prématurément. Log :" >&2
tail -30 "$SERVER_LOG" >&2
exit 1
fi
sleep 1
done
curl -sf "$BASE_URL/api/health" >/dev/null || {
echo "[ERR] Serveur injoignable sur $BASE_URL. Log :" >&2
tail -30 "$SERVER_LOG" >&2
exit 1
}
# ----- Browsers Playwright (no-op s'ils sont déjà installés) -----
# BUG-080 : `--yes` (jamais de prompt interactif npx qui pend), skip si un
# chromium est déjà présent (sauf E2E_INSTALL_BROWSERS=1), timeout dédié.
if [[ "${E2E_INSTALL_BROWSERS:-0}" == "1" ]] || ! ls -d ~/.cache/ms-playwright/chromium-*/chrome-linux/chrome &>/dev/null; then
run_with_timeout "$E2E_BROWSER_INSTALL_TIMEOUT_SEC" npx --yes playwright install chromium
else
echo "[INFO] Chromium Playwright déjà installé, étape sautée (E2E_INSTALL_BROWSERS=1 pour forcer)."
fi
# ----- Exécution de la suite (projet CI : chromium-desktop) -----
echo "[INFO] BASE_URL=$BASE_URL npx playwright test --project=chromium-desktop $*"
BASE_URL="$BASE_URL" run_with_timeout "$E2E_TIMEOUT_SEC" npx --yes playwright test --project=chromium-desktop "$@"