Files
ObsiGate/scripts/run-e2e-local.sh
T
bruno 212753f311
CI / lint (push) Successful in 42s
CI / security (push) Successful in 27s
CI / test (push) Successful in 55s
CI / build (push) Successful in 23s
CI / e2e (push) Successful in 9m33s
test(e2e): #75 I3 — matrice ouverture/fermeture split view (21 tests) + fix chemins Windows run-e2e-local.sh
2026-09-08 09:38:10 -04:00

110 lines
3.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"
# ----- 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) -----
npx playwright install chromium
# ----- 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" npx playwright test --project=chromium-desktop "$@"