#!/usr/bin/env bash
# Run in each commit's checkout after installing its dev client, starting its
# fresh backend with T3CODE_DEV_SEED=0 and Metro, and pairing the leased Pixel 9.
# Uses real GitHub data; never presses a merge button.
set -euo pipefail
: "${SESSION:?Set the leased agent-device session}"
: "${SIDE:?Set base or head}"
: "${OUT:?Set an evidence output directory}"
run_dir="$OUT/$(date -u +%Y%m%dT%H%M%SZ)-$SIDE"
mkdir -p "$run_dir"
agent-device click 'label="Pulls"' --session "$SESSION"
agent-device snapshot --session "$SESSION" > "$run_dir/list.txt"
pr_ref=$(python3 - "$run_dir/list.txt" <<'PY'
import re,sys
s=open(sys.argv[1]).read()
print(re.search(r'(@e\d+) \[button\] "Pull request 44773,',s).group(1))
PY
)
agent-device click "$pr_ref" --session "$SESSION"
agent-device wait 'label="Stack, 1 of 3"' --session "$SESSION"
agent-device snapshot --session "$SESSION" > "$run_dir/one.txt"
agent-device screenshot "$run_dir/one-a.png" --session "$SESSION"
sleep 0.5
agent-device screenshot "$run_dir/one-b.png" --session "$SESSION"
cmp "$run_dir/one-a.png" "$run_dir/one-b.png"
agent-device click 'label="Stack, 1 of 3"' --session "$SESSION"
agent-device click 'label="feat(server): hand a thread off to a linked environment, #44774 · 2 of 3, Open"' --session "$SESSION"
agent-device wait 'label="Stack, 2 of 3"' --session "$SESSION"
agent-device snapshot --session "$SESSION" > "$run_dir/two.txt"
agent-device screenshot "$run_dir/two-a.png" --session "$SESSION"
sleep 0.5
agent-device screenshot "$run_dir/two-b.png" --session "$SESSION"
cmp "$run_dir/two-a.png" "$run_dir/two-b.png"
