"""Actual cold-boot/slot circles for the two requested always-On hidden rules.
Underlying geometry/roster/ABI suites remain separate and mandatory.
"""
from pathlib import Path
from concurrent.futures import ThreadPoolExecutor
import json,os,subprocess,hashlib

def verify(rom,output,make_battery,field):
 h=Path(__file__).resolve().parent;o=Path(output)/('permanent-'+field);o.mkdir(parents=True,exist_ok=True)
 data=Path(rom).read_bytes();assert data.count(b'Faceoff Dots')==data.count(b'OT SO Rules')==0
 hook='''from pathlib import Path
import json
rows=[]
def rw(a):return(wram[ram(a)]<<8)|wram[ram(a+1)]
def test_tick(f):
 if f in [1000,1200,1400,1600,1800,2000,2200]:
  row=dict(frame=f,slot=rw(0xf06a),view=rw(0xf06c),dots=rw(0xf848),strict=rw(0xf046))
  assert row['dots']==row['strict']==1,('requested permanent rules lost on actual boot/slot circle',row)
  rows.append(row);(Path(outdir)/'results.json').write_text(json.dumps(rows,indent=2))
'''
 def trial(z):
  dev,gp,value=z;p=o/f'dev{dev}-gp{gp}-old{value}';p.mkdir(exist_ok=True);(p/'battery.srm').write_bytes(make_battery(gp,value));(p/'hook.py').write_text(hook)
  lines=[f'{1100+200*i} press 1 Right 5'for i in range(3)]+[f'{1700+200*i} press 1 Left 5'for i in range(3)]+['2200 snap','2201 exit'];(p/'commands.txt').write_text('\n'.join(lines)+'\n')
  env={k:v for k,v in os.environ.items()if not k.startswith('GPGX_')};env.update(GPGX_DEV=str(dev),GPGX_SRM=str(p/'battery.srm'),GPGX_HOOK=str(p/'hook.py'))
  with(p/'log').open('w')as log:subprocess.run(['python3',str(h/'test_core.py'),str(Path(rom).resolve()),str(p/'commands.txt'),str(p)],env=env,stdout=log,stderr=log,check=True,timeout=45)
  rows=json.loads((p/'results.json').read_text());assert [(r['slot'],r['view'])for r in rows]==[(1,1),(2,1),(3,1),(3,0),(3,1),(2,1),(1,1)],('real slot circle',z,rows)
  return dict(device=dev,gp=gp,historical_value=value,rows=rows)
 with ThreadPoolExecutor(max_workers=3)as pool:rows=list(pool.map(trial,[(dev,gp,val)for dev in[513,1281]for gp in[0,1]for val in[0,1]]))
 result=dict(ROM_sha256=hashlib.sha256(data).hexdigest(),cases=rows,hidden_labels_absent=True,actual_boot_slot_samples=112)
 (o/'result.json').write_text(json.dumps(result,indent=2)+'\n');print('PASS16 real boot/slot circles,112 always-On samples, both devices/old choices/GP0 and1; hidden labels absent',flush=True);return result
