#!/usr/bin/env bash
# Run against each commit's fresh server after mobile-seed.py creates Earlier work.
# CHECKOUT, STATE, PORT, ORIGIN, METRO_URL and SESSION belong to the isolated run.
set -euo pipefail
python3 mobile-seed.py "$CHECKOUT" "$STATE" "$PORT"
agent-device open com.t3tools.t3code.dev "t3code-dev://expo-development-client/?url=$METRO_URL&disableOnboarding=1&disableFab=1&disableAutoLaunch=1" --no-test-ime --session "$SESSION"
# Pair through the repository helper; credentials are never printed or recorded.
"$CHECKOUT/.agents/skills/test-t3-mobile/scripts/pair-client.sh" "$PORT" "$STATE" "$ORIGIN" agent-device --session "$SESSION"
agent-device wait text 'Earlier work' 30000 --session "$SESSION"
agent-device record start interaction.mp4 --session "$SESSION"
agent-device find 'Earlier work' click --first --session "$SESSION"
agent-device wait text 'Worked for' 30000 --session "$SESSION"
agent-device find 'Worked for' click --first --session "$SESSION"
agent-device snapshot -i --session "$SESSION"
agent-device fill 'role="text-field"' 'Continue the inspection' --settle --session "$SESSION"
agent-device click 'label="Send"' --settle --session "$SESSION"
agent-device keyboard dismiss --session "$SESSION"
agent-device screenshot final-a.png --session "$SESSION"
sleep 0.5
agent-device screenshot final-b.png --session "$SESSION"
agent-device record stop --session "$SESSION"
