from pathlib import Path import json,hashlib,shutil out=Path(__file__).resolve().parent;root=out.parents[1];private=Path('C:/Users/macbook/.config/investmoz/parques-QA-20261016');qa=private/'source';compat=private/'compatibility-build-source' sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest();p=json.loads((out/'COMPATIBILITY-PREPARED.json').read_text('utf-8')) assert qa.resolve().as_posix().lower().startswith(private.resolve().as_posix().lower()+'/') and compat.resolve().as_posix().lower().startswith(private.resolve().as_posix().lower()+'/') for n,h in p['candidate'].items():assert sha(qa/n)==h,n for n in p['paths']: if n in p['retained'] or n==p['migration_retained']: if n=='app/Http/Controllers/InvestmentZoneController.php':shutil.copy2(compat/n,qa/n) continue if (root/n).exists():shutil.copy2(root/n,qa/n) else: target=(qa/n).resolve();assert target.as_posix().lower().startswith(qa.resolve().as_posix().lower()+'/') and sha(target)==p['candidate'][n];target.unlink() shutil.copytree(compat/'public/build',private/'compatibility-build',dirs_exist_ok=True) for file in (qa/'public/build').rglob('*'): if file.is_file(): relative=file.relative_to(qa/'public/build');frozen=json.loads((out/'FROZEN-CANDIDATE.json').read_text('utf-8'));assert sha(file)==frozen['build'][relative.as_posix()];file.unlink() shutil.copytree(private/'compatibility-build',qa/'public/build',dirs_exist_ok=True) record={'old_editor_sha256':sha(qa/'resources/js/pages/investment/zone.tsx'),'retained_sources':{n:sha(qa/n)for n in p['retained']},'migration_retained':sha(qa/p['migration_retained']), 'restored_or_removed':[n for n in p['paths']if n not in p['retained']and n!=p['migration_retained']], 'compatibility_manifest_sha256':sha(qa/'public/build/manifest.json'),'compatibility_files':{f.relative_to(qa/'public/build').as_posix():sha(f)for f in(qa/'public/build').rglob('*')if f.is_file()},'active_changes':0} assert record['old_editor_sha256']==p['base_editor_sha256'];(out/'REVERSAO-APLICADA-QA.json').write_text(json.dumps(record,indent=2)+'\n','utf-8');print(json.dumps({'old_editor_hash_matches':True,'retained_sources':len(p['retained']),'coherent_build_files':len(record['compatibility_files'])}))