"""Real-app Android touch-scroll driver; drafts remain private.
Run from the checkout that owns the agent-device session.
Usage: python3 android-review-proof.py SESSION OUTPUT [seed|capture]
Setup: run that commit's dev server with T3CODE_DEV_SEED=0 and Metro,
install with vp run mobile:install android --session SESSION, pair the app,
open Pulls > PR 34887 > Changed files > PullRequestSheetContent.tsx.
Device: Pixel 9, Android API 36, 1080 x 2424, default light theme.
Enable Android Developer options > Pointer location for gesture-visible recordings.
Clean screenshots can be captured with this overlay disabled.
"""
import pathlib, subprocess, sys, time
session, destination, action = sys.argv[1:]
out = pathlib.Path(destination) / time.strftime('%Y%m%d-%H%M%S')
out.mkdir(parents=True)
def run(*args, check=True):
    p = subprocess.run(['agent-device', *map(str,args), '--session', session], capture_output=True, text=True)
    print(p.stdout, p.stderr, flush=True)
    if check and p.returncode: raise RuntimeError(args)
    return p
if action == 'seed':
    # Descending lines keep earlier tap coordinates stable as draft cards appear.
    for line,y in [(34,915),(33,858),(32,800),(31,744),(30,687),(29,630)]:
        run('press',380,y,'--settle')
        run('fill','role="text-field"',f'Draft feedback for line {line}.','--settle')
        run('press','role="button" label="Save draft"','--settle')
    run('press','role="button" label="Submit review · 6"','--settle')
elif action == 'capture':
    def still(label):
        a,b=out/f'{label}-check.png',out/f'{label}.png'
        for _ in range(4):
            run('screenshot',a); time.sleep(.5); run('screenshot',b)
            if subprocess.run(['compare','-metric','AE',str(a),str(b),'null:'],capture_output=True).returncode == 0: return
        raise RuntimeError('Screenshots did not stabilize')
    still('initial')
    run('record','start',out/'scroll.mp4','--scope','app')
    for _ in range(4): run('scroll','down','.6','--duration-ms','1200',check=False)
    run('record','stop')
    still('after-four-drags')
    run('snapshot','-i')
else: raise ValueError(action)
print('OUTPUT',out)
