Files
Investidor-V2/outputs/investmoz-parques-L1-ativacao-20261018/prepare.py
T
nala 6bc0cc6f52
tests / ci (push) Canceled after 0s
versao nrgocios 3
2026-10-18 11:17:35 +02:00

47 lines
4.7 KiB
Python

from pathlib import Path
import json,hashlib,datetime,zipfile
root=Path(__file__).resolve().parents[2];out=Path(__file__).resolve().parent
release=root/'outputs/investmoz-parques-L1-QA-20261016';review=release/'para-revisao'
old=root/'outputs/investmoz-parques-ativacao-20261016'
sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
m=json.loads((review/'MANIFESTO-ENTREGA.json').read_text('utf-8'));r=json.loads((review/'RECIBO-INTEGRIDADE.json').read_text('utf-8'))
candidate='parques-L1-QA-fb56ec51f62e'
assert r['candidate']==candidate and m['code_hash']==r['code_hash']
for n,v in r['documents'].items():assert sha(review/n)==v['sha256']
archive=release/r['package']['name'];assert sha(archive)==r['package']['sha256']
with zipfile.ZipFile(archive) as z:
assert z.testzip() is None
entries=json.loads(z.read('MANIFESTO-INTEGRIDADE.json'))['entries']
assert set(z.namelist())==set(entries)|{'MANIFESTO-INTEGRIDADE.json'}
for n,v in entries.items():assert hashlib.sha256(z.read(n)).hexdigest()==v['sha256']
for s in m['sources']:assert (sha(root/s['path']) if (root/s['path']).exists() else None)==s['before_sha256'],s['path']
actual={p.relative_to(root).as_posix():sha(p) for f in ['app','config','routes','database','resources','public/build'] for p in (root/f).rglob('*') if p.is_file()}
base={'files':actual,'protected':{n:sha(root/n) for n in ['.env','composer.lock','package-lock.json']}}
(out/'ATIVO-ANTES.json').write_text(json.dumps(base,indent=2),'utf-8')
authorization={'at':datetime.datetime.now(datetime.timezone.utc).isoformat(),'candidate':candidate,'decision_record':'Mensagem expressa da Tempo em 18/10/2026: a Tempo autoriza a execução. Refere-se ao L1 DOC02 conferido nos turnos anteriores.','code_hash':m['code_hash'],'package_sha256':sha(archive),'QA_receipt_sha256':sha(review/'RECIBO-INTEGRIDADE.json'),'migration':'2026_10_16_140000_add_investment_zone_operational_details','limits':['Preservar matriz e backlog atuais','Sem fixtures, grants, flags, gravação ou publicação de fichas','Instalação nominal autenticada; backup/restauro fresco','Ficha integral aberta; navegação separada']}
assert not(out/'AUTORIZACAO-TEMPO.json').exists()
(out/'AUTORIZACAO-TEMPO.json').write_text(json.dumps(authorization,ensure_ascii=False,indent=2),'utf-8')
docs={n:sha(root/n) for n in ['docs/investmoz/v2/auditoria-portal/matriz-requisitos.csv','docs/investmoz/v2/auditoria-portal/backlog.md','docs/investmoz/unification/traceability-and-manual.md']}
(out/'DOCUMENTOS-ATUAIS-ANTES.json').write_text(json.dumps(docs,indent=2),'utf-8')
text=(old/'fresh-backup.php').read_text('utf-8').replace('outputs/investmoz-parques-QA-20261016','outputs/investmoz-parques-L1-QA-20261016').replace('MANIFESTO-CANDIDATA.json','MANIFESTO-ENTREGA.json')
text=text.replace("$manifest['candidate']","'"+candidate+"'")
text=text.replace("$release.'/ATIVO-ANTES.json'","__DIR__.'/ATIVO-ANTES.json'")
text=text.replace("'parks-before-'","'parks-L1-before-'")
text=text.replace("'economic_migration'=>(int)","'economic_migration'=>(int)")
text=text.replace("'economic_migration'=>1]","'economic_migration'=>1]")
text=text.replace("['ledger'=>0,'column'=>0,'economic_migration'=>1]","['ledger'=>1,'column'=>1,'economic_migration'=>1]")
needle=" file_put_contents(__DIR__.'/PREFLIGHT-ESQUEMA.json'"
pos=text.index(needle)
text=text[:pos]+" if((int)$source->query(\"SELECT count(*) FROM migrations WHERE migration='2026_10_16_140000_add_investment_zone_operational_details'\")->fetchColumn()!==0 || (int)$source->query(\"SELECT count(*) FROM information_schema.columns WHERE table_name='investment_zones' AND column_name='operational_details'\")->fetchColumn()!==0)throw new RuntimeException('L1 already present; reconcile');\n"+text[pos:]
(out/'fresh-backup.php').write_text(text,'utf-8')
text=(old/'boot-restored-clone.php').read_text('utf-8').replace('parques-operacionais-QA-6aacf653a98e',candidate)
needle=" $proof=['at'"
pos=text.index(needle)
text=text[:pos]+" $cipher=$db->table('investment_zones')->whereNotNull('editorial_draft')->value('editorial_draft'); if(!$cipher)throw new RuntimeException('No ciphertext available to verify restored key'); Illuminate\\Support\\Facades\\Crypt::decryptString($cipher);\n"+text[pos:]
text=text.replace("'DB_read_only'=>true","'restored_key_decryption_verified'=>true,'DB_read_only'=>true")
(out/'boot-restored-clone.php').write_text(text,'utf-8')
for n in ['verify-restored-files.py','cache-snapshot.php']:(out/n).write_bytes((old/n).read_bytes())
text=(old/'http-operacional.py').read_text('utf-8').replace('parques-operacionais-QA-6aacf653a98e',candidate)
(out/'http-operacional.py').write_text(text,'utf-8')
print(json.dumps({'preflight':'passed','runtime_files':len(actual),'sources':len(m['sources']),'package_entries':len(entries)+1,'active_changes':0}))