#!/usr/bin/env bash
set -euo pipefail
# Place this script, driver.cjs, native-input.py, and run-one.mjs together in your scratch folder.
# Requirements: Linux, headless-desktop (Xvfb + D-Bus/keyring), vp, Electron libraries,
# ffmpeg, xdotool, xset (Debian/Ubuntu: xdotool x11-xserver-utils).
# Run from a clean main repository checkout. These worktrees must not already exist.
# No real userdata is read or copied. Every invocation creates fresh timestamped state.
git worktree add --detach /home/ubuntu/wt/pr-33620-ev-base bbdc7dca320ee4fbc7131498aaffef2fa1eb3d41
git worktree add --detach /home/ubuntu/wt/pr-33620-ev-head a103cf6dffc5c06d386282ba3dd794ce43dac0be
capture_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
for side in base head; do
  root="/home/ubuntu/wt/pr-33620-ev-$side"
  (cd "$root" && T3CODE_DEV_SEED=0 vp install)
  (cd "$root/apps/desktop" && node scripts/ensure-electron-runtime.mjs && node scripts/build-preview-annotation-css.mjs && T3CODE_DEV_SEED=0 vp pack)
  (cd "$root/apps/server" && T3CODE_DEV_SEED=0 vp pack)
  (cd "$root/apps/web" && T3CODE_DEV_SEED=0 vp build)
  cp -a "$root/apps/web/dist" "$root/apps/server/dist/client"
  for mode in listeners native release-harness quiet-harness; do
    T3CODE_DEV_SEED=0 headless-desktop node "$capture_dir/run-one.mjs" "$root" "$side" "$mode"
  done
done
# Stop only processes captured by run-one.mjs. Inspect every result before cleanup.
# git worktree remove --force /home/ubuntu/wt/pr-33620-ev-base
# git worktree remove --force /home/ubuntu/wt/pr-33620-ev-head
