@@ -0,0 +1,58 @@
|
||||
"""Bind existing normative field IDs to actual QA response paths, without storing contents."""
|
||||
from pathlib import Path
|
||||
import sys,json,time,csv,hashlib,collections
|
||||
csv.field_size_limit(10000000)
|
||||
sys.argv=['audit-http.py','promoter'];OUT=Path(__file__).resolve().parent;ROOT=OUT.parents[1]
|
||||
ns={'__file__':str(OUT/'audit-http.py')}
|
||||
exec((OUT/'audit-http.py').read_text(encoding='utf-8-sig').split("proof={'at':")[0],ns)
|
||||
schema_path=ROOT/'resources/data/investmoz-opportunity-modular.schema.json';schema=json.loads(schema_path.read_text(encoding='utf-8-sig'));defs=schema['$defs']
|
||||
paths=collections.defaultdict(list)
|
||||
def walk(node,path=(),seen=()):
|
||||
if not isinstance(node,dict):return
|
||||
ref=node.get('$ref')
|
||||
if ref and ref.startswith('#/$defs/'):
|
||||
name=ref.split('/')[-1]
|
||||
if path not in paths[name]:paths[name].append(path)
|
||||
if name not in seen:walk(defs[name],path,seen+(name,))
|
||||
for key,value in node.get('properties',{}).items():walk(value,path+(key,),seen)
|
||||
if isinstance(node.get('items'),dict):walk(node['items'],path+('[]',),seen)
|
||||
for kind in ['allOf','anyOf','oneOf']:
|
||||
for value in node.get(kind,[]):walk(value,path,seen)
|
||||
walk({'$ref':'#/$defs/opportunity'})
|
||||
def at(data,path):
|
||||
if not path:return [data]
|
||||
part,*tail=path
|
||||
if part=='[]':return [y for x in (data if isinstance(data,list) else []) for y in at(x,tail)]
|
||||
if not isinstance(data,dict) or part not in data:return []
|
||||
return at(data[part],tail)
|
||||
proof={'target':ns['TARGET'],'base':ns['BASE'],'active_writes':0,'business_data_writes':0,'browser_observed':False,'schema_sha256':hashlib.sha256(schema_path.read_bytes()).hexdigest(),'fields':[],'records':[],'values_or_secrets_recorded':False}
|
||||
try:
|
||||
s=ns['Session']();status,_,body=s.request('GET','/_qa/runtime',check_target=False);assert status==200 and json.loads(body)['target']['database']=='stability_consumers_20261011_084534_test'
|
||||
a=ns['actors']['promoter'];assert s.request('GET','/login')[0]==200
|
||||
assert s.request('POST','/login',{'email':a['email'],'password':a['password']},'application/json')[0] in [200,204,302]
|
||||
assert s.request('GET','/two-factor-challenge')[0]==200
|
||||
if time.time()%30>26:time.sleep(4)
|
||||
assert s.request('POST','/two-factor-challenge',{'code':ns['otp'](a.get('totp_secret',a.get('secret')))},'application/json')[0] in [200,204,302]
|
||||
documents=[]
|
||||
for rid in [30,31,32,33,34,35,54]:
|
||||
status,_,body=s.request('GET',f'/minhas-oportunidades/{rid}/response',accept='application/json');assert status==200
|
||||
data=json.loads(body);assert data['compatibility']['normative_response_complete'] is False
|
||||
documents.append((rid,data['data']));proof['records'].append({'id':rid,'status':status,'normative_response_complete':False})
|
||||
rows=list(csv.DictReader((ROOT/'docs/investmoz/v2/auditoria-portal/matriz-requisitos.csv').open(encoding='utf-8-sig',newline='')))
|
||||
for row in rows:
|
||||
if not row['ID'].startswith('OP-FIELD-'):continue
|
||||
group,field=row['ID'][len('OP-FIELD-'):].split('-',1);member=defs.get(group,{}).get('properties',{}).get(field)
|
||||
matches=[]
|
||||
for path in paths.get(group,[]):
|
||||
for rid,data in documents:
|
||||
for value in at(data,path):
|
||||
if isinstance(value,dict) and field in value:
|
||||
v=value[field];matches.append({'record_id':rid,'path':'.'.join(path+(field,)),'returned_type':'null' if v is None else ('boolean' if isinstance(v,bool) else 'array' if isinstance(v,list) else 'object' if isinstance(v,dict) else 'number' if isinstance(v,(int,float)) else 'string')})
|
||||
proof['fields'].append({'ID':row['ID'],'schema_definition':group,'schema_property':field,'present_in_normative_schema':member is not None,'mapped_response_paths':['.'.join(x) for x in paths.get(group,[])],'response_matches':matches,'scope':'Read key/type from existing persisted QA examples; does not demonstrate Create/Patch, all validation branches, UI or normative compatibility.'})
|
||||
assert s.request('POST','/logout',{},'application/json')[0] in [200,204,302]
|
||||
proof['result']='passed';proof['summary']={'fields':len(proof['fields']),'schema_members':sum(x['present_in_normative_schema'] for x in proof['fields']),'returned_fields':sum(bool(x['response_matches']) for x in proof['fields'])}
|
||||
except Exception as error:proof.update(result='stopped',error_type=type(error).__name__)
|
||||
finally:
|
||||
(OUT/'response-field-coverage-http.json').write_text(json.dumps(proof,ensure_ascii=False,indent=2),encoding='utf-8')
|
||||
print(json.dumps({k:proof[k] for k in ['result','summary','active_writes','browser_observed'] if k in proof},ensure_ascii=True))
|
||||
sys.exit(0 if proof['result']=='passed' else 1)
|
||||
Reference in New Issue
Block a user