#!/usr/bin/env bash
set -euo pipefail
# Run from a current-main checkout with dependencies installed. Place the
# scenario under scripts/scenarios, and fixture.py beside this driver.
fixture_dir=$(cd "$(dirname "$0")" && pwd)
python3 "$fixture_dir/fixture.py" > "$fixture_dir/fixture-output.log" 2>&1 &
fixture_pid=$!
trap 'kill "$fixture_pid"; wait "$fixture_pid" || true' EXIT
while [ ! -f "$fixture_dir/remote-url" ]; do sleep 0.1; done
# e2e does not inherit arbitrary app environment variables by default.
python3 - <<'PY'
p='scripts/e2e.config.ts'
s=open(p).read()
if 'inheritEnv: ["GIT_ASKPASS"' not in s:
    s=s.replace('executable: resolved.node,', 'executable: resolved.node,\n          inheritEnv: ["GIT_ASKPASS", "GIT_SSL_CAINFO", "T3CODE_GIT_PRESERVE_ASKPASS", "T3CODE_DEV_SEED"],')
open(p,'w').write(s)
PY
export T3CODE_DEV_SEED=0
export T3CODE_GIT_PRESERVE_ASKPASS=1
export GIT_ASKPASS="$fixture_dir/askpass.sh"
export GIT_SSL_CAINFO="$fixture_dir/cert.pem"
export ASKPASS_FIXTURE_URL_FILE="$fixture_dir/remote-url"
vp run scenarios:prove scripts/scenarios/git-preserve-askpass.e2e.ts \
  --base 39ab6a2d2ff5337c60f545c80262714c46510bad \
  --head d65963400227bc46e6ab65a8a1e44fef8d2585bd
