Files
lmxopcua/infra/tools/ui-consistency/check_diagnostics.py
T

26 lines
2.8 KiB
Python

"""Native diagnostic disclosures over actual source components and synthetic data."""
import json,re,sys
from pathlib import Path
from playwright.sync_api import sync_playwright
sys.path.insert(0,'/Users/dohertj2/.codex/worktrees/scada-ui-consistency/scadaproj/components/ui-theme/validation/theme-1.0.0/canary')
from browser_zoom import zoom_browser,set_browser_zoom
origin=re.search(r'Now listening on: (http://127.0.0.1:\d+)',Path('/tmp/ot-pilot-host.log').read_text()).group(1)
out=Path('docs/ui-consistency/evidence/ot08-diagnostics');out.mkdir(parents=True,exist_ok=True)
results=[]
with sync_playwright() as p:
with zoom_browser(p) as (context,worker):
for sample in ['component','fleet','deployments','audit','log']:
for width,zoom in [(1440,1),(390,1),(1440,2)]:
page=context.new_page();page.set_viewport_size({'width':width,'height':1000});errors=[];page.on('pageerror',lambda e:errors.append(str(e)))
page.goto(origin+'/diagnostic-pilot?sample='+sample,wait_until='networkidle');set_browser_zoom(worker,page,zoom)
if sample=='log':page.locator('#publish-diagnostic').click()
detail=page.locator('details.diagnostic-details').first;detail.wait_for();summary=detail.locator('summary');summary.focus();page.keyboard.press('Enter');page.wait_for_function('document.querySelector("details.diagnostic-details").open')
payload=detail.get_by_role('region');page.keyboard.press('Tab');page.wait_for_function('document.querySelector("details.diagnostic-details[open] pre")===document.activeElement');[page.keyboard.press('ArrowDown',delay=30) for _ in range(12)];page.wait_for_function('document.querySelector("details.diagnostic-details[open] pre").scrollTop > 0')
data=payload.evaluate('e=>({text:e.textContent,focused:e===document.activeElement,height:e.clientHeight,scrollHeight:e.scrollHeight,top:e.scrollTop,scripts:e.querySelectorAll("script").length})')
layout=page.evaluate('({width:innerWidth,document:document.documentElement.scrollWidth,dpr:devicePixelRatio})')
result={'sample':sample,'width':width,'zoom':zoom,'nativeOpen':detail.get_attribute('open') is not None,'complete':len(data.pop('text'))>5000 and 'END-DIAGNOSTIC' in payload.inner_text(),'payload':data,'layout':layout,'errors':errors}
result['passed']=result['nativeOpen'] and result['complete'] and data['focused'] and data['scripts']==0 and data['height']<=data['scrollHeight'] and layout['document']==layout['width'] and not errors
results.append(result);page.screenshot(path=str(out/f'{sample}-{width}-zoom{zoom}.png'),full_page=False);page.close();(out/'confirmation-matrix.json').write_text(json.dumps(results,indent=2)+'\n')
print(json.dumps({'origin':origin,'cases':len(results),'passed':sum(r['passed'] for r in results),'failed':[r for r in results if not r['passed']]},indent=2))
raise SystemExit(0 if all(r['passed'] for r in results) else 1)