18 lines
2.0 KiB
Python
18 lines
2.0 KiB
Python
"""Existing host preference script, copied byte-for-byte into the disposable localhost document."""
|
|
from pathlib import Path
|
|
import json,re,hashlib
|
|
from playwright.sync_api import sync_playwright
|
|
source=Path('src/ZB.MOM.WW.ScadaBridge.Host/Components/App.razor').read_text();script=re.search(r'<script>.*?</script>',source,re.S).group()
|
|
fixture=Path('/Users/dohertj2/.codex/worktrees/scada-ui-consistency/scadaproj/components/ui-theme/validation/scadabridge-ui/host/Components/App.razor').read_text();results=[]
|
|
with sync_playwright() as p:
|
|
b=p.chromium.launch(channel='chromium')
|
|
for width in [1440,390]:
|
|
for mode,want in [('dark','dark'),('light','light'),('absent','light'),('blocked','light')]:
|
|
context=b.new_context(viewport={'width':width,'height':900});page=context.new_page()
|
|
if mode=='blocked':page.add_init_script("Object.defineProperty(window,'localStorage',{get(){throw new Error('synthetic blocked storage')}})")
|
|
elif mode!='absent':page.add_init_script("localStorage.setItem('sb-theme', '"+mode+"')")
|
|
page.add_init_script("document.addEventListener('DOMContentLoaded',()=>{requestAnimationFrame(()=>window.fixtureFirstFrameScheme=document.documentElement.dataset.bsTheme)})")
|
|
errors=[];page.on('pageerror',lambda e:errors.append(str(e)));page.goto('http://127.0.0.1:5201/overlays',wait_until='networkidle');record=page.evaluate('({scheme:document.documentElement.dataset.bsTheme,firstFrame:window.fixtureFirstFrameScheme})');record.update(width=width,mode=mode,errors=errors);record['passed']=record['scheme']==want and record['firstFrame']==want and not errors;results.append(record);context.close()
|
|
b.close()
|
|
Path('docs/ui-consistency/evidence/sb13-15/preference-startup.json').write_text(json.dumps({'hostScriptSha256':hashlib.sha256(script.encode()).hexdigest(),'fixtureCopiesExactExistingScript':script in fixture,'scope':'Existing script in disposable document, not a deployed full-host first-paint claim','cases':results},indent=2));print({'cases':len(results),'passed':sum(r['passed'] for r in results)})
|