#!/usr/bin/env bash
set -euo pipefail
# Run from the tested checkout after pairing a Pixel 9 and opening file01.ts.
# SESSION is the leased session, FIXTURE_PROJECT is the disposable GitLab project id.
# FIXTURE_BRANCH is its MR branch; EVIDENCE_DIR is a new output directory.
: "${SESSION:?}" "${FIXTURE_PROJECT:?}" "${FIXTURE_BRANCH:?}" "${EVIDENCE_DIR:?}"
ad() { agent-device "$@" --session "$SESSION"; }
ad swipe 530 1950 530 400 --count 4 --pause-ms 400
ad snapshot -i
# The proxy's fail-page2 flag must exist before opening the diff.
# Confirm Retry loading remaining files, then update the real MR head.
python3 - "$FIXTURE_BRANCH" > "$EVIDENCE_DIR/update.json" <<'JSON'
import json,sys
print(json.dumps({'branch':sys.argv[1],'commit_message':'Replace obsolete line','actions':[{'action':'update','file_path':'file01.ts','content':'export const marker = "NEW-REPLACEMENT-LINE";\n'}]}))
JSON
glab api -X POST "projects/$FIXTURE_PROJECT/repository/commits" --input "$EVIDENCE_DIR/update.json"
sleep 65
ad press 'label="Changed files"' --settle
ad press 'label="View diff for file01.ts, 1 additions, 0 deletions"' --settle
ad press 'label="Diff options"' --settle
ad press 'label="Add comment"' --settle
ad press 'label="Cancel"' --settle
# Remove the proxy's fail-page2 flag before the following reload.
ad record start "$EVIDENCE_DIR/reload.mp4" --quality medium --hide-touches
ad press 'label="Reload changes"' --settle
ad press 430 459 --settle
ad record stop
ad screenshot "$EVIDENCE_DIR/editor.png"
