Files
Investidor-V2/outputs/investmoz-parques-mapa-20261016/seal-map.py
T
nala cef6e201c7
tests / ci (push) Canceled after 0s
versao nrgocios 2
2026-10-16 20:11:05 +02:00

36 lines
4.9 KiB
Python

from pathlib import Path,PurePosixPath
import json,csv,io,hashlib,datetime,zipfile
out=Path(__file__).resolve().parent;root=out.parents[1];review=out/'para-revisao';sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
load=lambda n:json.loads((out/n).read_text('utf-8'));baseline=load('BASELINE-APLICACAO.json')
for n,h in {**baseline['files'],**baseline['protected']}.items():assert sha(root/n)==h,n
current={p.relative_to(root).as_posix()for folder in ['app','config','routes','database','resources','public/build']for p in(root/folder).rglob('*')if p.is_file()};assert current==set(baseline['files'])
csv.field_size_limit(10000000)
def records(raw):
text=raw.decode('utf-8-sig');lines=text.splitlines(keepends=True);r=csv.reader(io.StringIO(text,newline=''));h=next(r);start=r.line_num;rows=[]
for row in r:
end=r.line_num;rows.append((row,''.join(lines[start:end])));start=end
return h,rows
old=(out/'matrix-tool/before.csv').read_bytes();new=(root/'docs/investmoz/v2/auditoria-portal/matriz-requisitos.csv').read_bytes();h,x=records(old);hh,y=records(new);assert h==hh and len(x)==len(y)==3402
matrix=load('MATRIZ-ATUALIZACAO.json');ids=set(matrix['rows_updated']);allowed={h.index(n)for n in matrix['columns_updated']};preserved=0
for (a,raw),(b,now)in zip(x,y):
assert a[0]==b[0]
if a[0]not in ids:assert raw==now;preserved+=1
else:assert all(v==b[i]for i,v in enumerate(a)if i not in allowed)
assert preserved==3394 and sha(root/'docs/investmoz/v2/auditoria-portal/matriz-requisitos.csv')==matrix['sha256_after']
delta=json.loads((review/'ATUALIZACAO-MESMA-MATRIZ.json').read_text('utf-8'));delta.update({'rows_updated':matrix['rows_updated'],'matrix_sha256_before':matrix['sha256_before'],'matrix_sha256_after':matrix['sha256_after'],'unrelated_raw_rows_preserved':preserved,'states_and_criteria_preserved':True});(review/'ATUALIZACAO-MESMA-MATRIZ.json').write_text(json.dumps(delta,ensure_ascii=False,indent=2)+'\n','utf-8')
proof={'at':datetime.datetime.now(datetime.timezone.utc).isoformat(),'application_sources_and_build_unchanged':len(baseline['files']),'protected_config_and_locks_unchanged':len(baseline['protected']),'active_database_connections':0,'active_changes':0,'isolated_snapshot_inspection':'READ ONLY','functional_implementation_started':False,'accepted_tests_repeated':False,'matrix_updated_rows':8,'unrelated_raw_rows_preserved':3394,'states_and_criteria_preserved':True,'full_corpus_fresh_scan_claimed':False,'source_inventory_reused_count':10717,'current_attachments_count':60,'bounded_exemplars':10,'backlog_sha256':sha(root/'docs/investmoz/v2/auditoria-portal/backlog.md')}
(review/'VERIFICACAO-LEITURA-E-PRESERVACAO.json').write_text(json.dumps(proof,ensure_ascii=False,indent=2)+'\n','utf-8')
files={'documents/'+p.name:p for p in review.iterdir()if p.is_file()and p.name!='RECIBO-INTEGRIDADE.json'}
# Deliberately exclude the full corpus inventory, raw private zone record and original documents.
index={'type':'planning_only_no_runtime_payload','entries':{n:{'sha256':sha(p),'bytes':p.stat().st_size}for n,p in files.items()},'excluded':['Original DOCX/PDF files and full corpus paths','Raw private restored database inventory','Credentials, MFA, environment, dumps and runtime payload']}
indexfile=out/'MANIFESTO-INTEGRIDADE.json';indexfile.write_text(json.dumps(index,ensure_ascii=False,indent=2)+'\n','utf-8')
bundle=out/'parques-mapa-QA-20261016.zip';assert not bundle.exists()
with zipfile.ZipFile(bundle,'w',zipfile.ZIP_DEFLATED,compresslevel=9)as z:
for n,p in files.items():assert '..'not in PurePosixPath(n).parts;z.write(p,n)
z.write(indexfile,'MANIFESTO-INTEGRIDADE.json')
with zipfile.ZipFile(bundle)as z:
assert z.testzip()is None and set(z.namelist())==set(files)|{'MANIFESTO-INTEGRIDADE.json'}
for n,p in files.items():assert hashlib.sha256(z.read(n)).hexdigest()==sha(p)
receipt={'at':proof['at'],'status':'read_only_planning_complete_no_implementation','documents':{p.name:{'sha256':sha(p),'bytes':p.stat().st_size}for p in review.iterdir()if p.is_file()and p.name!='RECIBO-INTEGRIDADE.json'},'package':{'name':bundle.name,'sha256':sha(bundle),'bytes':bundle.stat().st_size,'entries':len(files)+1,'CRC':'passed','all_entry_SHA256':'passed'},'verification':proof,'estimates':{'remaining_QA_hours':[19,29],'future_activation_hours':[2,4],'factual_data_completion':'not determined; does not block preparation with explicit unknowns'},'limits':['No current active database query or browser acceptance performed','Restored snapshot predates economic installation; execution clone must include that delta','Full operational parks sheet not closed','No official source provenance revalidation or current legal/operational claims','Menus, duplicates, Fintech, CAE discrepancy and prior closed deliveries retain states']}
(review/'RECIBO-INTEGRIDADE.json').write_text(json.dumps(receipt,ensure_ascii=False,indent=2)+'\n','utf-8');print(json.dumps({'package':receipt['package'],'documents':receipt['documents'],'receipt_sha256':sha(review/'RECIBO-INTEGRIDADE.json'),'application_files_unchanged':989}))