57 lines
2.8 KiB
Python
57 lines
2.8 KiB
Python
"""Re-run the unchanged PDF oracle and bind its results to final producer bytes."""
|
|
from pathlib import Path
|
|
import datetime
|
|
import hashlib
|
|
import json
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
|
|
HERE = Path(__file__).resolve().parent
|
|
ROOT = HERE.parents[2]
|
|
RAW = ROOT / '.artifacts/phase9'
|
|
|
|
|
|
def sha(path):
|
|
return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
|
|
|
|
def main():
|
|
producer = RAW / 'ordinary-cta-shard-1-exit.json'
|
|
assert json.loads(producer.read_text(encoding='utf-8-sig'))['exitCode'] == 0
|
|
sources = [ROOT / 'scripts/verify-cv-fidelity.py', RAW / 'ordinary-cta-shard-1.json', producer]
|
|
for name, count in [('fidelity', 16), ('settings-fidelity', 8)]:
|
|
folder = RAW / name
|
|
if name == 'settings-fidelity':
|
|
inputs = [json.loads(p.read_text(encoding='utf-8')) for p in sorted(folder.glob('*-measurements.json'))]
|
|
assert len(inputs) == 4
|
|
merged = dict(browserVersion=inputs[0]['browserVersion'], fixtures=[f for data in inputs for f in data['fixtures']])
|
|
(folder / 'measurements.json').write_text(json.dumps(merged, indent=2), encoding='utf-8')
|
|
fixtures = json.loads((folder / 'measurements.json').read_text(encoding='utf-8'))['fixtures']
|
|
assert len(fixtures) == len({f['fixture'] for f in fixtures}) == count
|
|
sources.append(folder / 'measurements.json')
|
|
sources.extend(sorted(folder.glob('*-measurements.json')))
|
|
for fixture in fixtures:
|
|
sources.append(folder / fixture['fixture'] / 'export.pdf')
|
|
sources.extend(sorted((folder / fixture['fixture']).glob('preview-*.png')))
|
|
sources = sorted(set(sources))
|
|
before = {p.relative_to(ROOT).as_posix(): sha(p) for p in sources}
|
|
commands = []
|
|
outputs = {}
|
|
for name in ['fidelity', 'settings-fidelity']:
|
|
command = ['rtk', 'proxy', sys.executable, 'scripts/verify-cv-fidelity.py', str(RAW / name)]
|
|
with (RAW / f'{name}-oracle.log').open('w', encoding='utf-8') as log:
|
|
result = subprocess.run(command, cwd=ROOT, stdout=log, stderr=subprocess.STDOUT, check=True)
|
|
commands.append(dict(command=command, exitCode=result.returncode))
|
|
target = HERE / 'p9-05/evidence' / f'{name}-results.json'
|
|
shutil.copyfile(RAW / name / 'fidelity-results.json', target)
|
|
outputs[target.relative_to(ROOT).as_posix()] = sha(target)
|
|
assert before == {p.relative_to(ROOT).as_posix(): sha(p) for p in sources}
|
|
record = dict(finishedUtc=datetime.datetime.now(datetime.timezone.utc).isoformat(), inputs=before, outputs=outputs, commands=commands)
|
|
(HERE / 'p9-05/evidence/native-document-provenance.json').write_text(json.dumps(record, indent=2) + '\n', encoding='utf-8')
|
|
print('Unchanged native oracle passed on final producer inputs; hashes stable.')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|