#!/usr/bin/env bash
# Run from a directory containing stub.py and a Python venv named azure.
# Install: python3 -m venv azure; azure/bin/pip install azure-cli==2.92.0
# Initialize: AZURE_CONFIG_DIR="$PWD/azconfig" azure/bin/az extension add --name azure-devops --version 1.0.5
# Start stub separately: python3 stub.py
# Usage: bash reproduce.sh /path/to/checkout before-or-after
set -u
ROOT=$(cd -- "$(dirname -- "$0")" && pwd)
CHECKOUT=$1
SIDE=$2
RUN="$ROOT/run-$(date -u +%Y%m%dT%H%M%S)-$SIDE"
mkdir -p "$RUN"
export AZURE_CONFIG_DIR="$ROOT/azconfig"
# This credential is synthetic and accepted only by the local REST stub.
export AZURE_DEVOPS_EXT_PAT=synthetic-evidence-pat
AZ="$ROOT/azure/bin/az"
{
  "$AZ" version --query '"azure-cli"' -o tsv
  "$AZ" extension show --name azure-devops --query version -o tsv
  "$AZ" devops configure --defaults organization=http://127.0.0.1:18765/DefaultCollection project=proj
  "$AZ" repos pr list --detect false --query '[].{id:pullRequestId,title:title,status:status}' -o json
  echo "repos pr list exit=$?"
  "$AZ" account show --query user.name -o tsv
  echo "account show exit=$?"
  "$AZ" devops project list --top 1 --query 'value[0].url' -o tsv
  echo "project list exit=$?"
} > "$RUN/cli.txt" 2>&1
cat "$RUN/cli.txt"
cd "$CHECKOUT"
# The venv path is process-local, so T3 discovers the actual az executable.
exec env PATH="$ROOT/azure/bin:$PATH" T3CODE_DEV_SEED=0 vp run dev > "$RUN/app.log" 2>&1
# Browser steps (same on each build):
# Pair using the startup URL; set viewport 1280x900 and dark appearance.
# Open /settings/source-control; wait for Azure DevOps; scroll its row into view.
# Capture twice with a 500ms gap and require zero pixel differences.
# Crop the Azure DevOps row to exclude unrelated accounts; do not change UI state.
