44 lines
3.8 KiB
Python
44 lines
3.8 KiB
Python
from pathlib import Path
|
|
import hashlib,json,zipfile
|
|
|
|
root=Path('C:/laragon/www/portal-investidor')
|
|
out=root/'outputs/investmoz-negocios-classificacao-QA-20261016'
|
|
qa=Path('C:/Users/macbook/.config/investmoz/negocios-classificacao-QA-20261016/source')
|
|
sha=lambda b:hashlib.sha256(b).hexdigest()
|
|
manifest=json.loads((out/'MANIFESTO.json').read_text())
|
|
assert not (out/'RECIBO-QA.json').exists(),'Preserve sealed receipt'
|
|
files={}
|
|
for r in manifest['sources']:
|
|
p=r['path'];assert sha((qa/p).read_bytes())==r['after_sha256']
|
|
files['candidate/'+p]=qa/p
|
|
if r['operation']=='replace':
|
|
assert sha((root/p).read_bytes())==r['before_sha256']
|
|
files['reversal/'+p]=root/p
|
|
else:assert not (root/p).exists()
|
|
for r in manifest['build']:
|
|
assert sha((qa/r['path']).read_bytes())==r['sha256']
|
|
files['candidate/'+r['path']]=qa/r['path']
|
|
previous_build=[]
|
|
for f in sorted((root/'public/build').rglob('*')):
|
|
if f.is_file():
|
|
p=f.relative_to(root).as_posix();files['reversal/'+p]=f
|
|
previous_build.append({'path':p,'sha256':sha(f.read_bytes()),'bytes':f.stat().st_size})
|
|
(out/'REVERSAO-MANIFESTO.json').write_text(json.dumps({'candidate':manifest['candidate'],'source_replacements':[{'path':r['path'],'sha256':r['before_sha256']} for r in manifest['sources'] if r['operation']=='replace'],'remove_new_only_after_restoring_references':[{'path':r['path'],'only_if_sha256':r['after_sha256']} for r in manifest['sources'] if r['operation']=='new'],'previous_build':previous_build,'database_rollback':False,'preserve_classification_revisions_after_old_edit':True,'fresh_destination_snapshot_required_at_execution':True},ensure_ascii=False,indent=2)+'\n',encoding='utf-8')
|
|
documents=['RELATORIO-QA.md','PROPOSTA-UNICA-TEMPO.md','PROCEDIMENTO-E-REVERSAO.md','MANIFESTO.json','REVERSAO-MANIFESTO.json','QA-ISOLAMENTO.json','FIXTURE-QA.json','HTTP-QA.json','SCOPES-QA.json','INTERFACE-QA.json','REVERSAO-APOS-EDICAO-ANTERIOR.json','PRESERVACAO-FINAL.json','VERIFICACAO-TECNICA.json','CONSOLIDACAO-MATRIZ.json','QA-ERRO-VISIVEL.jpg','QA-PROJECAO-PUBLICA.jpg','QA-FILTROS-PUBLICOS.jpg','QA-RECUPERACAO-PRIVADA.jpg']
|
|
for p in documents:files['review/'+p]=out/p
|
|
assert all(p.is_file() for p in files.values())
|
|
receipt={'candidate':manifest['candidate'],'date':'2026-10-16','source_count':11,'replacements':8,'new_files':3,'build_count':manifest['build_count'],'previous_build_count':len(previous_build),'scope':'QA preparation only; no active authorization','files':[{'path':name,'sha256':sha(path.read_bytes()),'bytes':path.stat().st_size} for name,path in sorted(files.items())],'verification':'All listed ZIP entries re-read after writing and compared byte by byte with this receipt; ZIP CRC checked. The receipt does not hash itself.'}
|
|
(out/'RECIBO-QA.json').write_text(json.dumps(receipt,ensure_ascii=False,indent=2)+'\n',encoding='utf-8')
|
|
files['review/RECIBO-QA.json']=out/'RECIBO-QA.json'
|
|
zip_path=root/'outputs'/f"{manifest['candidate']}.zip"
|
|
assert not zip_path.exists()
|
|
with zipfile.ZipFile(zip_path,'x',compression=zipfile.ZIP_DEFLATED,compresslevel=9) as z:
|
|
for name,path in sorted(files.items()):z.writestr(name,path.read_bytes())
|
|
with zipfile.ZipFile(zip_path) as z:
|
|
assert z.testzip() is None
|
|
assert set(z.namelist())==set(files)
|
|
for name,path in files.items():assert z.read(name)==path.read_bytes()
|
|
integrity={'candidate':manifest['candidate'],'package':str(zip_path),'sha256':sha(zip_path.read_bytes()),'bytes':zip_path.stat().st_size,'entries':len(files),'CRC_and_all_entry_hashes_verified':True,'receipt_sha256':sha((out/'RECIBO-QA.json').read_bytes()),'review_documents':{p:sha((out/p).read_bytes()) for p in documents[:3]},'contains_credentials_env_dump_sessions':False,'active_unchanged':True}
|
|
(out/'INTEGRIDADE-PACOTE.json').write_text(json.dumps(integrity,ensure_ascii=False,indent=2)+'\n',encoding='utf-8')
|
|
print(json.dumps(integrity))
|