#!/usr/bin/env bash
set -euo pipefail
# Run from the commit's checkout with its fresh isolated server and Metro running.
# Install through: vp run mobile:install ios --session "$SESSION"
# Pair the installed client using the repository's pair-client.sh helper.
: "${SESSION:?}" "${T3_HOME:?}" "${T3CODE_PORT:?}" "${PROJECT_DIR:?}"
: "${ENVIRONMENT_ID:?}" "${CAPTURE_DIR:?}"
mkdir -p "$PROJECT_DIR" "$CAPTURE_DIR"
git -C "$PROJECT_DIR" init --quiet --initial-branch=main
git -C "$PROJECT_DIR" -c user.name=Scenario -c user.email=scenario@example.invalid commit --allow-empty -m 'Initial commit'
node apps/server/src/bin.ts project add "$PROJECT_DIR" --title 'Link language demo' --base-dir "$T3_HOME"
node apps/server/src/bin.ts thread start "$PROJECT_DIR" 'Ready to test links' --title 'Link language' --provider devReplay --model multi-turn --wait --json --base-dir "$T3_HOME" > "$CAPTURE_DIR/thread.json"
THREAD_ID=$(node -e 'const fs=require("node:fs"); process.stdout.write(encodeURIComponent(JSON.parse(fs.readFileSync(process.argv[1],"utf8")).threadId))' "$CAPTURE_DIR/thread.json")
ad() { agent-device "$@" --session "$SESSION"; }
# Start in English on Settings. Select Japanese through the actual controls.
ad open com.t3tools.t3code.dev 't3code-dev://settings'
ad record start "$CAPTURE_DIR/reproduction.mp4"
ad press 'label=General' --settle
ad press 'label="Language, English"' --settle
ad press 'label=日本語' --settle
ad open com.t3tools.t3code.dev "t3code-dev://threads/$ENVIRONMENT_ID/$THREAD_ID"
ad fill 'label=何でも質問' 'See <t3-thread://v1/hunt-missing-thread>' --settle
ad press 'label=送信' --settle
ad snapshot -i
ad screenshot "$CAPTURE_DIR/result.png"
ad record stop
# Base observed: See Thread no longer available
# Head observed: See スレッドは利用できなくなりました
