Files
Investidor-V2/outputs/investmoz-negocios-classificacao-ativacao-20261016/prepare.py
T
nala 6a76aac80f
tests / ci (push) Canceled after 0s
versao compilada 1
2026-10-16 09:17:28 +02:00

47 lines
5.0 KiB
Python

from pathlib import Path,PurePosixPath
import datetime,hashlib,json,zipfile
root=Path(__file__).resolve().parents[2];out=Path(__file__).resolve().parent
release=root/'outputs/investmoz-negocios-classificacao-QA-20261016'
sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
candidate='negocios-classificacao-QA-53311df2f59c'
assert not (out/'AUTORIZACAO-TEMPO.json').exists()
integrity=json.loads((release/'INTEGRIDADE-PACOTE.json').read_text('utf-8'))
receipt=json.loads((release/'RECIBO-QA.json').read_text('utf-8'))
manifest=json.loads((release/'MANIFESTO.json').read_text('utf-8'))
assert integrity['candidate']==receipt['candidate']==manifest['candidate']==candidate
assert sha(release/'RECIBO-QA.json')==integrity['receipt_sha256']=='37408adc283fdb8af25428a2c2230858168fba011a78f5645a5266698743e300'
archive=Path(integrity['package']);assert archive.parent==root/'outputs'
assert sha(archive)==integrity['sha256']=='23924f337acd24017c533c5861fda79fb84b5717bac24598ef227d05ac0ae6cb'
with zipfile.ZipFile(archive) as z:
assert z.testzip() is None and len(z.namelist())==len(set(z.namelist()))==1400
for r in receipt['files']:
p=PurePosixPath(r['path']);assert not p.is_absolute() and '..' not in p.parts
b=z.read(r['path']);assert hashlib.sha256(b).hexdigest()==r['sha256'] and len(b)==r['bytes']
assert z.read('review/MANIFESTO.json')==(release/'MANIFESTO.json').read_bytes()
for n,h in integrity['review_documents'].items():assert sha(release/n)==h
for s in manifest['sources']:
p=root/s['path'];assert (sha(p) if p.is_file() else None)==s['before_sha256'],s['path']
base=json.loads((release/'ATIVO-ANTES.json').read_text('utf-8'))
for n,h in {**base['files'],**base['protected']}.items():assert sha(root/n)==h,n
plan=json.loads((root/'outputs/investmoz-negocios-classificacao-mapa-20261016/FONTES-E-DELTA-PREVISTO.json').read_text('utf-8'))
for p in plan['reused_unchanged']:assert sha(root/p['path'])==p['sha256'],p['path']
assert not (root/'public/hot').exists() and not (root/'storage/framework/down').exists()
auth={'at':datetime.datetime.now(datetime.timezone(datetime.timedelta(hours=2))).isoformat(),'candidate':candidate,'authorization_message':'A tempo autoriza a prosseguir','scope':'Disponibilização das 11 fontes e compilação conforme proposta, recibo e procedimento revistos; backup/restauro fresco e conferência operacional sem guardar.','limits':['Não classificar anúncios reais ou divulgar relações','Sem repetir provas aceites ou incluir outras alterações','Preservar B, COUNTRY02, cache de dados, permissões, documentos e histórico','Cadeia sem caso positivo, sem prova volumétrica e limite do fixture de reversão permanecem explícitos'],'authorization_inferred_from_context':'Explicit assent to the immediately preceding specific deployment proposal, not permission for unrelated changes','review_scope':'Tempo conferiu documentos e hashes; não conferiu ZIP nem recibo completo. Integridade completa verificada localmente.'}
(out/'AUTORIZACAO-TEMPO.json').write_text(json.dumps(auth,ensure_ascii=False,indent=2)+'\n','utf-8')
(out/'PREFLIGHT.json').write_text(json.dumps({'candidate':candidate,'at':auth['at'],'package_SHA256':sha(archive),'package_entries':1400,'all_entry_hashes_verified':True,'source_replacements_matched':8,'new_absences_matched':3,'sources_build_config_locks_unchanged':len(base['files'])+len(base['protected']),'reused_dependencies_matched':len(plan['reused_unchanged']),'build_files':161,'maintenance_before':False},indent=2)+'\n','utf-8')
# Adapt the proven backup/restore harness, with the exact new candidate, baseline
# and a separate guarded QA restore database. Application sources are not edited.
prior=root/'outputs/investmoz-promotor-contexto-ativacao-20261015'
backup=(prior/'fresh-backup.php').read_text('utf-8')
backup=backup.replace('investmoz-promotor-contexto-QA-20261015','investmoz-negocios-classificacao-QA-20261016').replace('MANIFESTO-DELTA.json','MANIFESTO.json').replace("$p['previous_sha256']","$p['before_sha256']")
backup=backup.replace("$manifest['sources'])];","$manifest['sources'])];")
backup=backup.replace('promoter-before-','negocios-before-').replace('promoter_before_','negocios_before_')
backup=backup.replace("$baseline=json_decode(file_get_contents($release.'/ATIVO-ANTES.json'),true,512,JSON_THROW_ON_ERROR)['files'];","$baselineData=json_decode(file_get_contents($release.'/ATIVO-ANTES.json'),true,512,JSON_THROW_ON_ERROR);$baseline=array_merge($baselineData['files'],$baselineData['protected']);")
(out/'fresh-backup.php').write_text(backup,'utf-8')
boot=(prior/'boot-restored-clone.php').read_text('utf-8').replace('promotor-contexto-QA-e8858cb44dca',candidate).replace('promoter_before_','negocios_before_').replace('promoter-restore.test','negocios-restore.test')
boot=boot.replace("['/up','/login','/oportunidades']","['/up','/login','/negocios']")
(out/'boot-restored-clone.php').write_text(boot,'utf-8')
(out/'cache-snapshot.php').write_bytes((prior/'cache-snapshot.php').read_bytes())
print(json.dumps({'candidate':candidate,'preflight':'passed','backup_harness':'prepared','active_changes':0}))