"""Independent Poppler/pypdf values against frozen separately observed Excel displays."""
from pathlib import Path
import json,sys,hashlib,os,subprocess,datetime
root=Path(__file__).resolve().parents[1];base=root/'benchmarks/research/office-wasm';folder=Path(sys.argv[1]).resolve();name='results.json' if (folder/'results.json').exists() else 'capture.json';cap=json.loads((folder/name).read_text());manifest=json.loads((root/'benchmarks/fixtures/yearfrac2/manifest.json').read_text());names={r['file']for r in manifest['files']};selected=[r for r in cap['rows'] if Path(r['source']).name in names];assert len(selected)==4 and all(r['pass']for r in selected)
# Only adapt the metadata shape to the existing independent reader. Input bytes and external values stay immutable.
meta=folder/'probe-validation-metadata';meta.mkdir(exist_ok=True)
for f in manifest['files']:
 assert hashlib.sha256((root/'benchmarks/fixtures/yearfrac2'/f['file']).read_bytes()).hexdigest()==f['sha256']
 for row in f['rows']:row.update(kind='uncached-formula',originalValue=row['formula'],format='0.0000000000')
(meta/'manifest.json').write_text(json.dumps(manifest,indent=2)+'\n')
rows=[]
for r in selected:
 path=base/r['output'] if name=='results.json' else folder/r['output'];rows.append({**r,'output':os.path.relpath(path,base)})
part=folder/'new-probe-reader-capture.json';part.write_text(json.dumps({'sourceCaptureSha256':hashlib.sha256((folder/name).read_bytes()).hexdigest(),'rows':rows},indent=2)+'\n');out=folder/'new-probe-validation.json';subprocess.run([sys.executable,str(base/'scripts/validate-calendar.py'),str(part),'--fixtures',str(meta),'--excel-reference',str(root/'benchmarks/research/office-yearfrac2/microsoft-excel'),'--output',str(out)],check=True);r=json.loads(out.read_text());r.update(sourceCells=760,sourceWorkbooks=2,originalManifestSha256=hashlib.sha256((root/'benchmarks/fixtures/yearfrac2/manifest.json').read_bytes()).hexdigest(),scope='760 unchanged original synthetic cells:304 raw DATE and456 YEARFRAC. Both source date systems, arbitrary days, month ends and centuries through2404. External Excel16.88 displayed values; Chromium/WebKit and two independent PDF readers. No source rewrite, user/provider upload or general-quality claim.');out.write_text(json.dumps(r,indent=2)+'\n');(folder/'new-probe-validator.py').write_bytes(Path(__file__).read_bytes());assert r['checks']==3040 and not r['failures']
