#!/usr/bin/env bash
set -euo pipefail
# Run from either evidence checkout. Keep github-fixture.mjs beside this script.
# Each invocation creates fresh synthetic state; no live account or database is used.
: "${EVIDENCE_ROOT:?Choose an empty evidence output parent}"
fixture_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
run_dir="$EVIDENCE_ROOT/$(date -u +%Y%m%dT%H%M%S)-$$"
mkdir -p "$run_dir/demo"
git init -q "$run_dir/demo"
git -C "$run_dir/demo" remote add origin https://github.com/queue-evidence/demo.git
node apps/server/src/bin.ts project add --base-dir "$run_dir/home" --title demo "$run_dir/demo" > "$run_dir/seed.log" 2>&1
project_id=$(sqlite3 "$run_dir/home/userdata/statev2.sqlite" "select project_id from projection_projects where title='demo';")
printf 'Project ID: %s\n' "$project_id"
printf 'PR path: /pull-requests?repository=queue-evidence%%2Fdemo&number=7&host=github.com&projectId=%s\n' "$project_id"
printf 'Pair with the startup URL, then follow capture-steps.md.\n'
export T3CODE_DEV_SEED=0 GH_TOKEN=evidence-fixture
export NODE_OPTIONS="--import=$fixture_dir/github-fixture.mjs"
export EVIDENCE_API_LOG="$run_dir/api.jsonl"
exec vp run dev --host 0.0.0.0 --home-dir "$run_dir/home"
