"""Actual log/alert snapshots over fabricated local broadcaster events 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-tail-host.log').read_text()).group(1) out=Path('docs/ui-consistency/evidence/ot11-tails');out.mkdir(parents=True,exist_ok=True);results=[] with sync_playwright() as p: with zoom_browser(p) as (context,worker): for sample,capacity,latest in [('log',500,601),('alerts',200,251)]: 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+'/live-tail-pilot?sample='+sample,wait_until='networkidle');set_browser_zoom(worker,page,zoom) count=page.locator('[data-testid=tail-retained-count]');toggle=page.locator('[data-testid=tail-pause]');status=page.locator('[data-testid=tail-status]');checks={} page.locator('#fixture-emit-one').click();page.locator('tbody tr').filter(has_text='Local sample 1').wait_for();page.evaluate('window.frozenRow=document.querySelector("tbody tr")') toggle.focus();toggle.press('Enter');page.wait_for_function('document.querySelector("[data-testid=tail-pause]").getAttribute("aria-pressed")==="true"') page.locator('#fixture-emit-burst').click();page.wait_for_function('(n)=>document.querySelector("[data-testid=tail-retained-count]").textContent.trim()===String(n)',arg=capacity) checks['boundedRetainedWhilePaused']=count.inner_text().strip()==str(capacity);checks['sameFrozenRow']=page.evaluate('document.querySelector("tbody tr")===window.frozenRow') and page.locator('tbody tr').count()==1;checks['frozenPayload']='Local sample 1' in page.locator('tbody').inner_text() and f'Local sample {latest}' not in page.locator('tbody').inner_text() checks['payloadOutsideLiveRegion']='Local sample' not in status.inner_text() page.locator('#fixture-disconnect').click();status.filter(has_text='Disconnected').wait_for();checks['pauseSurvivesDisconnect']=toggle.get_attribute('aria-pressed')=='true' page.screenshot(path=str(out/f'{sample}-paused-{width}-zoom{zoom}.png'),full_page=False) toggle.focus();toggle.press('Enter');page.locator('tbody tr').filter(has_text=f'Local sample {latest}').wait_for();checks['resumeLatestBounded']=page.locator('tbody tr').count()==capacity and f'Local sample {latest}' in page.locator('tbody tr').first.inner_text() toggle.click();page.locator('[data-testid=tail-clear]').click();page.wait_for_function('document.querySelector("[data-testid=tail-retained-count]").textContent.trim()==="0"');checks['clearRetainsPause']=toggle.get_attribute('aria-pressed')=='true' and page.locator('tbody tr').count()==0 page.locator('#fixture-emit-one').click();page.wait_for_function('document.querySelector("[data-testid=tail-retained-count]").textContent.trim()==="1"');checks['clearDropsOldWindow']=page.locator('tbody tr').count()==0 toggle.click();page.locator('tbody tr').filter(has_text=f'Local sample {latest+1}').wait_for();checks['resumeAfterClear']=page.locator('tbody tr').count()==1 layout=page.evaluate('({width:innerWidth,document:document.documentElement.scrollWidth,dpr:devicePixelRatio})');checks['noBodyOverflow']=layout['width']==layout['document'];checks['noPageErrors']=not errors results.append({'sample':sample,'viewport':width,'zoom':zoom,'layout':layout,'checks':checks,'errors':errors,'passed':all(checks.values())});page.screenshot(path=str(out/f'{sample}-resumed-{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(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)