"""Drive the Android reproduction from the open Transcription models list.
Usage: python3 cancel-download.py <agent-device-session> <output-directory>
Pair an isolated environment first; install/select Canary with seed.py.
"""
import datetime
import subprocess
import sys
import time
from pathlib import Path
session, output = sys.argv[1:]
run = Path(output) / datetime.datetime.now(datetime.UTC).strftime('%Y%m%dT%H%M%SZ')
run.mkdir(parents=True)
def device(*args):
    return subprocess.run(['agent-device', *args, '--session', session], check=True, capture_output=True, text=True).stdout
print(run, flush=True)
device('record', 'start', str(run / 'cancellation.mp4'), '--hide-touches')
device('press', 'label="Voxtral Mini 4B Realtime"', '--settle')
device('press', 'text="Download"', '--settle')
device('wait', 'text', 'Tap to cancel')
device('press', 'label="Voxtral Mini 4B Realtime"', '--settle')
device('wait', 'absent', 'text="Tap to cancel"')
device('snapshot', '-i')
device('screenshot', str(run / 'models.png'))
device('record', 'stop')
device('press', 'label="Close transcription models"', '--settle')
device('screenshot', str(run / 'voice-a.png'))
time.sleep(0.5)
device('screenshot', str(run / 'voice-b.png'))
print(device('snapshot', '-i'), flush=True)
