#!/usr/bin/env bash
set -eu
# Run from a checkout with dependencies installed. All data is synthetic.
# Arguments: isolated T3 home; path to the VM-provided T3 Connect test env file.
proof_home="$1"
set -a
. "$2"
set +a
export T3CODE_DEV_SEED=0
mkdir -p "$proof_home/bin"
printf '#!/bin/sh\necho "Relay Proof Laptop"\n' > "$proof_home/bin/hostnamectl"
chmod +x "$proof_home/bin/hostnamectl"
export PATH="$proof_home/bin:$PATH"
# Approve the printed device-code request with test account 1 in the browser.
node apps/server/src/bin.ts connect login --headless --base-dir "$proof_home"
node apps/server/src/bin.ts connect link --headless --base-dir "$proof_home"
# Keep this process in the foreground; wait for its reachable message.
node apps/server/src/bin.ts serve --host 127.0.0.1 --port 14691 --base-dir "$proof_home"
# After the comparison: connect unlink, then connect logout, using this base-dir.
