"""Preserve corrected production bytes, then substitute exact prior production for a red run.""" from pathlib import Path import hashlib import json import zipfile base = Path(__file__).resolve().parent root = base.parents[1] rel = 'crates/oa-desktop/src/app/source_symbols.rs' destination = base / 'focus-corrected-source' destination.mkdir() corrected = (root / rel).read_bytes() with zipfile.ZipFile(base / 'attempt-4/inputs.zip') as archive: old = archive.read(rel) assert hashlib.sha256(old).hexdigest() == '1fb3709bb973e7dcfbcde56054d028e47d770a62f3b7c8b6fac411543a234b7b' assert corrected != old and b'focus-only' in corrected (destination / 'source_symbols.rs').write_bytes(corrected) record = {'path': rel, 'oldSha256': hashlib.sha256(old).hexdigest(), 'correctedSha256': hashlib.sha256(corrected).hexdigest(), 'correctedBytes': len(corrected)} (destination / 'manifest.json').write_text(json.dumps(record, indent=2)+'\n', encoding='utf-8') (root / rel).write_bytes(old) assert (root / rel).read_bytes() == old print(json.dumps(record), flush=True)