Repository Public
1#!/usr/bin/env bash2# VQuant iOS3# File: Scripts/test-live.sh4# Description: Runs the tests against the frozen VQuant Next test backend (M2U64:5058, a copy of production data with5# the /api/v2 routes; never production, never 5055/5056/5057/5059) through an SSH tunnel, with a device6# session minted in that copy's database. Test objects written there are prefixed `ios-test-`.7# usage: test-live.sh tunnel | close | token | test | uitest [extra xcodebuild args]8#9# Author: Simon-Pierre Boucher10# Contact: contact@spboucher.ai11set -uo pipefail12cd "$(dirname "$0")/.."13PORT=505814TOKEN_FILE="$HOME/.config/vquant-ios-test/token-5058"15PID_FILE="build/tunnel-$PORT.pid"16tunnel() {17 curl -s -m 4 "http://127.0.0.1:$PORT/api/health" >/dev/null && return 018 # A tunnel opened by this script is remembered by PID so `close` ends that one only (another session on this Mac19 # may hold its own tunnel to the same port: it is reused, never killed).20 mkdir -p build21 ssh -N -o ExitOnForwardFailure=yes -o ServerAliveInterval=30 -L "$PORT:localhost:$PORT" M2U64 & echo $! > "$PID_FILE"22 sleep 223 curl -s -m 6 "http://127.0.0.1:$PORT/api/health" >/dev/null || { echo "backend de test injoignable (M2U64:~/dev/vquant-next-api, port $PORT)"; exit 1; }24}25close() { [ -s "$PID_FILE" ] && kill "$(cat "$PID_FILE")" 2>/dev/null; rm -f "$PID_FILE"; echo "tunnel fermé"; }26token() {27 # mints a device session in the copy's database (the script refuses to run in the production directory)28 mkdir -p "$(dirname "$TOKEN_FILE")"29 ssh M2U64 'export PATH="$HOME/local/node-v22.15.0-darwin-arm64/bin:$PATH"; cd ~/dev/vquant-next-api && node --env-file=.env scripts/native-test-token.mjs simon ios' | awk '{print $1}' > "$TOKEN_FILE"30 chmod 600 "$TOKEN_FILE"; echo "jeton de test renouvelé"31}32case "${1:-test}" in33 tunnel) tunnel && echo "tunnel ouvert sur 127.0.0.1:$PORT" ;;34 close) close ;;35 token) token ;;36 test|uitest)37 mode="$1"; shift38 tunnel39 [ -s "$TOKEN_FILE" ] || token40 export TEST_RUNNER_VQUANT_BASE_URL="http://127.0.0.1:$PORT"41 export TEST_RUNNER_VQUANT_TEST_TOKEN="$(cat "$TOKEN_FILE")"42 Scripts/build.sh "$mode" "$@" ;;43 *) echo "usage: test-live.sh tunnel|close|token|test|uitest"; exit 2 ;;44esac45