Files
EscapistsReintroduced/docs/evidence/crash-start-2026-10-03/validation/apply_proposal.py
T
jakub 6a667d8deb Capture current mission, AI, map and administration development
Include the current addon, terrain integrations, tools, regression tests and recorded development evidence.
2026-10-13 22:52:53 +02:00

18 lines
1.1 KiB
Python

import hashlib,json,subprocess,sys
from pathlib import Path
root=Path('/home/jakub/devel/escapistsrereintroduced')
proposal=Path(sys.argv[1]); manifest=json.loads((proposal/'source-manifest.json').read_text()); patch=proposal/'fix.patch'
if 'files' not in manifest:manifest['files']={manifest['file']:manifest}
def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest() if p.is_file() else None
assert sha(patch)==manifest['patch_sha256']
for name,entry in manifest['files'].items():
p=root/name
assert p.resolve().is_relative_to(root)
assert sha(p)==entry['baseline_sha256'],name
cached=subprocess.check_output(['git','diff','--cached','--binary'],cwd=root)
subprocess.run(['git','apply','--check',str(patch)],cwd=root,check=True)
subprocess.run(['git','apply',str(patch)],cwd=root,check=True)
for name,entry in manifest['files'].items():assert sha(root/name)==entry.get('proposal_sha256',entry.get('proposed_sha256')),name
assert subprocess.check_output(['git','diff','--cached','--binary'],cwd=root)==cached
print('Applied exact proposal:',proposal,len(manifest['files']),'paths; staged diff unchanged')