#!/usr/bin/env bash
set -euo pipefail
# Run once in each checkout after vp i. Start its fresh backend with
# T3CODE_DEV_SEED=0 vp run dev --host 0.0.0.0
# and Metro from apps/mobile: vp run dev:client --port <metro-port>.
# Arguments: session, backend port, reachable backend origin, data directory,
# synthetic repository path, output parent.
session=$1
port=$2
origin=$3
base_dir=$4
repo=$5
out="$6/$(date -u +%Y%m%dT%H%M%SZ)"
mkdir -p "$out"
export T3CODE_PORT="$port"
node apps/server/src/bin.ts project add "$repo" --title 'Review demo' --base-dir "$base_dir"
node apps/server/src/bin.ts thread start "$repo" first --title 'Review the link' --provider devReplay --model showcase --wait --json --base-dir "$base_dir"
.agents/skills/test-t3-mobile/scripts/pair-client.sh "$port" "$base_dir" "$origin" agent-device --session "$session"
# Wait for pairing to complete, then open this server's newly created thread.
agent-device snapshot -i --session "$session"
agent-device click 'label="Review the link, Done"' --session "$session"
agent-device click 'label="Git controls"' --session "$session"
agent-device click 550 610 --session "$session"
agent-device screenshot "$out/diff.png" --session "$session"
# Pixel 9, Android API 36, portrait 1080x2424, light theme.
agent-device record start "$out/comment.mp4" --session "$session"
agent-device click 260 780 --session "$session"
agent-device type 'On the new link' --session "$session"
agent-device click 'label="Comment"' --session "$session"
agent-device screenshot "$out/note-a.png" --session "$session"
sleep 0.5
agent-device screenshot "$out/note-b.png" --session "$session"
agent-device record stop --session "$session"
