Files
Investidor-V2/outputs/investmoz-documentos-publicos-QA-20261018/finish.py
T
nala cf003c8623
tests / ci (push) Canceled after 0s
versao nrgocios 4
2026-10-18 15:57:06 +02:00

51 lines
5.8 KiB
Python

from pathlib import Path
import hashlib,json,zipfile,subprocess,re,urllib.request
root=Path.cwd();out=Path(__file__).resolve().parent;qa=Path('C:/Users/macbook/.config/investmoz/documentos-publicos-QA-20261018/source');review=out/'para-revisao';review.mkdir(exist_ok=True);sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
base=json.loads((out/'ATIVO-ANTES.json').read_text('utf-8'))
for n,h in {**base['files'],**base['protected']}.items():assert sha(root/n)==h,n
paths=['app/Http/Controllers/PortalServicesController.php','app/Services/PublicDocumentPresentation.php','resources/js/pages/portal/services.tsx','resources/js/pages/portal/document.tsx','resources/js/components/simulation-form.tsx','resources/js/components/journey-document-resources.tsx','resources/js/components/public-document-content.tsx']
changes=[{'path':n,'before_sha256':base['files'].get(n),'after_sha256':sha(qa/n),'operation':'replace' if n in base['files'] else 'new'} for n in paths]
for folder in ['app','config','routes','database','resources']:
for p in (qa/folder).rglob('*'):
if p.is_file():
n=p.relative_to(qa).as_posix()
# Wayfinder's route/action adapters are derived build inputs, never deployed as source changes.
if n not in paths and not n.startswith(('resources/js/actions/','resources/js/routes/')):assert sha(p)==base['files'].get(n),n
build=[{'path':p.relative_to(qa).as_posix(),'sha256':sha(p)} for p in sorted((qa/'public/build').rglob('*')) if p.is_file()]
fingerprint={s['path']:s['after_sha256'] for s in changes}|{s['path']:s['sha256'] for s in build};revision=hashlib.sha256(json.dumps(fingerprint,sort_keys=True,separators=(',',':')).encode()).hexdigest();candidate='documentos-publicos-QA-'+revision[:12]
before=json.loads((out/'ESTADO-ANTES.json').read_text('utf-16'));after=json.loads((out/'ESTADO-DEPOIS.json').read_text('utf-16'));assert before['tables']==after['tables']
proof=json.loads((out/'PROVAS-HTTP-QA.json').read_text('utf-8'));assert all(c['result']=='observado' for c in proof['checks'])
private=json.loads((out/'PROVAS-ACESSO-PRIVADO-QA.json').read_text('utf-8'));assert all(c['result']=='observado' for c in private['checks'])
# Manager's full original action is byte-identical, including relation/evidence/history retrieval.
old=(root/paths[0]).read_text('utf-8');new=(qa/paths[0]).read_text('utf-8');a=lambda s:s[s.index(' public function manage('):s.index(' public function upload(')]
assert a(old)==a(new)
extra=[]
for path in ['/documentos?page=2','/como-investir','/simulador-fiscal','/Simulador']:
with urllib.request.urlopen('http://127.0.0.1:18546'+path,timeout=40) as r:body=r.read().decode('utf-8');assert r.status==200 and r.headers.get('X-QA-Target')=='public_documents_20261018_test:55441'
props=json.loads(re.search(r'<script[^>]*data-page="app"[^>]*>(.*?)</script>',body,re.S).group(1))['props']
if 'resources' in props:
for row in props['resources']['data']:assert not any(k in row for k in ['links','source_reference','documentary_evidence','document_id'])
extra.append({'path':path,'status':200,'scope':'consumer loads only; no form filled/saved/submitted'})
checks={'candidate':candidate,'target':'public_documents_20261018_test:55441','tables_preserved':after['tables'],'management_action_byte_identical':True,'source_changes':len(changes),'new_sources':2,'active_runtime_and_protected_files_unchanged':len(base['files'])+len(base['protected']),'additional_consumers':extra,'accepted_journeys_repeated':False,'migrations':[]}
(out/'PRESERVACAO-FINAL.json').write_text(json.dumps(checks,ensure_ascii=False,indent=2),'utf-8')
manifest={'candidate':candidate,'revision_sha256':revision,'revision_algorithm':'sha256 canonical sorted compact JSON of path->sha256 for listed sources/build','sources':changes,'build':build,'migrations':[],'data_writes':False,'active_unchanged':True,'QA_only':True,'affected_screens':['/legislacao','/documentos','/documentos/{id}','/simulador-fiscal and /Simulador document recommendations','/como-investir (shared guide wording only)'],'public_api':['Inertia props on lists/details','/api/v1/documents/recommendations'],'management_preserved':'/management/portal-services'}
(review/'MANIFESTO-QA.json').write_text(json.dumps(manifest,ensure_ascii=False,indent=2),'utf-8')
with zipfile.ZipFile(review/(candidate+'.zip'),'w',zipfile.ZIP_DEFLATED)as z:
for n in paths+[s['path'] for s in build]:z.write(qa/n,'candidate/'+n)
z.write(review/'MANIFESTO-QA.json','MANIFESTO-QA.json')
rollback=[]
with zipfile.ZipFile(review/(candidate+'-reversao.zip'),'w',zipfile.ZIP_DEFLATED)as z:
for s in changes:
if s['before_sha256'] is not None:z.write(root/s['path'],'previous/'+s['path'])
rollback.append({'path':s['path'],'operation':'replace' if s['before_sha256'] else 'remove','sha256':s['before_sha256'],'remove_only_if_sha256':None if s['before_sha256'] else s['after_sha256']})
for p in (root/'public/build').rglob('*'):
if p.is_file():z.write(p,'previous/'+p.relative_to(root).as_posix())
z.writestr('MANIFESTO-REVERSAO.json',json.dumps({'sources':rollback,'data_restore':False,'warning':'Restoring previous public presentation re-exposes internal metadata. Separate operational decision required.'},indent=2))
archives=[]
for p in review.glob('*.zip'):
with zipfile.ZipFile(p)as z:assert z.testzip() is None
archives.append({'file':p.name,'sha256':sha(p),'bytes':p.stat().st_size,'CRC':'passed'})
(review/'PACOTES-VERIFICADOS.json').write_text(json.dumps({'candidate':candidate,'archives':archives},indent=2),'utf-8')
for n in ['PROVAS-HTTP-QA.json','PROVAS-ACESSO-PRIVADO-QA.json','PRESERVACAO-FINAL.json','QA-ISOLAMENTO.json']:(review/n).write_bytes((out/n).read_bytes())
print(json.dumps({'candidate':candidate,'revision':revision,'sources':len(changes),'build_files':len(build),'http_checks':len(proof['checks']),'private_checks':len(private['checks']),'additional_consumers':len(extra),'active_unchanged':True}))