SPB Git

Repository Public

dev-session.sh 1.6 KB 23 lines shellscript

1#!/usr/bin/env bash2# Author: Simon-Pierre Boucher — contact@spboucher.ai3# File: Scripts/dev-session.sh4# Description: Opens an SSH tunnel to the DEVELOPMENT backend and mints a session for its development database (for Debug runs and UI tests).5#6# Usage: eval "$(Scripts/dev-session.sh)"   → exports SPCHAT_SERVER and SPCHAT_SESSION_COOKIE (never printed to the terminal by itself)7# Debug builds only honour these variables, and only for a loopback server.8set -euo pipefail9NODE="${DEV_NODE:-M4M64c}"; DIR="${DEV_DIR:-work/csa-v3}"; PORT="${DEV_PORT:-8510}"10RP="$(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'")"11[[ "$RP" == "localhost" ]] || { echo "echo 'ERROR: not a development instance' >&2; false"; exit 1; }12curl -fsS -m 3 "http://localhost:$PORT/api/health" >/dev/null 2>&1 || ssh -f -N -o ExitOnForwardFailure=yes -L "$PORT:localhost:$PORT" "$NODE"13TOKEN="$(ssh "$NODE" "export PATH=/opt/homebrew/bin:\$PATH; cd $DIR && cat > scripts/_devsession.tmp.ts <<'TS'14import \"./_bootstrap\";15import { createSession } from \"../src/lib/auth/session\";16import { sql } from \"../src/lib/db\";17const { token } = await createSession({ credentialId: null, userAgent: \"SPChat/dev (Macintosh) native\", ip: \"127.0.0.1\" });18console.log(token); await sql.end();19TS20node_modules/.bin/tsx scripts/_devsession.tmp.ts 2>/dev/null | tail -1; rm -f scripts/_devsession.tmp.ts")"21[[ ${#TOKEN} -eq 43 ]] || { echo "echo 'ERROR: could not mint a development session' >&2; false"; exit 1; }22echo "export SPCHAT_SERVER=http://localhost:$PORT SPCHAT_SESSION_COOKIE=csa_session=$TOKEN"23
Files main
Menu

Theme