63 lines
6.4 KiB
Python
63 lines
6.4 KiB
Python
"""Actual deployment-page feedback over a serial, fabricated memory-only fixture."""
|
|
import json,re,sys,uuid
|
|
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/ot09-deployments');out.mkdir(exist_ok=True)
|
|
results=[]
|
|
with sync_playwright() as p:
|
|
with zoom_browser(p) as (context,worker):
|
|
for sample in ['accept','nochanges','rejected','unknown','blocked','initial-error']:
|
|
for width,zoom in [(1440,1),(390,1),(1440,2),(390,2)]:
|
|
page=context.new_page();page.set_viewport_size({'width':width,'height':1000});errors=[];navigations=[]
|
|
page.on('pageerror',lambda e:errors.append(str(e)));page.on('framenavigated',lambda f:navigations.append(f.url) if f==page.main_frame else None)
|
|
page.goto(origin+'/deployment-pilot?sample='+sample+'&run='+uuid.uuid4().hex,wait_until='networkidle');set_browser_zoom(worker,page,zoom)
|
|
status=page.locator('section[aria-label="Deployment feedback"] [role=status]');status.wait_for()
|
|
for attempt in range(3):
|
|
page.locator('#fixture-observe').click()
|
|
try: page.locator('#fixture-interactive-state').filter(has_text='ready').wait_for(timeout=1500);break
|
|
except Exception:
|
|
if attempt==2:raise
|
|
checks={};metrics={}
|
|
def layout():return page.evaluate('({width:innerWidth,document:document.documentElement.scrollWidth,dpr:devicePixelRatio})')
|
|
if sample!='initial-error':
|
|
previous=page.locator('[data-testid=deployment-last-fetched]').get_attribute('datetime')
|
|
page.locator('[data-testid=deployment-refresh]').click()
|
|
page.wait_for_function('(before)=>document.querySelector("[data-testid=deployment-last-fetched]").getAttribute("datetime")!==before',arg=previous)
|
|
if sample=='initial-error':
|
|
checks['unavailableNotEmpty']='history is unavailable' in status.inner_text() and 'No deployment history' not in status.inner_text()
|
|
checks['requestDisabledUntilHistoryRead']=page.locator('[data-testid=deployment-request]').is_disabled()
|
|
page.locator('#fixture-restore-read').click();page.locator('[data-testid=deployment-refresh]').click();status.filter(has_text='No deployment history').wait_for()
|
|
checks['manualRecoveryToConfirmedEmpty']=not page.locator('[data-testid=deployment-request]').is_disabled()
|
|
else:
|
|
page.wait_for_function('!document.querySelector("[data-testid=deployment-request]").disabled')
|
|
page.locator('[data-testid=deployment-request]').dblclick()
|
|
expected={'accept':'Request accepted','nochanges':'No configuration changes','rejected':'Request rejected','unknown':'could not be confirmed','blocked':'This request was not started'}[sample]
|
|
status.filter(has_text=expected).wait_for()
|
|
checks['actualOutcomeVisible']=expected in status.inner_text()
|
|
page.locator('#fixture-observe').click();page.wait_for_function('document.querySelector("#fixture-request-count").textContent.trim()==="1"')
|
|
checks['doubleClickDispatchesOnce']=page.locator('#fixture-request-count').inner_text().strip()=='1'
|
|
if sample=='accept':
|
|
checks['acceptedNotCompleted']='in progress' in status.inner_text() and 'completed' not in status.inner_text()
|
|
metrics['acceptedLayout']=layout();checks['acceptedNoBodyOverflow']=metrics['acceptedLayout']['width']==metrics['acceptedLayout']['document']
|
|
checks['acceptedStatusNotClipped']=status.locator('.chip').evaluate_all('els=>els.every(e=>{const r=e.getBoundingClientRect(),p=e.closest("section").getBoundingClientRect();return r.left>=p.left&&r.right<=p.right;})')
|
|
status.scroll_into_view_if_needed();page.screenshot(path=str(out/f'accepted-{width}-zoom{zoom}.png'),full_page=False)
|
|
page.locator('#fixture-seal').click();checks['noUnrequestedPolling']='awaiting apply acknowledgements' in status.inner_text().lower()
|
|
page.locator('[data-testid=deployment-refresh]').click();status.filter(has_text='Sealed').wait_for()
|
|
checks['manualRefreshObservesSealed']=True
|
|
fetched=page.locator('[data-testid=deployment-last-fetched]').get_attribute('datetime')
|
|
page.locator('#fixture-fail-read').click();page.locator('[data-testid=deployment-refresh]').click();page.get_by_role('alert').filter(has_text='History refresh failed').wait_for()
|
|
checks['failedRefreshPreservesRowsAndTime']=page.locator('tbody tr').count()==1 and 'sealed' in status.inner_text().lower() and page.locator('[data-testid=deployment-last-fetched]').get_attribute('datetime')==fetched
|
|
page.locator('#fixture-restore-read').click();checks['restoreDoesNotFabricateARead']=page.get_by_role('alert').filter(has_text='History refresh failed').count()==1
|
|
page.locator('[data-testid=deployment-refresh]').click();page.get_by_role('alert').filter(has_text='History refresh failed').wait_for(state='detached');checks['explicitRetryClearsError']=True
|
|
elif sample=='nochanges':checks['noFalseRejection']='Request rejected' not in status.inner_text()
|
|
elif sample=='unknown':checks['noInventedVerdict']='Request accepted' not in status.inner_text() and 'Request rejected' not in status.inner_text()
|
|
metrics['finalLayout']=layout();checks['noBodyOverflow']=metrics['finalLayout']['width']==metrics['finalLayout']['document'];checks['noPageReload']=len(navigations)==1;checks['statusNotClipped']=status.locator('.chip').evaluate_all('els=>els.every(e=>{const r=e.getBoundingClientRect(),p=e.closest("section").getBoundingClientRect();return r.left>=p.left&&r.right<=p.right;})')
|
|
checks['perNodeLinkRetained']=page.get_by_role('link',name='View per-node application status').get_attribute('href')=='/fleet'
|
|
record={'sample':sample,'width':width,'zoom':zoom,'checks':checks,'metrics':metrics,'errors':errors};record['passed']=all(checks.values()) and not errors
|
|
results.append(record);status.scroll_into_view_if_needed();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)
|