import subprocess,time,sys,hashlib,pathlib
root=pathlib.Path(__file__).parent
label=sys.argv[1]
runroot=root/'stable'/str(time.time_ns());runroot.mkdir(parents=True)
for n in range(8):
 a=runroot/(str(n)+'-a.png');b=runroot/(str(n)+'-b.png')
 for path in [a,b]:
  subprocess.run(['agent-device','screenshot',str(path),'--session','auth17114'],check=True,stdout=subprocess.DEVNULL)
  if path==a:time.sleep(.5)
 if a.read_bytes()==b.read_bytes():
  (root/(label+'.png')).write_bytes(b.read_bytes());print(label+': two identical captures, 500ms wait between captures');break
else:raise SystemExit(label+': screen did not settle')
