#!/usr/bin/env bash
# Run from each checkout, after starting its isolated server and Metro.
# Arguments: pooled agent-device session, reachable Metro origin, output directory.
set -euo pipefail
session=$1
metro=$2
out=$3
mkdir -p "$out"
agent-device settings appearance light --session "$session"
agent-device settings clear-app-state com.t3tools.t3code.dev --session "$session"
url=$(python3 -c 'import sys,urllib.parse; print(urllib.parse.quote(sys.argv[1],safe=""))' "$metro")
agent-device open com.t3tools.t3code.dev "t3code-dev://expo-development-client/?url=$url&disableOnboarding=1&disableFab=1&disableAutoLaunch=1" --session "$session"
# Accept an iOS Open confirmation if it appears, then wait for Add environment.
agent-device wait text 'Add environment' --session "$session"
agent-device press 'role=button label="Settings"' --settle --session "$session"
agent-device press 'role=button label="General"' --settle --session "$session"
agent-device snapshot --json --session "$session" > "$out/frames.json"
agent-device screenshot "$out/check.png" --session "$session"
sleep 0.5
agent-device screenshot "$out/capture.png" --session "$session"
compare -metric AE "$out/check.png" "$out/capture.png" null:
# Inspect the capture and compare the Use last project switch center with
# the center of the union of its label and description accessibility frames.
