fix: harden supervised replacement and missing uid handling

This commit is contained in:
阿白叔 committed 2026-10-30 16:33:10 +08:00
1 parent 656f43e2ff
commit 131b6dbbb3
30 files changed
+1655 -92

No files matched your search

+60
View File
@@ -166,6 +166,66 @@ def test_native_context_rejects_missing_or_changed_target_without_no_match():
check_context(App(components), Api, metadata, [record])
def test_native_snapshot_rejects_empty_uid_snapshot_only_until_inventory_fallback(tmp_path):
from dx_productivity.trial_task_center.native_helper import read_snapshot
snapshot = tmp_path / 'snapshot.tsv'
snapshot.write_text(
'M\tC:/board.prj\tOLD\tNEW\tMAIN:1\tpreserve\t\t1\ttargets\t\x1fR1\x1fA\n'
'C\t\tR1\t0\t0\t0\t0\t\n', encoding='utf-8')
with pytest.raises(ValueError, match='UID'):
read_snapshot(snapshot)
def test_native_context_uses_refdes_fallback_for_empty_component_uid():
from dx_productivity.trial_task_center.native_helper import check_context
class Component:
UID = ''
Refdes = 'R1'
_oleobj_ = None
def FindAttribute(self, name):
value = 'OLD' if name == 'Part Number' else 'A'
return type('Attr', (), {'InstanceValue': value, 'Value': value})()
Component._oleobj_ = Component()
class View:
Block = type('Block', (), {'SheetNum': '1'})()
def GetName(self, index): return 'MAIN'
def Query(self, kind, selected): return [Component()]
class App:
ActiveView = View()
def GetProjectData(self):
return type('Project', (), {'GetProjectFilePath': lambda self: 'C:/board.prj'})()
class Api:
IVdComp = staticmethod(lambda value: value)
metadata = ['M', 'C:/board.prj', 'OLD', 'NEW', 'MAIN:1', 'preserve', '', '1', 'targets', 'x\x1fR1\x1fA']
metadata[9] = '@REFDES|R1\x1fR1\x1fA'
assert len(check_context(App(), Api(), metadata,
[['C', '@REFDES|R1', 'R1', '0', '0', '0', '0', '']], require_selection=False)) == 1
def test_native_context_rejects_duplicate_refdes_fallback():
from dx_productivity.trial_task_center.native_helper import check_context
class Component:
UID = ''
Refdes = 'R1'
_oleobj_ = None
def FindAttribute(self, name):
return type('Attr', (), {'InstanceValue': 'OLD', 'Value': 'OLD'})()
Component._oleobj_ = Component()
class View:
Block = type('Block', (), {'SheetNum': '1'})()
def GetName(self, index): return 'MAIN'
def Query(self, kind, selected): return [Component(), Component()]
class App:
ActiveView = View()
def GetProjectData(self):
return type('Project', (), {'GetProjectFilePath': lambda self: 'C:/board.prj'})()
class Api:
IVdComp = staticmethod(lambda value: value)
with pytest.raises(ValueError, match='Duplicate component UID'):
check_context(App(), Api(), ['M', 'C:/board.prj', 'OLD', 'NEW', 'MAIN:1'],
[['C', '@REFDES|R1', 'R1']])
def test_native_rejects_changed_unselected_component_since_snapshot(tmp_path):
class Component:
UID = 'u2'