Files
lmxopcua/docs/ui-consistency/evidence/ot13-equipment-caller/check-boundaries.py
T

39 lines
4.1 KiB
Python

"""Equipment contract/source boundaries, supplementary to actual component and browser tests."""
import hashlib,json,re,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='b3f6001f3bf8fd0b2c177fb43f31e204638d0544'
page='src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/Uns/EquipmentPage.razor'
def old(path):return subprocess.check_output(['git','show',baseline+':'+path],cwd=root)
prior=old(page).decode();source=(root/page).read_text()
def method(text,marker):
a=text.index(marker);start=text.index('{',a);depth=1;i=start+1
while depth:
if text[i]=='{':depth+=1
elif text[i]=='}':depth-=1
i+=1
return text[a:i]
def payload(text):return re.sub(r'\s+','',re.search(r'new EquipmentInput\((.*?)\);',text,re.S).group(1).replace('_form.','form.'))
checks={
'formModelDefaultsAnnotationsExact':prior[prior.index(' private sealed class FormModel'):].strip()==source[source.index(' private sealed class FormModel'):].strip(),
'loadedDtoFormMapExact':method(prior,' private void LoadFormFrom(')==method(source,' private void LoadFormFrom('),
'all15PayloadFieldsOrderExact':payload(prior)==payload(source) and len(payload(source).split(','))==15,
'sameServiceApiSet':set(re.findall(r'Svc\.(\w+)\(',prior))==set(re.findall(r'Svc\.(\w+)\(',source)),
'sameRoutesQueryAndAuthorization':all(x in source for x in ['@page "/uns/equipment/new"','@page "/uns/equipment/{EquipmentId}"','@attribute [Authorize(Policy = AdminUiPolicies.ConfigEditor)]','[SupplyParameterFromQuery] public string? LineId','@rendermode RenderMode.InteractiveServer']),
'createRedirectPreserved':'Nav.NavigateTo($"/uns/equipment/{result.CreatedId}")' in source,
'rawPathAbbreviationFullTooltipPreserved':'title="@r.RawPath"' in source and '@DisplayText.Abbreviate(r.RawPath, 48)' in source,
'allThreeDestructiveIntentsStillConfirm':all(x in source for x in ['ConfirmRemoveReference(presentation, equipmentId, r)','ConfirmDeleteVirtualTag(presentation, equipmentId, v.VirtualTagId, v.Name)','ConfirmDeleteAlarm(presentation, equipmentId, a.ScriptedAlarmId, a.Name)']),
}
assert all(checks.values()),checks
files=[]
for path in ['src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Uns/EquipmentInput.cs','src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Uns/IUnsTreeService.cs','src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Uns/EquipmentChildRows.cs']:
data=(root/path).read_bytes();unchanged=old(path)==data;assert unchanged,path;files.append({'file':path,'sha256':hashlib.sha256(data).hexdigest(),'unchanged':unchanged})
test='tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/Pages/EquipmentCallerPresentationTests.cs'
wiring='tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/Uns/DeleteConfirmationWiringTests.cs'
result={'baseline':baseline,'page':page,'beforeSha256':hashlib.sha256(prior.encode()).hexdigest(),'afterSha256':hashlib.sha256(source.encode()).hexdigest(),'test':test,'testSha256':hashlib.sha256((root/test).read_bytes()).hexdigest(),'checks':checks,'unchangedContracts':files,'sharedWiring':{'path':wiring,'sha256':hashlib.sha256((root/wiring).read_bytes()).hexdigest(),'ownerCommit':'e411f89f6','note':'Root integrates Equipment first-method and gateway ScriptEdit third-method refinements; not part of this worker commit'},'fieldInventory':{'detailsEditable':15,'disabledSystemEquipmentId':1,'requiredOrParserErrorLinks':['Name','MachineCode','UnsLineId','YearOfConstruction'],'persistentExistingHints':['EquipmentId','Name','ZTag'],'referenceOverride':'unique per-row id +visible row/column composite name +persistent clear-override help +shared scoped error','childWrappers':['AddReferenceModal','VirtualTagModal','ScriptedAlarmModal'],'confirmation':'RawConfirmDialog outside every tab; captured operation and explicit page/confirmation Target'},'scope':'Source checks do not certify runtime; see actual TRX/browser/focus/busy evidence. VoiceOver explicitly excluded.'}
(root/'docs/ui-consistency/evidence/ot13-equipment-caller/source-boundaries.json').write_text(json.dumps(result,indent=2)+'\n')
print(json.dumps({'checks':len(checks),'unchangedContracts':len(files),'allPassed':True}))