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

30 lines
3.1 KiB
Python

from pathlib import Path
import json,hashlib,zipfile,datetime
root=Path(__file__).resolve().parents[2];out=Path(__file__).resolve().parent
release=root/'outputs/investmoz-promotor-contexto-QA-20261015'
old=root/'outputs/investmoz-classificacao-ativacao-20261015'
sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
m=json.loads((release/'MANIFESTO-DELTA.json').read_text('utf-8'))
r=json.loads((release/'RECIBO-INTEGRIDADE.json').read_text('utf-8'))
assert m['candidate']=='promotor-contexto-QA-e8858cb44dca'
assert sha(release/'MANIFESTO-DELTA.json')==r['manifest_sha256']
archive=root/'outputs'/r['zip']['name'];assert sha(archive)==r['zip']['sha256']
with zipfile.ZipFile(archive) as z:
assert z.testzip() is None and len(z.namelist())==18
for f in m['payload']:assert hashlib.sha256(z.read(f['path'])).hexdigest()==f['sha256']
baseline=json.loads((release/'ATIVO-ANTES.json').read_text('utf-8'))
for n,h in {**baseline['files'],**baseline['protected']}.items():assert sha(root/n)==h,n
for s in m['sources']:
p=root/s['path'];assert (sha(p) if p.is_file() else None)==s['previous_sha256'],s['path']
assert not (root/'storage/framework/down').exists()
auth={'at':datetime.datetime.now(datetime.timezone(datetime.timedelta(hours=2))).isoformat(),'candidate':m['candidate'],'decision':'A Tempo autoriza disponibilizar','scope':'Latest explicit consent applies the immediately preceding three-source proposal; normal account 2 editor GET only; no save, grants or business writes','sources':3,'build_changes':0,'fresh_backup_restore_required':True}
assert not (out/'AUTORIZACAO-TEMPO.json').exists()
(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':m['candidate'],'at':auth['at'],'protected_files':baseline['protected'],'verified_source_assets':len(baseline['files']),'previous_hashes':2,'required_absences':1,'archive_sha256':sha(archive)},indent=2)+'\n','utf-8')
backup=(old/'fresh-backup.php').read_text('utf-8').replace('investmoz-classificacao-multidimensional-QA-20261015','investmoz-promotor-contexto-QA-20261015').replace('MANIFESTO-ENTREGA.json','MANIFESTO-DELTA.json').replace('classification-before-','promoter-before-').replace('classification_before_','promoter_before_').replace("$baseline=json_decode(file_get_contents($release.'/ATIVO-FICHEIROS-ANTES.json'),true,512,JSON_THROW_ON_ERROR);","$baseline=json_decode(file_get_contents($release.'/ATIVO-ANTES.json'),true,512,JSON_THROW_ON_ERROR)['files'];")
(out/'fresh-backup.php').write_text(backup,'utf-8')
boot=(old/'boot-restored-clone.php').read_text('utf-8').replace('classificacao-multidimensional-QA-64ab05e20b95',m['candidate']).replace('classification_before_','promoter_before_').replace('classification-restore.test','promoter-restore.test')
(out/'boot-restored-clone.php').write_text(boot,'utf-8')
(out/'cache-snapshot.php').write_bytes((old/'cache-snapshot.php').read_bytes())
print(json.dumps({'candidate':m['candidate'],'archive_verified':True,'protected_files':len(baseline['files']),'previous_hashes':2,'absences':1,'active_changes':0}))