"""Focused packaged-asset and interaction acceptance; no new visual polish round.""" import argparse import hashlib import json from pathlib import Path from urllib.parse import urlsplit from zipfile import ZipFile from playwright.sync_api import sync_playwright, expect parser = argparse.ArgumentParser() parser.add_argument('--perpage', required=True) parser.add_argument('--bootstrap', required=True) parser.add_argument('--out', required=True, type=Path) parser.add_argument('--theme-cache', type=Path, default=Path('/tmp/scada-secrets-ui100-host-packages')) args = parser.parse_args() root = Path(__file__).resolve().parents[4] record = json.loads((Path(__file__).parent/'SEC07-artifacts.json').read_text()) ui = next(a for a in record['artifacts'] if a['id'].endswith('.Ui')) with ZipFile(ui['path']) as package: assets = {'Secrets.Ui/js/'+n:package.read('staticwebassets/js/'+n) for n in ['secrets-dialog.js','secrets-reveal.js']} theme_root = args.theme_cache/'zb.mom.ww.theme/1.0.1' assert hashlib.sha256((theme_root/'zb.mom.ww.theme.1.0.1.nupkg').read_bytes()).hexdigest() == '995b117b0245577598c91404ed7957c071ebe3413696c8be48b419c9deb1bd5d' for n in ['css/theme.css','css/layout.css','fonts/ibm-plex-sans-400.woff2','fonts/ibm-plex-sans-600.woff2','fonts/ibm-plex-mono-500.woff2']: assets['Theme/'+n]=(theme_root/'staticwebassets'/n).read_bytes() results = {'sourceRevision':record['sourceRevision'],'uiSha256':ui['sha256'],'hosts':[]} with sync_playwright() as p: browser=p.chromium.launch(channel='chromium',headless=True) try: for mode,origin in [('perpage',args.perpage),('bootstrap',args.bootstrap)]: assert urlsplit(origin).hostname in {'127.0.0.1','localhost','::1'} page=browser.new_page(viewport={'width':1440,'height':1000}) page.set_default_timeout(7000) row={'mode':mode,'origin':origin,'checks':[],'errors':[],'assetHashes':{}} page.on('pageerror',lambda e:row['errors'].append(str(e))) def check(name,passed): row['checks'].append({'name':name,'passed':bool(passed)}) assert passed,name def faults(**settings): assert page.request.post(origin+'/fixture/faults',data=settings).status==204 try: provenance=page.request.get(origin+'/fixture/provenance').json() check('Packaged UI and shared Theme identities',provenance['ui']=='1.0.0.0' and provenance['theme']=='1.0.1.0' and provenance['purpose'].startswith('Loopback synthetic Secrets UI')) for name,data in assets.items(): response=page.request.get(origin+'/_content/ZB.MOM.WW.'+name) check('Exact packaged asset '+name,response.status==200 and response.body()==data) row['assetHashes'][name]=hashlib.sha256(response.body()).hexdigest() response=page.goto(origin+'/admin/secrets') expect(page.locator('[data-fixture-ready=true]')).to_be_visible() check('One working wrapped route',response.status==200 and page.get_by_test_id('add-secret').count()==1) search=page.get_by_test_id('secret-filter');search.fill('APP/ALPHA') expect(page.locator('tr[data-secret-row]')).to_have_count(1) page.get_by_test_id('clear-secret-filter').click() expect(page.locator('tr[data-secret-row]')).to_have_count(3) check('Packaged metadata filter clears',True) page.get_by_test_id('add-secret').click() expect(page.get_by_test_id('secret-name')).to_be_visible() controls=page.locator('.tech-field input,.tech-field select').evaluate_all("ns=>ns.filter(n=>n.dataset.testid!=='secret-filter').map(n=>({id:n.id,labels:n.labels.length}))") check('Packaged field associations',len(controls)==4 and len({n['id'] for n in controls})==4 and all(n['id'] and n['labels']==1 for n in controls)) page.get_by_test_id('secret-name').fill('../invalid') page.get_by_test_id('secret-value').fill('synthetic candidate value') page.get_by_test_id('editor-submit').click() expect(page.get_by_test_id('secret-name')).to_have_attribute('aria-invalid','true') page.wait_for_function("()=>document.activeElement?.dataset.testid==='secret-name'") check('Packaged invalid-field focus',True) page.get_by_test_id('editor-cancel').click() page.locator('.rotate-secret[data-secret-name="app/alpha"]').click() page.get_by_test_id('secret-value').fill('draft belonging to alpha') page.locator('.rotate-secret[data-secret-name="app/bravo"]').click() expect(page.get_by_test_id('secret-value')).to_have_value('') check('Packaged target isolation',True) page.get_by_test_id('editor-cancel').click() target=page.locator('tr[data-secret-row="app/alpha"]') target.get_by_test_id('reveal-button').click() expect(target.get_by_test_id('revealed-value')).to_have_text('synthetic-fixture-value') check('Non-sensitive packaged reveal outcome','synthetic-fixture-value' not in target.get_by_test_id('reveal-status').inner_text()) target.get_by_test_id('hide-button').click() expect(page.get_by_test_id('revealed-value')).to_have_count(0) faults(audit=True) target.get_by_test_id('reveal-button').click() expect(target.get_by_test_id('reveal-error')).to_be_visible() check('Packaged audit failure withholds disclosure',page.get_by_test_id('revealed-value').count()==0 and 'synthetic-fixture-value' not in page.content()) target.get_by_test_id('hide-button').click() faults() page.get_by_test_id('add-secret').click() page.get_by_test_id('secret-name').fill('package/new') page.get_by_test_id('secret-value').fill('synthetic candidate value') faults(audit=True,list=True) page.get_by_test_id('editor-submit').click() expect(page.get_by_test_id('list-error')).to_be_visible() check('Packaged committed outcome survives audit/refresh failure','Change saved; list refresh failed' in page.get_by_test_id('list-error').inner_text()) before=page.request.get(origin+'/fixture/counts').json() faults();page.get_by_test_id('list-retry').click() expect(page.get_by_test_id('list-error')).to_have_count(0) after=page.request.get(origin+'/fixture/counts').json() check('Packaged Retry does not replay mutation',before['upserts']==1 and after['upserts']==1 and after['lists']>before['lists']) page.locator('.delete-secret[data-secret-name="package/new"]').click() expect(page.locator('dialog:modal')).to_be_visible() page.wait_for_function("()=>document.activeElement?.dataset.testid==='cancel-delete'") page.keyboard.press('Tab') check('Packaged dialog keyboard containment',page.get_by_test_id('confirm-delete').evaluate('n=>document.activeElement===n')) page.keyboard.press('Escape') expect(page.locator('dialog')).to_have_count(0) check('Packaged native lifecycle cleanup',page.evaluate("()=>document.body.style.overflow!=='hidden'") and page.request.get(origin+'/fixture/counts').json()['deletes']==0) page.goto(origin+'/admin/secrets?role=manage') expect(page.locator('[data-fixture-ready=true]')).to_be_visible() check('Packaged manage does not imply reveal',page.get_by_test_id('reveal-button').count()==0) check('Packaged denied route',page.request.get(origin+'/admin/secrets?role=denied').status==403) check('No packaged page errors',not row['errors']) except Exception as error: row['failure']=str(error) finally: faults();page.close() results['hosts'].append(row) finally:browser.close() args.out.write_text(json.dumps(results,indent=2)+'\n') failed=[h.get('failure') for h in results['hosts'] if h.get('failure')] print(json.dumps({'checks':sum(len(h['checks']) for h in results['hosts']),'failed':failed,'modes':len(results['hosts'])})) raise SystemExit(1 if failed else 0)