#!/usr/bin/env bash
# Run on each commit from its isolated checkout, with a leased Pixel 9.
# SERVER_ORIGIN and METRO_ORIGIN are device-reachable URLs for that checkout.
# Start the backend with T3CODE_DEV_SEED=0 and NODE_OPTIONS=--require=<slow-write.cjs>.
# Start this checkout's Metro on all interfaces, using its own port.
set -euo pipefail
: "${SESSION:?leased agent-device session}"
: "${METRO_ORIGIN:?device-reachable Metro origin}"
: "${SERVER_ORIGIN:?device-reachable isolated server origin}"
: "${SERVER_PORT:?isolated backend port}"
: "${OUT:?capture directory}"
vp run mobile:install android --session "$SESSION" --metro "$METRO_ORIGIN"
# Wait until the app has finished bundling before opening the pairing route.
.agents/skills/test-t3-mobile/scripts/pair-client.sh "$SERVER_PORT" .t3 "$SERVER_ORIGIN" agent-device --session "$SESSION"
agent-device snapshot -i --session "$SESSION"
agent-device press 'label="Settings"' --session "$SESSION" --settle
agent-device press 'label="Voice"' --session "$SESSION" --settle
# Select the tested environment and confirm "Use environment" if necessary.
agent-device snapshot -i --session "$SESSION"
# Tap the local-model selector from the snapshot (its label depends on installed state).
# On a fresh server: "Local model, No model installed · Choose one to download".
agent-device press 'label="Local model, No model installed · Choose one to download"' --session "$SESSION" --settle
agent-device fill 'label="Search models or languages"' 'Moonshine Tiny' --session "$SESSION" --settle
agent-device record start "$OUT/android.mp4" --session "$SESSION" --hide-touches
agent-device press 'label="Moonshine Tiny"' --session "$SESSION" --settle
agent-device press 'label="Download"' --session "$SESSION" --settle
agent-device keyboard dismiss --session "$SESSION"
# While the final write is delayed, snapshot the real caption and capture the screen.
agent-device snapshot -i --session "$SESSION"
agent-device screenshot "$OUT/android.png" --session "$SESSION"
# Find Forget(Progress), tree its @c ref, inspect the immediate View child.
# This records accessibilityValue.now supplied by Progress.android.tsx.
agent-device react-devtools find Progress --session "$SESSION"
# agent-device react-devtools tree <Progress-ref> --depth 2 --session "$SESSION"
# agent-device react-devtools inspect <View-ref> --session "$SESSION"
agent-device get attrs 'label="Moonshine Tiny download progress"' --session "$SESSION"
agent-device record stop --session "$SESSION"
