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

36 lines
3.6 KiB
Python

"""Bounded real-component tree recovery/filter checks on synthetic root reads 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/ot10-trees');out.mkdir(parents=True,exist_ok=True);results=[]
with sync_playwright() as p:
with zoom_browser(p) as (context,worker):
for sample in ['raw','uns']:
for width,zoom in [(1440,1),(390,1),(1440,2),(390,2)]:
page=context.new_page();page.set_viewport_size({'width':width,'height':2800 if zoom==2 else 1100});errors=[];page.on('pageerror',lambda e:errors.append(str(e)))
page.goto(origin+'/tree-recovery-pilot?sample='+sample,wait_until='networkidle');set_browser_zoom(worker,page,zoom)
page.get_by_role('alert').filter(has_text='could not be loaded').wait_for();checks={}
checks['failureNotEmpty']=page.get_by_text('No clusters yet.',exact=True).count()==0
summary=page.get_by_text('Raw loading details' if sample=='raw' else 'UNS loading details',exact=True)
details=summary.locator('..')
details.locator('summary').click();checks['fullEscapedDiagnostic']='ignored()' in details.inner_text() and details.locator('script').count()==0
page.locator('[data-testid=tree-retry]').click()
page.wait_for_function('document.activeElement?.dataset.testid==="tree-retry"')
checks['failedRetryReturnsFocus']=True
page.locator('#fixture-recover-tree').click();page.locator('[data-testid=tree-retry]').click()
if sample=='raw':page.get_by_text('No clusters yet.',exact=True).wait_for();checks['recoveryConfirmedEmpty']=True
else:
field=page.get_by_role('textbox',name='Filter loaded UNS names');field.wait_for();page.get_by_text('Synthetic press',exact=True).wait_for()
hint=field.get_attribute('aria-describedby');checks['scopeHintLinked']='Unloaded tag contents are not searched' in page.locator('#'+hint).text_content()
field.fill('unloaded-tag');page.get_by_role('status').filter(has_text='No loaded names match').wait_for();checks['noMatchExplicit']=True
page.get_by_role('button',name='Clear filter',exact=True).click();page.wait_for_function('(id)=>{const e=document.getElementById(id);return e.value==="" && document.activeElement===e;}',arg=field.get_attribute("id"));checks['clearFocusReturned']=field.evaluate('(e)=>e===document.activeElement');checks['clearRestoresLoadedNodes']=page.get_by_text('Synthetic press',exact=True).count()==1 and field.input_value()==''
page.locator('#fixture-observe-tree').click();counts=page.locator('#fixture-tree-count').inner_text();checks['noLazyOrMutationCalls']=counts.split('/')[-1].strip()=='0'
layout=page.evaluate('({width:innerWidth,document:document.documentElement.scrollWidth,dpr:devicePixelRatio})');checks['noBodyOverflow']=layout['width']==layout['document'];checks['noPageErrors']=not errors
result={'sample':sample,'viewport':width,'zoom':zoom,'layout':layout,'counts':counts,'checks':checks,'errors':errors,'passed':all(checks.values())};results.append(result)
page.screenshot(path=str(out/f'{sample}-{width}-zoom{zoom}.png'),full_page=False);page.close();(out/'matrix.json').write_text(json.dumps(results,indent=2)+'\n')
print(json.dumps({'origin':origin,'cases':len(results),'passed':sum(x['passed'] for x in results),'failed':[x for x in results if not x['passed']]},indent=2))
raise SystemExit(0 if all(x['passed'] for x in results) else 1)