Repository Public
1#!/usr/bin/env bash2# Author: Simon-Pierre Boucher — contact@spboucher.ai3# File: Scripts/integration-test.sh4# Description: Runs the end-to-end core tests (v1 journey + backend 1.0 additions) against the DEVELOPMENT backend (never production) through an SSH tunnel.5#6# Usage: Scripts/integration-test.sh [--journey]7# default backend 1.0 suite (NextGenIntegrationTests) with a minted development session — signs nobody out8# --journey also the v1 journey (BackendIntegrationTests: WebAuthn enrolment by recovery code) — it signs out every9# other session of the development database: run it alone10# DEV_NODE node running the development server (default M4M64c)11# DEV_DIR development worktree on the node (default ~/work/csa-v3)12# DEV_PORT port of the development server (default 8510)13# A one-time enrolment code is created on the node for the development database; it is passed to the tests through the14# environment and never printed.15set -euo pipefail16cd "$(dirname "$0")/.."17NODE="${DEV_NODE:-M4M64c}"; DIR="${DEV_DIR:-work/csa-v3}"; PORT="${DEV_PORT:-8510}"1819JOURNEY=0; [[ "${1:-}" == "--journey" ]] && JOURNEY=12021RP="$(ssh "$NODE" "export PATH=/opt/homebrew/bin:\$PATH; cd $DIR && node_modules/.bin/tsx scripts/auth.ts status 2>/dev/null | sed -n 's/^RP id *//p'")"22[[ "$RP" == "localhost" ]] || { echo "ERROR: $NODE:$DIR is not a development instance (RP id '$RP'). Refusing to run." >&2; exit 1; }2324# reuse a tunnel that is already open (never close someone else's); otherwise open one and close it at exit25if ! curl -fsS -m 3 "http://localhost:$PORT/api/health" >/dev/null 2>&1; then26 ssh -f -N -o ExitOnForwardFailure=yes -L "$PORT:localhost:$PORT" "$NODE"27 trap 'pkill -f "ssh -f -N -o ExitOnForwardFailure=yes -L $PORT:localhost:$PORT" 2>/dev/null || true' EXIT28fi29curl -fsS -m 10 "http://localhost:$PORT/api/health" >/dev/null || { echo "ERROR: development server unreachable on :$PORT" >&2; exit 1; }30show() { sed 's/\x1b\[[0-9;]*m//g' | grep -E "✘|✔|error:|Test run|recorded"; }3132if [[ $JOURNEY -eq 1 ]]; then33 # The v1 journey enrols a passkey with a recovery code: the server then REVOKES EVERY OTHER SESSION of the development34 # database (other apps and scripts signed in on it are signed out). Run it alone, not while someone else is testing.35 CODE="$(ssh "$NODE" "export PATH=/opt/homebrew/bin:\$PATH; cd $DIR && node_modules/.bin/tsx scripts/auth.ts bootstrap --recover 2>/dev/null" | grep -Eo '^ +[0-9A-Z]{4}(-[0-9A-Z]{4}){4}$' | tr -d ' ' | head -1)"36 [[ -n "$CODE" ]] || { echo "ERROR: could not obtain an enrolment code from the development instance." >&2; exit 1; }37 SPCHAT_IT_URL="http://localhost:$PORT" SPCHAT_IT_CODE="$CODE" swift test --filter BackendIntegrationTests 2>&1 | show38fi3940# backend 1.0 suite: a session minted for the development database (never printed); it revokes nothing41eval "$(Scripts/dev-session.sh)"42SPCHAT_IT_URL="http://localhost:$PORT" SPCHAT_IT_COOKIE="$SPCHAT_SESSION_COOKIE" swift test --filter NextGenIntegrationTests 2>&1 | show43