"""Run pinned checkers privately; persist each diagnostic report and return code.""" import pathlib,json,subprocess,os,datetime,sys,time P=pathlib.Path(__file__).resolve().parent jar=P/'tools/epubcheck-5.4.0/epubcheck.jar' electron=P/'tools/node_modules/electron/dist/electron.exe' def run(case,strict=False): f=P/'fixtures'/(case+'.epub'); target=P/'raw'/case;target.mkdir(parents=True,exist_ok=True) env=os.environ.copy();env.pop('ELECTRON_RUN_AS_NODE',None);env['BENCH_NETWORK_LOG']=str(target/'denied-network.jsonl');env['BENCH_VERSIONS_OUT']=str(P/'engine-versions.json') for tool,cmd in [('epubcheck',['java','-jar',str(jar),str(f),'--json',str(target/'epubcheck.json')]),('ace',[str(electron),str(P/'offline-ace.cjs'),str(f),'-o',str(target/('ace-strict' if strict else 'ace')),'-f']+(['--exiterror2'] if strict else []))]: if strict and tool=='epubcheck':continue label=tool+('-strict' if strict else '');start=time.time() try: r=subprocess.run(cmd,cwd=P,env=env,capture_output=True,text=True,encoding='utf8',errors='replace',timeout=90,creationflags=subprocess.CREATE_NO_WINDOW) (target/(label+'.log')).write_text(r.stdout+'\nSTDERR\n'+r.stderr,encoding='utf8') result={'case':case,'tool':label,'exit_code':r.returncode,'seconds':round(time.time()-start,3),'command':[str(x).replace(str(P),'BENCH_ROOT') for x in cmd],'completed_at_utc':datetime.datetime.now(datetime.timezone.utc).isoformat()} except subprocess.TimeoutExpired as e:result={'case':case,'tool':label,'processing_error':'timeout','seconds':90} (target/(label+'-execution.json')).write_text(json.dumps(result,indent=2));print(result['case'],result['tool'],result.get('exit_code',result.get('processing_error')),flush=True) if __name__=='__main__': cases=sys.argv[1:] or [x['id'] for x in json.loads((P/'fixture-manifest.json').read_text())] for case in cases:run(case) if 'image-alt-missing' in cases:run('image-alt-missing',True)