"""Bounded actual DriverStatusPanel diagnostics; synthetic serial localhost adapter only.""" 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');results=[] with sync_playwright() as p: with zoom_browser(p) as (context,worker): for sample in ['read-error','last-error','operation']: 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+'/driver-diagnostic-pilot?sample='+sample,wait_until='networkidle');set_browser_zoom(worker,page,zoom) if sample=='operation':page.get_by_role('button',name='Reconnect',exact=True).click() if sample=='read-error':summary=page.locator('details.diagnostic-details summary').filter(has_text='Status read error').first elif sample=='last-error':summary=page.locator('details.diagnostic-details summary').filter(has_text='Last error').first else:summary=page.locator('details.diagnostic-details summary').filter(has_text='Operation details').first summary.wait_for();summary.focus();page.keyboard.press('Enter');detail=summary.locator('..');region=detail.get_by_role('region');page.keyboard.press('Tab');page.wait_for_function('(label)=>document.activeElement?.getAttribute("aria-label")===label',arg=region.get_attribute('aria-label'));[page.keyboard.press('ArrowDown',delay=30) for _ in range(12)];page.wait_for_function('(label)=>[...document.querySelectorAll("details.diagnostic-details[open] pre")].some(e=>e.getAttribute("aria-label")===label && e.scrollTop>0)',arg=region.get_attribute('aria-label')) data=region.evaluate('e=>({complete:e.textContent.includes("END-DIAGNOSTIC")&&e.textContent.length>5000,focused:e===document.activeElement,scripts:e.querySelectorAll("script").length,top:e.scrollTop,height:e.clientHeight,scroll:e.scrollHeight})') layout=page.evaluate('({width:innerWidth,document:document.documentElement.scrollWidth,dpr:devicePixelRatio})') result={'sample':sample,'width':width,'zoom':zoom,'data':data,'layout':layout,'errors':errors};result['passed']=data['complete'] and data['focused'] and data['scripts']==0 and data['top']>0 and layout['width']==layout['document'] and not errors results.append(result);page.screenshot(path=str(out/f'driver-{sample}-{width}-zoom{zoom}.png'),full_page=False);page.close();(out/'driver-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)