import subprocess,time,pathlib,sys,hashlib
root=pathlib.Path(__file__).parent
side=sys.argv[1]
root=root/(side+'-'+time.strftime('%Y%m%dT%H%M%S'))
root.mkdir()
def run(*args):
 p=subprocess.run(['agent-device',*args,'--session','proof46787'],text=True,capture_output=True,check=True)
 print(p.stdout,flush=True)
run('scroll','top','--settle')
for window,label in [('24h','Past 24 hours'),('7d','Past 7 days'),('30d','Past 30 days')]:
 run('press',f'text="{label}"','--settle')
 run('scroll','down','450','--settle')
 a=root/f'{side}-{window}.png'; b=root/f'{side}-{window}-check.png'
 for attempt in range(3):
  run('screenshot',str(a)); time.sleep(.5); run('screenshot',str(b))
  if a.read_bytes()==b.read_bytes(): break
 else: raise RuntimeError('Screenshots not stable')
 print(f'STABLE {side} {window}',flush=True)
 run('scroll','top','--settle')
