Files
Investidor-V2/tools/portal-country-https-active-result-verify.py
T
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

56 lines
4.2 KiB
Python

"""Verify precise audit updates, preserved sealed deliveries and the reverted active state."""
from pathlib import Path
from collections import Counter
from datetime import datetime,timezone
import csv,hashlib,json,zipfile
csv.field_size_limit(20_000_000)
ROOT=Path(__file__).resolve().parent.parent
DIR=ROOT/'storage/app/private/investmoz-v2/portal-audit'
DOC=ROOT/'docs/investmoz/v2/auditoria-portal'
OUT=ROOT/'outputs/investmoz-country02-https-activation-20261011'
read=lambda p:json.loads(Path(p).read_text(encoding='utf-8-sig'))
sha=lambda p:hashlib.sha256(Path(p).read_bytes()).hexdigest()
packet=read(DIR/'country-https-active-result-20261011/csv-edits.json')
verified=[]
for edit in packet['files']:
rows=list(csv.reader((DOC/edit['filename']).open(encoding='utf-8-sig',newline='')))
assert len(rows)==len(edit['rows'])
patched={p['row']:p['values'] for p in edit['patches']}
for i,row in enumerate(rows):
expected=list(edit['rows'][i])
for field,value in patched.get(i,{}).items():expected[rows[0].index(field)]=value
assert row==expected
if i>0:assert row[rows[0].index('Estado')]==edit['rows'][i][rows[0].index('Estado')]
assert {rows[i][rows[0].index('ID')] for i in patched}=={'AUD-COUNTRY-02','AUD-OPS-01'}
verified.append({'file':edit['filename'],'changed_requirements':2,'states_and_source_references_preserved':True,'sha256':sha(DOC/edit['filename'])})
rows=list(csv.DictReader((DOC/'matriz-requisitos.csv').open(encoding='utf-8-sig',newline='')))
assert len(rows)==len({r['ID'] for r in rows})==3393
assert sum(int(r['Quantidade de linhas de origem']) for r in rows)==6845
baseline=read(DIR/'country-c110-source-latest.json')
for name,digest in baseline['baseline_live_sources'].items():assert sha(ROOT/name)==digest,name
stage=read(DIR/'country-https-active-stage-latest.json')
for file,item in stage['backup_files'].items():assert sha(file)==item['sha256']
for directory in ['investmoz-country02-candidate-20261011','investmoz-country02-c110-20261011','investmoz-country02-https-20261011']:
path=ROOT/'outputs'/directory;sealed=read(path/'manifesto-pacote.json')
assert sha(path/sealed['archive'])==sealed['archive_sha256']
assert sha(path/'manifesto-candidata.json')==sealed['manifesto_candidata_sha256']
with zipfile.ZipFile(path/sealed['archive']) as archive:
assert len(archive.namelist())==sealed['archive_entries']
for name,digest in sealed['verified_members_sha256'].items():assert hashlib.sha256(archive.read(name)).hexdigest()==digest
state=read(DIR/'country-https-active-check-reverted-20261011.json')
assert state['result']=='passed' and state['country_enabled'] is False
assert state['changed_tables']==[] and state['installed_packages']==[] and state['columns']==[] and state['installation_audits']==0
assert state['counts_before']==state['counts_after'] and state['business_rows_preserved'] is True
assert state['tables']==288 and state['original_mfa_envelopes_recovered']==2
summary={'result':'passed','at':datetime.now(timezone.utc).isoformat(),'active_installation_performed':False,
'authorization':'13644ed74a48/162daff6ce08 + HTTPS + logout + only050000/COUNTRY02 remains valid',
'authenticated_preview_obtained':False,'active_SQL_changes':0,'original_active_sources_config_manifest_restored':True,
'new_immutable_assets_and_prepared_private_TLS_preserved':True,'sealed_deliveries_unchanged':True,
'backup_readonly_revalidated_at':'2026-10-11T08:03:24+00:00','active_final_readonly_verified_at':state['at'],
'requirements':3393,'source_occurrences':6845,'states':dict(Counter(r['Estado'] for r in rows)),
'AB_C37_and_other_requirement_states_preserved':True,'csv_edits':verified,
'master_write_not_demonstrated_active':'0 legitimate organizations and 0 memberships; no fixtures allowed',
'remaining':'Local CA trust, coordinated normal Laragon Apache reload after restaging, existing authorized manager login/MFA, exact authenticated preview, only050000, audit/flag/profile/logout/new-session proofs'}
(OUT/'verificacao-final.json').write_text(json.dumps(summary,ensure_ascii=False,indent=2),encoding='utf-8')
print(json.dumps(summary,ensure_ascii=False))