from pathlib import Path from datetime import datetime,timezone from urllib.parse import urlsplit import importlib.util,json,re,hashlib OUT=Path(__file__).resolve().parent;ROOT=OUT.parents[1];QA=ROOT/'storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742' dest=OUT/'option-B7-navigation-HTTP.json';assert not dest.exists() s=importlib.util.spec_from_file_location('transport',OUT/'consumer-lot-lib.py');lib=importlib.util.module_from_spec(s);s.loader.exec_module(lib) proof={'at':datetime.now(timezone.utc).isoformat(),'target':lib.TARGET,'active_writes':0,'browser_observed':False,'scope':'dashboard shared prop and production assets only; no repeated workflow','cases':[]} code=1;clients=[];step='profile-specific dashboard entry' try: for role in ['promoter','validator','publisher','outsider','multiple']: c=lib.Client().login(role);clients.append(c);p=c.call('GET','/dashboard',json_response=False) expected='/management/negocios' if role in ['validator','publisher'] else None assert p['businessReviewUrl']==expected and p['auth']['canManagePortal']is False if expected: page=c.call('GET',expected,json_response=False);assert page['management']is True proof['cases'].append({'actor_id':lib.actors[role]['id'],'role':role,'dashboard_HTTP':200,'business_review_url':p['businessReviewUrl'],'manage_portal':False, 'navigation_input':{'authenticated':True,'manager':False,'businesses':p['existingBusinessEnabled'],'businessReviewUrl':p['businessReviewUrl']}}) c.logout();clients.remove(c) step='anonymous entry and compiled assets' anon=lib.Client();p=anon.call('GET','/login',json_response=False);assert p['businessReviewUrl']is None status,headers,body=anon.request('GET','/login');assert status==200 manifest=json.loads((QA/'public/build/manifest.json').read_text(encoding='utf-8'));app=manifest['resources/js/app.tsx']['file'];path='/build/'+app assert path.encode()in body st,_,raw=anon.request('GET',path,check_target=False);assert st==200 assert hashlib.sha256(raw).hexdigest()==hashlib.sha256((QA/'public/build'/app).read_bytes()).hexdigest() absolute=[u.decode()for u in re.findall(rb'(?:src|href)="(https?://[^" ]+)"',body)] assert all(urlsplit(u).scheme=='https'for u in absolute) proof.update(result='passed',anonymous_business_review_url=None,production_app_asset={'path':path,'HTTP':st,'sha256':hashlib.sha256(raw).hexdigest()}, absolute_asset_urls_HTTPS=True,navigation_visible_clicks_or_focus_observed=False) code=0 except Exception as e:proof.update(result='stopped',step=step,error_type=type(e).__name__) finally: for c in clients: try:c.logout() except Exception:pass proof['requests']=lib.events;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)