#!/usr/bin/env bash
set -euo pipefail
# Manual proof driver transcript, with semantic selectors replacing snapshot refs.
# Prerequisites: tested checkout's fresh server + Metro, a pooled Pixel 9 with dev client,
# paired to that server, the seed.ts fixture, and doomed-attachment.png in Downloads.
# Run each side from clean app data. The same native fingerprint was used on both sides.
# Required env: SESSION, OUTPUT (new run directory), METRO_ORIGIN. CWD: tested checkout.
mkdir -p "$OUTPUT"
ad() { agent-device "$@" --session "$SESSION"; }
read_drafts() { node "$(dirname "$0")/read-drafts.mjs" > "$OUTPUT/$1.json"; }
ad press 'role=button label="Doomed thread"' --settle
ad wait 'label="Ask anything"'
ad fill 'label="Ask anything"' 'UNSENT DRAFT for doomed thread' --settle
ad keyboard dismiss
ad record start "$OUTPUT/flow.mp4" --hide-touches
ad press 'label="Add attachment"' --settle
ad press 'label="Choose Files"' --settle
ad press 'label="doomed-attachment.png"' --settle
ad wait 'label="Open doomed-attachment.png"'
read_drafts doomed-draft
ad back --settle
ad press 'role=button label="Control thread"' --settle
ad wait 'label="Ask anything"'
ad fill 'label="Ask anything"' 'CONTROL DRAFT keep me' --settle
ad keyboard dismiss
ad back --settle
read_drafts before-delete
# Inspect the pending upload named in before-delete.json in the isolated server's
# userdata/attachments directory; save existence/size before and after deletion.
ad longpress 'role=button label="Doomed thread"' --settle
ad press 'label="Delete"' --settle
ad wait 'role=button label="Delete"'
ad press 'role=button label="Delete"' --settle
ad wait absent 'role=button label="Doomed thread"'
read_drafts after-delete
ad record stop
ad open com.t3tools.t3code.dev --relaunch
ad wait 'role=button label="Control thread"'
read_drafts after-relaunch
# Capture two screenshots 500ms apart; retain only when pixel-identical.
# Compare the three JSON snapshots: doomed draft missing on head, present on base;
# control draft deep-equal to its pre-delete value; unreferenced pending PNG removed on head.
