"""Capture the real Android MR description after installing this checkout's dev client.
Start a fresh server with T3CODE_DEV_SEED=0 vp run dev --host 0.0.0.0,
start Metro in apps/mobile with vp run dev:client --port <metro-port>,
add the cloned fixture with node apps/server/src/bin.ts project add <clone>
--title 'HTML reference proof' --base-dir <home>, then run this driver.
Use the same fixture, Pixel 9, light theme and 1080x2424 viewport on each side.
"""
import argparse,subprocess,pathlib,json,urllib.request,urllib.parse,time,hashlib
p=argparse.ArgumentParser()
for name in ['checkout','home','port','origin','project','repository','session','output','side']:
 p.add_argument('--'+name,required=True)
a=p.parse_args()
out=pathlib.Path(a.output)/time.strftime('%Y%m%d-%H%M%S'); out.mkdir(parents=True)
def run(args):
 return subprocess.run(args,cwd=a.checkout,check=True,capture_output=True,text=True).stdout
run(['.agents/skills/test-t3-mobile/scripts/pair-client.sh',a.port,a.home,a.origin,'agent-device','--session',a.session])
env=json.load(urllib.request.urlopen('http://127.0.0.1:'+a.port+'/.well-known/t3/environment'))['environmentId']
route='t3code-dev://pull-requests/'+env+'/'+a.project+'/'+urllib.parse.quote(a.repository,safe='')+'/1?host=gitlab.com'
run(['agent-device','open','com.t3tools.t3code.dev',route,'--session',a.session])
run(['agent-device','wait','text','Case C: See','--session',a.session])
previous=None
for n in range(10):
 image=out/(a.side+'-description-'+str(n)+'.png')
 run(['agent-device','screenshot',str(image),'--session',a.session])
 digest=hashlib.sha256(image.read_bytes()).digest()
 if digest==previous:
  print(image); break
 previous=digest
 time.sleep(.5)
else: raise SystemExit('No stable screenshot pair')
