#!/usr/bin/env bash
# Run from the checkout under test. Use a fresh DATA directory for each side.
set -euo pipefail
: "${TEST_ENV_FILE:?stage environment file}" "${DATA:?fresh host data directory}" "${AUTH_DATA:?test CLI login directory}" "${PORT:?}" "${CLIENT_ORIGIN:?}"
set -a
. "$TEST_ENV_FILE"
set +a
mkdir -p "$DATA/userdata/secrets"
cp "$AUTH_DATA/userdata/secrets/cloud-cli-oauth-token.bin" "$DATA/userdata/secrets/cloud-cli-oauth-token.bin"
node apps/server/src/bin.ts connect link --headless --publish-only --base-dir "$DATA"
export T3CODE_DEV_SEED=0 T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD=0 T3CODE_ENVIRONMENT_LABEL='Remote demo'
exec node apps/server/src/bin.ts serve --host 127.0.0.1 --port "$PORT" --dev-url "$CLIENT_ORIGIN" --base-dir "$DATA"
