#!/usr/bin/env bash
set -euo pipefail
# Place the uploaded agent, HTTPS fixture and network resolver beside this script.
# Place each uploaded e2e.ts file in the checkout's scripts/scenarios directory.
proof_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
openssl req -x509 -newkey rsa:2048 -nodes -keyout "$proof_dir/key.pem" -out "$proof_dir/cert.pem" -days 1 -subj /CN=code.acme.test -addext 'subjectAltName=DNS:code.acme.test,DNS:github.acme.test'
sudo -n node "$proof_dir/enterprise-fixture.cjs" &
fixture_pid=$!
trap 'kill "$fixture_pid" 2>/dev/null || true' EXIT
export T3CODE_DEV_SEED=0
export ISSUE_PROOF_AGENT_PATH="$proof_dir/issue-replay.mjs"
export NODE_OPTIONS="--require=$proof_dir/network.cjs"
export NODE_EXTRA_CA_CERTS="$proof_dir/cert.pem"
export GH_HOST=code.acme.test
# This is a synthetic credential accepted only by the local fixture.
export GH_ENTERPRISE_TOKEN=scenario-enterprise-token
export T3_SCENARIO_INHERIT_ENV='T3CODE_DEV_SEED,NODE_OPTIONS,NODE_EXTRA_CA_CERTS,GH_HOST,GH_ENTERPRISE_TOKEN'
vp run scenarios:prove "scripts/scenarios/${1:-enterprise-issue-38251.e2e.ts}" --base bfd37b2b5341645c5da172e6e2acae9b82c946f8 --head de49a97f2995eb9d282b3cdb710d36f2d947602c --upload-command 'ghdrop upload'
