Files
Investidor-V2/outputs/investmoz-audit-current-20261012/option-B8-map-v2-HTTP.py
T
nala ba1c0340ea
tests / ci (push) Canceled after 0s
oportunidades 8
2026-10-14 08:25:30 +02:00

27 lines
4.9 KiB
Python

from pathlib import Path
from datetime import datetime,timezone
import importlib.util,json,uuid,copy,sys,subprocess,hashlib
OUT=Path(__file__).resolve().parent;phase=sys.argv[1];spec=importlib.util.spec_from_file_location('transport',OUT/'option-B8-transport.py');lib=importlib.util.module_from_spec(spec);spec.loader.exec_module(lib)
progress=OUT/'option-B8-map-v2-progress.json';s=json.loads(progress.read_text(encoding='utf-8'))if progress.exists()else{};clients=[];proof={'at':datetime.now(timezone.utc).isoformat(),'target':lib.TARGET,'phase':phase,'active_writes':0,'browser_observed':False};code=1;stage='login'
def save():progress.write_text(json.dumps(s,ensure_ascii=False,indent=2)+'\n',encoding='utf-8')
def view(c):return c.call('GET','/minhas-oportunidades/32/view',json_response=False)
def act(c,action,expected=200,**extra):return c.call('POST','/minhas-oportunidades/32/workflow',{'etag':view(c)['etag'],'action':action,'reason':'SIMULAÇÃO QA B8: esboço espacial próprio v2, preservando exemplar textual e revisões não afetadas',**extra},expected=expected)
try:
c=lib.Client().login('promoter');clients.append(c)
if phase=='upload':
assert not s;x=view(c);assert x['workflowState']=='published';s={'baseline':x['values']['canonical'],'reviews':x['profileContext']['reviews']};save();act(c,'request_revision');fixture=json.loads((OUT/'option-B8-map-v2-fixture.json').read_text(encoding='utf-8'));r=c.call('POST','/minhas-oportunidades/32/resources/documents',{'etag':view(c)['etag'],'creation_key':str(uuid.uuid4()),'reason':'SIMULAÇÃO QA B8: esboço v2 com coordenadas e área, sem atribuir parcela ou direito real','payload':json.dumps({'title':'SIMULAÇÃO QA32 - esboço espacial v2','classification':'restricted','visibility':'internal','category':'qa-synthetic'})},expected=201,file=fixture['path']);row=next(x for x in c.call('GET','/minhas-oportunidades/32/resources',json_response=False)['resources']['documents']if x['id']==r['id']);s.update(resource_id=r['id'],document_id=row['document_id'],sha256=fixture['sha256']);save();proof.update(result='awaiting_own_scan',resource_id=r['id'],previous_v1_preserved=True);code=0
else:
x=view(c);canonical=copy.deepcopy(x['values']['canonical']);old=canonical['land_rights']['community_consultation']['map_document_id'];canonical['land_rights']['community_consultation']['map_document_id']=s['resource_id'];canonical['documents'].append(s['resource_id']);c.call('PUT','/minhas-oportunidades/32/draft',{'etag':x['etag'],'canonical':canonical,'reason':'SIMULAÇÃO QA B8: ligar esboço v2; preservar mapa textualv1, ata, titular, área e restante contrato'});act(c,'submit');x=view(c);mat=x['profileContext']['materiality'];assert mat['reopened']==['community_environment_review']
for gate in mat['retained']:assert all(x['profileContext']['reviews'][gate][k]==s['reviews'][gate][k]for k in ['hash','actor_id','at'])
v=lib.Client().login('validator');clients.append(v);act(v,'start_review');act(v,'review_gate',gate='community_environment_review',gate_decision='approved',evidence_document_ids=[s['resource_id'],canonical['land_rights']['community_consultation']['minutes_document_id']]);act(v,'approve');p=lib.Client().login('publisher');clients.append(p);act(p,'publish',confirm_publication=True,preview_hash=view(p)['profileContext']['approval']['hash'])
c.logout();clients.remove(c);c=lib.Client().login('promoter');clients.append(c);x=view(c);assert x['workflowState']=='published'and x['values']['canonical']==canonical and old in canonical['documents'];status,h,raw=c.request('GET',f'/minhas-oportunidades/32/resources/documents/{s["resource_id"]}/download');assert status==200 and hashlib.sha256(raw).hexdigest()==s['sha256'];c.call('GET','/minhas-oportunidades/32/response')
main=OUT/'option-B8-documents-32-progress.json';data=json.loads(main.read_text(encoding='utf-8'));data['canonical']=canonical;data['resources']['land-map-v2']={'resource_id':s['resource_id'],'document_id':s['document_id'],'sha256':s['sha256'],'fixture':json.loads((OUT/'option-B8-map-v2-fixture.json').read_text(encoding='utf-8'))['path']};main.write_text(json.dumps(data,ensure_ascii=False,indent=2)+'\n',encoding='utf-8');save()
proof.update(result='passed',reopened=mat['reopened'],retained=mat['retained'],retained_hash_actor_time_preserved=True,previous_map_v1_still_linked=True,approval_actor=24,publication_actor=25,visibility='internal',new_session_recovers_map_reference_and_bytes=True,area_12001_74_and_other_contract_fields_preserved=True);code=0
except Exception as e:proof.update(result='stopped',stage=stage,error_type=type(e).__name__)
finally:
for c in clients:
try:c.logout()
except Exception:pass
proof['requests']=lib.events;dest=OUT/f'option-B8-map-v2-{phase}-HTTP.json';assert not dest.exists();dest.write_text(json.dumps(proof,ensure_ascii=False,indent=2)+'\n',encoding='utf-8');print(json.dumps({k:v for k,v in proof.items()if k!='requests'},ensure_ascii=False))
raise SystemExit(code)