#!/usr/bin/env bash
set -euo pipefail
# Run from each tested checkout after vp i and starting its fresh dev server.
# Supply AZURE_DEVOPS_EXT_PAT to the server environment, and enable Pi in Settings.
# REPO is the synthetic Azure repository clone; PR_NUMBER is its open PR number.
: "${REPO:?}" "${PR_NUMBER:?}"
node apps/server/src/bin.ts project add "$REPO" --title 'Azure PR URL evidence' --base-dir .t3
node apps/server/src/bin.ts thread start "$REPO" \
  "Call pull_request_read exactly once with only {\"number\":$PR_NUMBER}. Report raw host, repository, number and url. Do not pass URL or repository. Do not use other tools." \
  --title 'Azure PR URL evidence' --provider pi --model anthropic/claude-haiku-5-5 --wait --json --base-dir .t3
# Open the returned thread in the web client. Inspect the recorded tool input/output.
# Authenticate GET requests with the PAT kept in the environment, never in a URL.
python3 - <<'PY'
import base64, os, urllib.request, urllib.error
n=os.environ['PR_NUMBER']
for url in [f'https://dev.azure.com/t3-factory-test/pullrequest/{n}', f'https://dev.azure.com/t3code-factory-test/t3-factory-test/_git/t3-factory-test/pullrequest/{n}']:
 req=urllib.request.Request(url,headers={'Authorization':'Basic '+base64.b64encode(('pat:'+os.environ['AZURE_DEVOPS_EXT_PAT']).encode()).decode()})
 try:
  with urllib.request.urlopen(req) as r: status=r.status
 except urllib.error.HTTPError as e: status=e.code
 print(url, status)
PY
