#!/usr/bin/env bash
# Real Azure DevOps + Android reproduction. Run separately in base and head checkouts.
# Requires Azure test credentials, a leased agent-device SESSION, and dev client installed.
set -euo pipefail
: "${SESSION:?}" "${PR_ID:?}" "${AZURE_DEVOPS_TEST_ORG:?}" "${OUT:?}"
mkdir -p "$OUT"
az repos pr update --id "$PR_ID" --organization "$AZURE_DEVOPS_TEST_ORG" \
  --description $'\uFEFF- [ ] a\n- [ ] b\n' --query description -o json > "$OUT/initial-description.json"
# Start this checkout's fresh dev server with T3CODE_DEV_SEED=0 and --host 0.0.0.0.
# Add the real Azure clone with `t3 project add`, start this checkout's Metro,
# install using `vp run mobile:install android --session "$SESSION" --metro "$METRO"`,
# relaunch the app, and pair via .agents/skills/test-t3-mobile/scripts/pair-client.sh.
# In the app: Pulls > Filter > Project > azrepo > BOM checkbox proof 45754 > Overview.
agent-device snapshot -i --session "$SESSION"
agent-device screenshot "$OUT/before.png" --session "$SESSION"
agent-device record start "$OUT/toggle.mp4" --session "$SESSION"
# Pixel 9, Android 36, light theme, 1080x2424: b at y=1539 on head, y=1558 on base.
# Set CHECKBOX_Y=1558 for base; both taps target the same b checkbox.
agent-device press 61 "${CHECKBOX_Y:-1539}" --session "$SESSION"
az repos pr show --id "$PR_ID" --organization "$AZURE_DEVOPS_TEST_ORG" \
  --query description -o json > "$OUT/saved-description.json"
agent-device record stop --session "$SESSION"
agent-device screenshot "$OUT/after.png" --session "$SESSION"
python3 - "$OUT/saved-description.json" <<'PY'
import json, sys
body = json.load(open(sys.argv[1]))
print(ascii(body))
print('Expected head body:', body == '\ufeff- [ ] a\n- [x] b\n')
PY
