#!/usr/bin/env bash
set -eu
# Run from a checkout of main containing the scenario runner.
# Put hung-path-server.e2e.ts in scripts/scenarios/ and delayed-fs.py beside this script.
# Prerequisites: Linux FUSE mount access, libfuse2, fusermount3, Python fusepy, vp, ghdrop.
fixture_dir=$(mktemp -d)
mkdir "$fixture_dir/mount"
python3 "$(dirname "$0")/delayed-fs.py" "$fixture_dir/mount" &
fixture_pid=$!
cleanup() {
  curl -sf http://127.0.0.1:18938/release >/dev/null || true
  fusermount3 -u "$fixture_dir/mount" || true
  wait "$fixture_pid" || true
  rmdir "$fixture_dir/mount" "$fixture_dir"
}
trap cleanup EXIT
# Wait for the independent control endpoint before starting either revision.
python3 - <<'PY'
import time, urllib.request
for attempt in range(100):
    try:
        urllib.request.urlopen('http://127.0.0.1:18938/state').read()
        break
    except OSError:
        time.sleep(.1)
else:
    raise RuntimeError('FUSE fixture did not start')
PY
base=$(git merge-base origin/main a57a70a3ff1d4b08d01b5b18baf3561e739bce67)
T3CODE_DEV_SEED=0 PATH="$fixture_dir/mount:$PATH" vp run scenarios:prove \
  scripts/scenarios/hung-path-server.e2e.ts --base "$base" \
  --head a57a70a3ff1d4b08d01b5b18baf3561e739bce67 --upload-command 'ghdrop upload'
