#!/usr/bin/env bash
# Run in each tested checkout, with its own fresh .t3 and no copied database.
# Args: checkout scratch session server-port metro-port side
set -euo pipefail
checkout=$1; scratch=$2; session=$3; server_port=$4; metro_port=$5; side=$6
cd "$checkout"
# Start separately, retain both terminal sessions, and stop them after capture:
# T3CODE_DEV_SEED=0 T3CODE_ENVIRONMENT_LABEL='Attachment example' vp run dev:server --host 0.0.0.0 --port "$server_port"
# In apps/mobile: T3CODE_DEV_SEED=0 EXPO_NO_METRO_LAZY=1 REACT_NATIVE_PACKAGER_HOSTNAME=$(tailscale ip -4) CI=1 vp run dev:client --port "$metro_port"
node apps/server/src/bin.ts project add "$scratch/repository" --title 'Attachment example' --base-dir "$checkout/.t3"
vp run mobile:install ios --session "$session"
agent-device open com.t3tools.t3code.dev "t3code-dev://expo-development-client/?url=http%3A%2F%2F$(tailscale ip -4)%3A$metro_port&disableOnboarding=1&disableFab=1&disableAutoLaunch=1" --session "$session"
# Wait for app load; accept the iOS open-link prompt if present.
.agents/skills/test-t3-mobile/scripts/pair-client.sh "$server_port" "$checkout/.t3" "http://$(tailscale ip -4):$server_port" agent-device --session "$session"
# Through snapshots: PRs -> More filters -> Project -> Attachment example -> MR 1.
# For the second side disable the first connection and reset the project filter first.
# Wait until the description and images load, then use the same gesture:
agent-device swipe 205 690 205 300 --session "$session"
agent-device screenshot "$scratch/$side-captions-a.png" --session "$session"
sleep 0.5
agent-device screenshot "$scratch/$side-captions.png" --session "$session"
cmp "$scratch/$side-captions-a.png" "$scratch/$side-captions.png"
agent-device snapshot -i --session "$session"
caption='My%20Screenshot.png'
if [[ $side == after ]]; then caption='My Screenshot.png'; fi
agent-device record start "$scratch/$side-gallery.mp4" --hide-touches --session "$session"
agent-device press "label=\"View attachment: $caption\"" --session "$session"
agent-device snapshot -i --session "$session"
agent-device swipe 330 420 60 420 --session "$session"
agent-device snapshot -i --session "$session"
agent-device swipe 330 420 60 420 --session "$session"
agent-device snapshot -i --session "$session"
agent-device press 'label="close"' --session "$session"
agent-device record stop --session "$session"
