feat: expose proven pin metadata and unsupported mapping coverage

This commit is contained in:
阿白叔 committed 2026-11-17 15:43:47 +08:00
1 parent de486a9c6b
commit deaf8c3ab4
5 files changed
+106 -1

No files matched your search

@@ -0,0 +1,58 @@
"""Conservative native text adapter. Missing fields remain unknown."""
from pathlib import Path
import re
from ..native_netlist import _hash, _instance_identity
from ..native_inventory import read_native_text
from .rules import component_key
def inspect_footprint_mapping(binding):
return {'state':'unknown','mapping':None,'reason':'未实现确切库版本的内部引脚到焊盘映射读取'}
def inspect_pin_metadata(export,*,evidence_root):
result={'pins':[],'uncovered':['引脚级 Value','库内引脚到焊盘映射']}
try:
path=Path(export.get('outputs',{})['effective']).resolve()
if not path.is_relative_to(Path(evidence_root).resolve()):raise ValueError('原始证据越界')
sha=_hash(path);lines=read_native_text(path).splitlines();records=[];record=None
for n,line in enumerate(lines,1):
if line.startswith(' Symbol '):
match=re.fullmatch(r' Symbol (.+?)\tref des ([^\t]*)\tpage ([^\t]*)',line)
record={'uid':match[1],'refdes':match[2],'page':match[3],'paths':[],'pins':[]} if match else None
if record:records.append(record)
elif record is not None:
if line.startswith('\tPath '):record['paths'].append(line[6:])
elif line.startswith('\tPin '):
fields=line[5:].split('\t');values=dict(v.split(' ',1) for v in fields[1:] if ' ' in v)
record['pins'].append((fields[0],values,n))
graph=export.get('graph',{}).get('components',{})
candidates=[]
for record in records:
for scope in record['paths']:
uid=_instance_identity(record['uid'],scope);component=graph.get(uid)
if component is None or component.get('refdes')!=record['refdes']:continue
for name,values,n in record['pins']:
pin=component.get('pins',{}).get(name)
if not pin or not values.get('num') or pin.get('number')!=values['num']:continue
key=component_key(uid,component)
if key is None:continue
candidates.append({'endpoint':[*key,values['num']],
'logical_name':{'value':name,'confidence':'proven'},
'pin_value':{'value':None,'confidence':'unknown'},
'electrical_type':{'value':values.get('type'),'confidence':'proven' if 'type' in values else 'unknown'},
'raw':{'path':str(path),'sha256':sha,'line':n,'page':record['page'] or None}})
from collections import Counter
counts=Counter(tuple(p['endpoint']) for p in candidates)
result['pins']=[p for p in candidates if counts[tuple(p['endpoint'])]==1]
if _hash(path)!=sha:raise ValueError('原始证据在读取时变化')
except (OSError,ValueError,KeyError,TypeError) as error:
result.update(pins=[],reason=str(error))
return result
def compare_metadata(before,after):
left={tuple(p['endpoint']):p for p in before['pins']};right={tuple(p['endpoint']):p for p in after['pins']}
return {'comparisons':{str(key):{phase:{name:row[name]['value'] for name in ('pin_value','electrical_type')}
for phase,row in (('before',left[key]),('after',right[key]))}
for key in left.keys()&right.keys()}}
@@ -46,8 +46,12 @@ def run_attempt(service,attempt_id,*,stop_event):
check_cancelled(stop_event)
expected=service.artifacts.read(payload['expectation_ref'],'expectations') if payload['expectation_ref'] else None
from .rules import evaluate
result=dict(evaluate(left,right,expectations=expected,check_plan=payload['check_plan']),
from .pin_metadata import inspect_pin_metadata,compare_metadata
metadata={phase:inspect_pin_metadata(export,evidence_root=output) for phase,export in (('before',left),('after',right))}
result=dict(evaluate(left,right,expectations=expected,check_plan=payload['check_plan'],
pin_metadata=compare_metadata(metadata['before'],metadata['after'])),
before=left,after=right,attempt_state='succeeded',resource_state='released')
result['pin_metadata']=metadata
result.update(item_id=attempt['item_id'],input_version=attempt['input_version'],attempt_id=attempt_id,
generation=attempt['generation'],input_digest=payload['payload_digest'],policy=payload['check_plan'])
ref=service.artifacts.put('result',result)