"""Run after pairing the synthetic Korean fixture in the Android dev client."""
import sys,subprocess,time,unicodedata
from pathlib import Path
from PIL import Image,ImageChops
session,directory,side=sys.argv[1:]
out=Path(directory);out.mkdir(parents=True,exist_ok=False)
def ad(*args):
 return subprocess.check_output(['agent-device',*args,'--session',session],text=True)
def stable(name):
 previous=None
 for i in range(10):
  raw=out/f'{name}-raw-{i}.png'
  ad('screenshot',str(raw),'--normalize-status-bar')
  im=Image.open(raw).convert('RGB')
  if previous is not None and ImageChops.difference(previous,im).getbbox() is None:
   im.crop((0,240,im.width,im.height)).save(out/f'{name}.png')
   return
  previous=im;time.sleep(.5)
 raise RuntimeError('No identical screenshot pair 500ms apart')
ad('press','label="Korean file display, Done"','--settle')
ad('wait','label="Ask anything" editable=true')
ad('record','start',str(out/'interaction-raw.mp4'),'--hide-touches')
ad('fill','label="Ask anything" editable=true','@','--settle')
ad('wait','label="b.txt, 보고서"')
stable('menu')
norm='NFD' if side=='base' else 'NFC'
n=unicodedata.normalize(norm,'시안.txt');f=unicodedata.normalize(norm,'시안')
ad('press',f'label="{n}, {f}"','--settle')
stable('selected')
ad('record','stop')
print('Captured native menu and selected mention; screenshots crop the environment header only.')
