#!/usr/bin/env bash
set -euo pipefail
# Run from either checkout after seeding with manual-pr-page-driver.ts.
# The session must show Pulls, all projects, and a completed healthy refresh.
session=$1
out=$2
export GLAB_CONFIG_DIR=$3
mkdir -p "$out"
trap 'glab config set api_host gitlab.com --host gitlab.com' EXIT
glab config set api_host gitlab.com --host gitlab.com
agent-device record start "$out/pagination.mp4" --session "$session"
# Precondition: a completed healthy refresh with both repository cursors.
# No provider response is fabricated: real glab gets a connection refusal.
glab config set api_host 127.0.0.1:9 --host gitlab.com
agent-device swipe 200 720 200 220 --count 14 --pause-ms 500 --session "$session"
agent-device snapshot -i --session "$session"
agent-device screenshot "$out/error-a.png" --session "$session"
agent-device screenshot "$out/error-b.png" --session "$session"
# On this 402x874 viewport, the footer's Try again button is at (80,724).
agent-device click 80 724 --session "$session"
agent-device swipe 200 720 200 220 --count 8 --pause-ms 500 --session "$session"
agent-device snapshot -i --session "$session"
agent-device screenshot "$out/retry.png" --session "$session"
agent-device record stop --session "$session"
