SPB Git

Repository Public

dev-session.sh 2.4 KB 28 lines shellscript

1#!/usr/bin/env bash2# Author: Simon-Pierre Boucher — contact@spboucher.ai3# File: Scripts/dev-session.sh4# Description: Opens the SSH tunnel to the frozen VQuant Next TEST backend and a device session on it, for visual checks and UI tests of the Debug build. Prints shell assignments; the token is never printed to the terminal.5#6# Usage: eval "$(Scripts/dev-session.sh)"   → VQ_SERVER, VQ_DEV_TOKEN7# The test backend is M2U64:~/dev/vquant-next-api on port 5058 (a copy of production data with every v6 route;8# PASSKEY_ORIGIN=http://localhost:5058). Never production (5000), never 5055/5056/5057/5059.9# The device token is minted on the node by the copy's own helper (scripts/native-test-token.mjs) and kept in a10# private file on this Mac; it is reused while the server still accepts it.11set -euo pipefail12cd "$(dirname "$0")/.."13NODE="${VQ_TEST_NODE:-M2U64}"; DIR="${VQ_TEST_DIR:-dev/vquant-next-api}"; PORT="${VQ_TEST_PORT:-5058}"14[[ "$PORT" == "5058" ]] || { echo "echo 'only the 5058 test backend may be used' >&2; false"; exit 1; }15NODEBIN='export PATH="$HOME/local/node-v22.15.0-darwin-arm64/bin:/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin"'16VERSION="$(sed -n 's/.*MARKETING_VERSION: "\(.*\)"/\1/p' project.yml | head -1)"17TOKEN_FILE="${TMPDIR:-/tmp}/vquant-next-dev-token"18curl -fsS -m 3 "http://127.0.0.1:$PORT/api/health" >/dev/null 2>&1 || ssh -f -N -o ExitOnForwardFailure=yes -L "$PORT:localhost:$PORT" "$NODE"19curl -fsS -m 10 "http://127.0.0.1:$PORT/api/health" >/dev/null || { echo "echo 'test server unreachable' >&2; false"; exit 1; }20# reuse the session while the server still accepts it21if [[ -s "$TOKEN_FILE" ]] && curl -fsS -m 5 -H "X-VQ-Client: vquant-macos/$VERSION" -H "Authorization: Bearer $(cat "$TOKEN_FILE")" "http://127.0.0.1:$PORT/api/native/session" >/dev/null 2>&1; then :; else22  ORIGIN="$(ssh "$NODE" "grep -E '^PASSKEY_ORIGIN=' $DIR/.env | tail -1 | cut -d= -f2-")"23  [[ "$ORIGIN" == "http://localhost:$PORT" ]] || { echo "echo 'not a test instance' >&2; false"; exit 1; }24  rm -f "$TOKEN_FILE"; ( umask 077; ssh "$NODE" "$NODEBIN; cd $DIR && node --env-file=.env scripts/native-test-token.mjs ${VQ_TEST_USER:-simon} macos" | cut -d' ' -f1 > "$TOKEN_FILE" )25  [[ "$(head -c 4 "$TOKEN_FILE")" == "vqn_" ]] || { rm -f "$TOKEN_FILE"; echo "echo 'could not open a development session' >&2; false"; exit 1; }26fi27echo "export VQ_SERVER=http://127.0.0.1:$PORT VQ_DEV_TOKEN=$(cat "$TOKEN_FILE")"28
Files main
Menu

Theme