#!/bin/sh
# Run from the evidence scratch root after the two specified worktrees exist.
set -eu
ROOT=/tmp/lead-29428-r1/evidence-capture
git -C /home/ubuntu/t3code worktree add /home/ubuntu/wt/pr-29428-base edc37c96c810d42761ab510c6a3e9d0a741547dc
(cd /home/ubuntu/wt/pr-29428-base && vp install) > "$ROOT/install-base.log" 2>&1
for SIDE in before after; do
  if [ "$SIDE" = before ]; then CHECKOUT=/home/ubuntu/wt/pr-29428-base; else CHECKOUT=/home/ubuntu/wt/pr-29428; fi
  (cd "$CHECKOUT/apps/server" && vp run build:bundle) > "$ROOT/build-$SIDE.log" 2>&1
  (cd "$CHECKOUT/apps/web" && vp run build) > "$ROOT/build-web-$SIDE.log" 2>&1
done
curl -fLsS https://github.com/pingdotgg/t3code/releases/download/v0.1.5/t3-0.1.5-linux-x64.tar.gz -o "$ROOT/t3-0.1.5-linux-x64.tar.gz"
curl -fLsS https://github.com/pingdotgg/t3code/releases/download/v0.1.5/SHA256SUMS -o "$ROOT/SHA256SUMS-0.1.5"
curl -fLsS https://github.com/pingdotgg/t3code/releases/download/v0.1.7-nightly.20261102.4080/t3-0.1.7-nightly.20261102.4080-linux-x64.tar.gz -o "$ROOT/t3-0.1.7-nightly.20261102.4080-linux-x64.tar.gz"
curl -fLsS https://github.com/pingdotgg/t3code/releases/download/v0.1.7-nightly.20261102.4080/SHA256SUMS -o "$ROOT/SHA256SUMS-nightly"
python3 "$ROOT/prepare.py"
(cd "$ROOT/nightly-source/apps/server" && vp pack) > "$ROOT/build-nightly-with-schema.log" 2>&1
python3 "$ROOT/capture.py"
# After publication and process cleanup:
# git -C /home/ubuntu/t3code worktree remove --force /home/ubuntu/wt/pr-29428-base
