"""Restore the explicitly base64-encoded fixture corpus into a chosen empty directory. Download fixture-corpus.json beside this script. Run: python restore-corpus.py restored-experiment Then install requirements-lock.txt there and run reproduce.py. No network calls. """ from pathlib import Path,PurePosixPath import sys,json,base64,hashlib source=Path(__file__).resolve().parent/'fixture-corpus.json' target=Path(sys.argv[1] if len(sys.argv)>1 else 'restored-experiment').resolve() assert not target.exists() or not any(target.iterdir()),'Choose a new or empty destination directory.' data=json.loads(source.read_text(encoding='utf-8')) for item in data['files']: name=PurePosixPath(item['file']) assert not name.is_absolute() and '..' not in name.parts and ':' not in str(name) and '\\' not in str(name) path=target.joinpath(*name.parts).resolve() assert path.is_relative_to(target) raw=base64.b64decode(item['base64'],validate=True) assert len(raw)==item['bytes'] and hashlib.sha256(raw).hexdigest()==item['sha256'] path.parent.mkdir(parents=True,exist_ok=True);path.write_bytes(raw) print(f'Restored {len(data["files"])} fingerprint-checked files to {target}')