Repository Public
1#!/usr/bin/env bash2# Author: Simon-Pierre Boucher — contact@spboucher.ai3# File: Scripts/integration-test.sh4# Description: Runs the core test suite against the REAL backend test copy on its node (never production): SSH tunnel, single-use setup link, optional real analysis.5#6# Usage: Scripts/integration-test.sh [--analysis]7# --analysis also runs one fast and one cancelled analysis (calls the model provider: a few cents).8# The test copy is the frozen VQuant Next API, M2U64:~/dev/vquant-next-api on port 5058 with9# PASSKEY_ORIGIN=http://localhost:5058 (see docs/TEST_REPORT.md). Objects written by the tests are prefixed mac-test-.10set -euo pipefail11cd "$(dirname "$0")/.."12NODE="${VQ_TEST_NODE:-M2U64}"; DIR="${VQ_TEST_DIR:-dev/vquant-next-api}"; PORT="${VQ_TEST_PORT:-5058}"13NODEBIN='export PATH="$HOME/local/node-v22.15.0-darwin-arm64/bin:/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin"'1415ORIGIN="$(ssh "$NODE" "grep -E '^PASSKEY_ORIGIN=' $DIR/.env | tail -1 | cut -d= -f2-")"16[[ "$ORIGIN" == "http://localhost:$PORT" ]] || { echo "ERROR: $NODE:$DIR is not a test instance (PASSKEY_ORIGIN='$ORIGIN'). Refusing to run." >&2; exit 1; }17ssh "$NODE" "curl -fsS -m 5 localhost:$PORT/api/health >/dev/null" || { echo "ERROR: the test server is not running on $NODE:$PORT (Scripts/backend-test.sh start)." >&2; exit 1; }18LINK="$(ssh "$NODE" "$NODEBIN; cd $DIR && node --env-file=.env scripts/access-invite.mjs invite simon 1" | sed -n 's/^[^:]*: \(http.*\)$/\1/p' | head -1)"19[[ "$LINK" == http://localhost:$PORT/setup/* ]] || { echo "ERROR: could not obtain a setup link from the test instance." >&2; exit 1; }2021if ! curl -fsS -m 3 "http://localhost:$PORT/api/health" >/dev/null 2>&1; then22 ssh -f -N -o ExitOnForwardFailure=yes -L "$PORT:localhost:$PORT" "$NODE"23 TUNNEL_PID="$(lsof -nP -iTCP:$PORT -sTCP:LISTEN -t | head -1)"24 trap '[[ -n "${TUNNEL_PID:-}" ]] && kill "$TUNNEL_PID" 2>/dev/null || true' EXIT25fi26curl -fsS -m 10 "http://localhost:$PORT/api/health" >/dev/null || { echo "ERROR: test server unreachable through the tunnel." >&2; exit 1; }2728ANALYSIS=0; [[ "${1:-}" == "--analysis" ]] && ANALYSIS=129# the 2.0 suites (Quant Lab, Studio, research workspace) authenticate with the development session instead of a passkey30eval "$(Scripts/dev-session.sh)"31export VQ_IT_TOKEN="$VQ_DEV_TOKEN" VQ_NEXT_URL="http://localhost:$PORT" VQ_NEXT_TOKEN="$VQ_DEV_TOKEN"32VQ_IT_URL="http://localhost:$PORT" VQ_IT_SETUP="$LINK" VQ_IT_ANALYSIS="$ANALYSIS" swift test ${VQ_IT_FILTER:+--filter "$VQ_IT_FILTER"} 2>&1 | sed 's/\x1b\[[0-9;]*m//g' | grep -E "✘|error:|Test run|recorded|skipped" || true33# the test passkeys and device sessions created by this run are removed from the test database34ssh "$NODE" "cd $DIR && sqlite3 local.db \"delete from vq_passkeys where label like 'Mac d’essai%'; delete from vq_devices where label like 'Mac d’essai%' or label like 'Deuxième Mac%' or label like 'Autre%';\""35