Files
lmxopcua/docs/ui-consistency/evidence/ot13-scripts-dialog/check-boundaries.py
T

28 lines
2.6 KiB
Python

"""Read-only Scripts dialog boundaries; supplemental to rendered behavior tests."""
import hashlib,json,subprocess
from pathlib import Path
root=Path(__file__).resolve().parent
while not list(root.glob('*.slnx')):
if root.parent==root:raise RuntimeError('Repository root not found')
root=root.parent
baseline='ea5bb6a0bc54844851b2ee6d0a165ebf53479c88';page='src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/Scripts.razor'
def old(path):return subprocess.check_output(['git','show',baseline+':'+path],cwd=root)
source=(root/page).read_text();prior=old(page).decode()
checks={
'listMarkupExact':prior.split('@* The dialog')[0]==source.replace('@implements IDisposable\n','').split('@* The dialog')[0],
'authorizationRouteRenderModeExact':all(x in source for x in ['@page "/scripts"','@attribute [Authorize(Policy = AdminUiPolicies.ConfigEditor)]','@rendermode RenderMode.InteractiveServer']),
'lazyProjectionAndReadCallsPreserved':all(source.count(x)==prior.count(x)==1 for x in ['ScriptListQueries.LoadRowsAsync(db)','ScriptListQueries.LoadSourceAsync(db, scriptId)']),
'currentErrorFormatPreserved':'$"The script source could not be loaded: {ex.Message}"' in source,
'sourceStillEncodedRazorText':'@_sourceCode</pre>' in source and 'MarkupString' not in source,
'readOnlyNoEntityMutation':not any(x in source for x in ['SaveChanges','AddAsync(','Remove(','Update(']),
'originalLargeScrollableGeometry':'DialogClass="modal-lg modal-dialog-scrollable"' in source,
'noInventedEditorOrFields':not any(x in source for x in ['<MonacoEditor','<input','<InputText','<textarea','<select']),
}
files=[]
for path in ['src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/ScriptList/ScriptListQueries.cs','src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Entities/Script.cs']:
payload=(root/path).read_bytes();same=old(path)==payload;assert same,path;files.append({'file':path,'sha256':hashlib.sha256(payload).hexdigest(),'unchangedFromBaseline':same})
assert all(checks.values()),checks
result={'baseline':baseline,'page':page,'beforeSha256':hashlib.sha256(prior.encode()).hexdigest(),'afterSha256':hashlib.sha256(source.encode()).hexdigest(),'checks':checks,'unchangedBoundaries':files,'fieldInventory':{'editableFields':0,'contextualHeader':1,'keyboardScrollableReadOnlySourceRegion':1,'safeFooterClose':1,'applicableHints':'No editable fields; loading/missing source have status, read failure has alert','outsideScope':'ScriptEdit create/edit/Monaco/build/delete routes are not this Source disclosure'}}
(root/'docs/ui-consistency/evidence/ot13-scripts-dialog/source-boundaries.json').write_text(json.dumps(result,indent=2)+'\n')
print(json.dumps({'checks':len(checks),'unchangedBoundaryFiles':len(files),'allPassed':True}))