#!/usr/bin/env bash
# Run from the revision's checkout against its own fresh dev server and Metro.
# Arguments: agent-device session, isolated T3 home, server port, project root.
# Install the cached client with `vp run mobile:install ios --session SESSION`,
# open this checkout's Metro development-client link, and pair with pair-client.sh first.
# Photos setup: dismiss first-launch Continue and Don't Allow; open the first image
# in Library (the simulator's yellow-fruit photo, IMG_0002.JPG).
set -euo pipefail
session=$1
test_home=$2
server_port=$3
project_root=$4
for project in alpha beta; do
  mkdir -p "$project_root/$project"
  git init -q "$project_root/$project"
  T3CODE_PORT="$server_port" node apps/server/src/bin.ts project add "$project_root/$project" --title "$project" --base-dir "$test_home"
done
# With a clean client, default Use last project is on.
agent-device press 'label="New chat"' --settle --session "$session"
agent-device press 'label="beta"' --settle --session "$session"
agent-device back --settle --session "$session"
agent-device press 'label="New chat"' --settle --session "$session"
# Observe the control: What should we build in beta?
agent-device back --settle --session "$session"
agent-device open com.apple.mobileslideshow --session "$session"
agent-device press 'label="Share"' --settle --session "$session"
# Do not settle against Photos after the destination changes to T3.
agent-device press 'role=cell label="T3 Code Dev"' --session "$session"
agent-device open com.t3tools.t3code.dev --session "$session"
agent-device snapshot -i --session "$session"
# Base: Choose project. Head: beta draft with IMG_0002.JPG attached.
