#!/usr/bin/env bash
# Run from the commit's checkout after starting its isolated server and Metro.
# Args: platform session server-port data-home reachable-origin project-path
set -euo pipefail
platform=$1
session=$2
server_port=$3
data_home=$4
origin=$5
project_path=$6
T3CODE_PORT="$server_port" node apps/server/src/bin.ts project add "$project_path" --title demo --base-dir "$data_home"
.agents/skills/test-t3-mobile/scripts/pair-client.sh "$server_port" "$data_home" "$origin" agent-device --session "$session"
agent-device press 'label=Settings' --session "$session" --settle
agent-device press 'label=General' --session "$session" --settle
agent-device press 'label="Language, English"' --session "$session" --settle
agent-device press 'label=Deutsch' --session "$session" --settle
# Return twice using the visible Back control, then Chats and New chat.
if [[ "$platform" == ios ]]; then
  agent-device press 'label=Back' --session "$session" --settle
  agent-device press 'label=Back' --session "$session" --settle
else
  agent-device back --session "$session" --settle
  agent-device back --session "$session" --settle
fi
agent-device press 'label=Chats' --session "$session" --settle
if [[ "$platform" == ios ]]; then
  agent-device press 'label="New chat"' --session "$session" --settle
else
  agent-device press 'label="Neuer Thread"' --session "$session" --settle
fi
agent-device press 'text=demo' --session "$session" --settle
agent-device wait text 'Frag irgendwas' 30000 --session "$session"
# This URI is the composer's markdown context-link format. The provider-facing
# representation [File: Notes; ref=missing-id] alone remains ordinary text.
composer_role=text-view
[[ "$platform" == android ]] && composer_role=text-field
agent-device fill "role=$composer_role" '[Notes](t3-context://v1/file/missing-id)' --session "$session" --settle
agent-device snapshot -i --session "$session"
# Capture the rendered static chip, with German surrounding UI and no model turn.

if [[ "$platform" == android ]]; then
  agent-device keyboard dismiss --session "$session"
fi
