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

15 lines
1.8 KiB
Python

"""Compare loopback-served package/CSS/font/JS bytes with accepted artifact/source bytes."""
import re,json,hashlib,zipfile,urllib.request
from pathlib import Path
origin=re.search(r'Now listening on: (http://127.0.0.1:\d+)',Path('/tmp/ot14-final-host.log').read_text()).group(1)
pkg=Path('/tmp/ot-ui101-official-packages/zb.mom.ww.theme/1.0.1/zb.mom.ww.theme.1.0.1.nupkg');expected='995b117b0245577598c91404ed7957c071ebe3413696c8be48b419c9deb1bd5d';results=[]
def check(url,content):
actual=urllib.request.urlopen(origin+url,timeout=10).read();results.append({'url':url,'expectedSha256':hashlib.sha256(content).hexdigest(),'servedSha256':hashlib.sha256(actual).hexdigest(),'equal':actual==content})
with zipfile.ZipFile(pkg) as z:
for name in z.namelist():
if name.startswith('staticwebassets/') and (name.endswith('.woff2') or name in ['staticwebassets/css/theme.css','staticwebassets/css/layout.css']):check('/_content/ZB.MOM.WW.Theme/'+name.removeprefix('staticwebassets/'),z.read(name))
for path in ['css/site.css','js/dialog-focus.js','js/monaco-init.js','js/tree-layout.js']:
check('/_content/ZB.MOM.WW.OtOpcUa.AdminUI/'+path,(Path('src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/wwwroot')/path).read_bytes())
x={'origin':origin,'acceptedThemeNupkgSha256':expected,'actualThemeNupkgSha256':hashlib.sha256(pkg.read_bytes()).hexdigest(),'checks':results,'scope':'Actual current owned loopback host. CSS/fonts match exact accepted1.0.1 nupkg; appCSS/JS match final sources. No production routing/auth/backend claim.'}
Path('docs/ui-consistency/evidence/ot14-final/served-assets.json').write_text(json.dumps(x,indent=2)+'\n');print({'checks':len(results),'passed':sum(r['equal'] for r in results),'packageEqual':x['actualThemeNupkgSha256']==expected});assert all(r['equal'] for r in results) and x['actualThemeNupkgSha256']==expected