47 lines
2.3 KiB
Python
47 lines
2.3 KiB
Python
"""Severity-aware native diagnostics: errors block; explicit warnings are retained."""
|
|
import json
|
|
|
|
VALIDATION_POLICY = 'native-errors-block-warnings-record-v1'
|
|
|
|
|
|
def classify_diagnostics(details, native_passed):
|
|
errors, warnings = [], []
|
|
if not isinstance(details, list) or not isinstance(native_passed, bool):
|
|
return {'passed': False, 'errors': [{'reason': 'Invalid native check response', 'details': details}], 'warnings': []}
|
|
|
|
def visit(item, inherited=None):
|
|
if not isinstance(item, dict):
|
|
errors.append({'reason': 'Unclassified native diagnostic', 'details': item});return
|
|
severity = str(item.get('severity', item.get('type', inherited or ''))).lower()
|
|
name = str(item.get('name', item.get('errorType', ''))).lower()
|
|
if severity in {'error','fatal'} or 'error' in name or '错误' in name:
|
|
severity = 'error'
|
|
elif severity in {'warn','warning'} or name in {'warning','warnings','警告'}:
|
|
severity = 'warning'
|
|
children = item.get('list')
|
|
if isinstance(children, list) and children:
|
|
for child in children:visit(child,severity)
|
|
elif severity == 'warning':
|
|
warnings.append(item)
|
|
else:
|
|
# Unknown categories are never silently converted to warnings.
|
|
errors.append(item)
|
|
|
|
for item in details:visit(item)
|
|
if not native_passed and not details:
|
|
errors.append({'reason': 'Native check returned false without diagnostic evidence'})
|
|
return {'passed': not errors, 'errors': errors, 'warnings': warnings, 'nativePassed':native_passed}
|
|
|
|
|
|
def evaluate_verification(result):
|
|
if not isinstance(result, dict):raise ValueError('Missing native verification result')
|
|
sch=classify_diagnostics(result.get('schErrors'), result.get('schPassed'))
|
|
pcb=classify_diagnostics(result.get('pcbErrors'), result.get('pcbPassed'))
|
|
result.update(validation_policy=VALIDATION_POLICY, accepted=sch['passed'] and pcb['passed'],
|
|
warnings={'schematic':sch['warnings'],'pcb':pcb['warnings']},
|
|
blockingErrors={'schematic':sch['errors'],'pcb':pcb['errors']})
|
|
if result.get('schematicParts',0)<2 or result.get('pcbParts',0)<2:
|
|
result['accepted']=False
|
|
result['blockingErrors']['design']=[{'reason':'Native design is empty or incomplete'}]
|
|
return result
|