#!/usr/bin/env bash
# Run from the checkout being tested after installing and pairing its dev client.
# Seed with seed.sh first. Use the same iPhone, light theme, and two thread titles.
set -euo pipefail
session=$1
output=$2
mkdir -p "$output"
agent-device record start "$output/flow.mp4" --hide-touches --session "$session"
agent-device press 'role=button label=Search' --settle --session "$session"
agent-device fill 'role=search' Orchid --delay-ms 100 --settle --session "$session"
agent-device press 'role=cell label="Orchid planning"' --settle --session "$session"
agent-device wait 'role=button label=Back' 30000 --session "$session"
agent-device press 'role=button label=Back' --settle --session "$session"
agent-device wait stable 1500 30000 --session "$session"
agent-device screenshot "$output/returned-home-a.png" --session "$session"
sleep 0.5
agent-device screenshot "$output/returned-home-b.png" --session "$session"
# Base retains an expanded field; head restores the Search button.
if agent-device is visible 'role=button label=Search' --session "$session"; then
  agent-device press 'role=button label=Search' --settle --session "$session"
else
  agent-device press 'role=search' --settle --session "$session"
fi
agent-device snapshot -i --session "$session"
agent-device record stop --session "$session"
