from pathlib import Path import json,hashlib,shutil,subprocess 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() baseline=json.loads((out/'ATIVO-ANTES.json').read_text('utf-8')) for n,h in {**baseline['files'],**baseline['protected']}.items():assert sha(root/n)==h,n plan=json.loads((root/'outputs/investmoz-parques-mapa-20261016/DOC01/FICHEIROS-PREVISTOS.json').read_text('utf-8'));paths=[x['path'] for x in plan['files']];assert len(paths)==16 assert not (private/'candidate-sources').exists() and not compat.exists() for n in paths: target=private/'candidate-sources'/n;target.parent.mkdir(parents=True,exist_ok=True);shutil.copy2(qa/n,target) if (root/n).exists(): target=private/'base-sources'/n;target.parent.mkdir(parents=True,exist_ok=True);shutil.copy2(root/n,target) shutil.copytree(qa/'public/build',private/'candidate-build') for folder in ['app','config','routes','database','resources','bootstrap']:shutil.copytree(qa/folder,compat/folder) for n in ['artisan','composer.json','composer.lock','package.json','package-lock.json','tsconfig.json','vite.config.ts','.env']:shutil.copy2(qa/n,compat/n) for folder in ['public/build','storage/framework/cache/data','storage/framework/views','storage/framework/sessions','storage/logs','storage/app/private','storage/app/public']:(compat/folder).mkdir(parents=True,exist_ok=True) for name in ['vendor','node_modules']:subprocess.run(['powershell','-NoProfile','-Command',f"New-Item -ItemType Junction -Path '{compat/name}' -Target '{root/name}' | Out-Null"],check=True,capture_output=True) for n in ['resources/js/pages/investment/zone.tsx','resources/js/pages/investment/zones.tsx','resources/js/pages/investor-path/index.tsx','routes/investment-zones.php','routes/investor-path.php','app/Http/Controllers/InvestorPathController.php']:shutil.copy2(root/n,compat/n) controller='app/Http/Controllers/InvestmentZoneController.php';s=(qa/controller).read_text('utf-8');old="'installation' => $management ? app(InvestmentZoneProfileInstallation::class)->preview($request->user()) : null,";assert s.count(old)==1;s=s.replace(old,"'installation' => null,");(compat/controller).write_text(s,'utf-8') record={'paths':paths,'retained':['app/Models/InvestmentZone.php',controller,'app/Services/InvestmentZones.php','app/Services/InvestmentZoneOperationalProfile.php','app/Services/InvestmentZonePathContext.php','app/Services/InvestorPath.php','resources/js/pages/investor-path/show.tsx'], 'migration_retained':'database/migrations/2026_10_16_130000_add_investment_zone_editorial_draft.php','base_editor_sha256':sha(root/'resources/js/pages/investment/zone.tsx'), 'candidate':{n:sha(qa/n)for n in paths},'base':{n:sha(root/n)if(root/n).exists()else None for n in paths},'compat_source':str(compat),'candidate_build_files':len(list((private/'candidate-build').rglob('*')))} (out/'COMPATIBILITY-PREPARED.json').write_text(json.dumps(record,indent=2)+'\n','utf-8');print(json.dumps({'sources_sealed':16,'retained_functional_sources':7,'old_editor_hash':record['base_editor_sha256'],'active_changes':0}))