#!/usr/bin/env python3 """Verify real showbox status/channels, exact bodies and continued PDF output. Both jobs must return TeX's intentional show diagnostic status 1. Unexpected errors remain failures. The runtime native engine never invokes TeX. """ import argparse import json import os import re import subprocess import xml.etree.ElementTree as ET from pathlib import Path def words(pdf): data=subprocess.check_output(['pdftotext','-bbox',str(pdf),'-']) pdf.with_suffix('.bbox.html').write_bytes(data) return [[(w.text,{k:float(v)for k,v in w.attrib.items()})for w in p.iter()if w.tag.endswith('}word')] for p in ET.fromstring(data).iter()if p.tag.endswith('}page')] def main(): p=argparse.ArgumentParser(description=__doc__) p.add_argument('--binary',type=Path,required=True) p.add_argument('--output-dir',type=Path,required=True) p.add_argument('--json',type=Path,required=True) a=p.parse_args();root=Path(__file__).resolve().parent.parent fixture=root/'examples/native-bootstrap/diagnostics.tex';out=a.output_dir.resolve();out.mkdir(parents=True,exist_ok=True) (out/'reference.tex').write_text('\\pdfoutput=1 \\pdfpagewidth=612bp \\pdfpageheight=792bp ' '\\vsize=648bp \\topskip=10bp\n'+fixture.read_text()) env={**os.environ,'TEXINPUTS':str(fixture.parent)+os.pathsep+os.environ.get('TEXINPUTS','')} native=subprocess.run([str(a.binary.resolve()),'native','--initex','--etex',str(fixture),'diagnostics.pdf'],cwd=out,capture_output=True,text=True) reference=subprocess.run(['pdftex','-ini','-etex','-interaction=nonstopmode','reference.tex'],cwd=out,env=env,capture_output=True,text=True) for name,r in [('native',native),('reference',reference)]: (out/(name+'-stdout.txt')).write_text(r.stdout);(out/(name+'-stderr.txt')).write_text(r.stderr) logs=[(out/n).read_text()for n in ['diagnostics.log','reference.log']] bodies=[re.findall(r'(?ms)^> \\box\d+=.*?(?=\n! OK\.)',s)for s in logs] only_show_errors=all([l for l in s.splitlines()if l.startswith('! ')]==['! OK.']*5 for s in logs) pdfs=[out/'diagnostics.pdf',out/'reference.pdf'];pages=[words(f)for f in pdfs] text_equal=[[w[0]for w in page]for page in pages[0]]==[[w[0]for w in page]for page in pages[1]] n=[w for page in pages[0]for w in page];r=[w for page in pages[1]for w in page] errors={k:max(abs(x[1][k]-y[1][k])for x,y in zip(n,r))for k in ['xMin','xMax','yMin','yMax']}if text_equal and n else None channels=('see the transcript file'in native.stderr and 'see the transcript file'not in logs[0] and 'BEFORE_SHOWS'in native.stderr and 'AFTER_SHOWS'in native.stderr) passed=([native.returncode,reference.returncode]==[1,1]and only_show_errors and'error:'not in native.stderr and bodies[0]==bodies[1]and len(bodies[0])==5 and channels and all('AFTER_SHOWS'in s for s in logs) and text_equal and[len(p)for p in pages]==[1,1]and errors is not None and max(errors.values())<=.02) result=dict(passed=passed,exit_codes=[native.returncode,reference.returncode],show_counts=list(map(len,bodies)), diagnostic_bodies_equal=bodies[0]==bodies[1],channels_verified=channels,only_show_errors=only_show_errors, pages=list(map(len,pages)),word_counts=[len(n),len(r)],text_equal=text_equal,max_word_box_errors_bp=errors, scope='Intentional nonstop show diagnostics, exact supported box bodies and unchanged 0.02bp PDF gate; source-context/error recovery is not certified.') a.json.parent.mkdir(parents=True,exist_ok=True);a.json.write_text(json.dumps(result,indent=2)+'\n');print(json.dumps(result,indent=2)) if not passed:raise SystemExit(1) if __name__=='__main__': main()