test(execution): cover lazy association collisions and context refresh

This commit is contained in:
阿白叔 committed 2026-10-19 10:14:49 +08:00
1 parent 8fe82c3124
commit 998d78dbc0
1 file changed
+48
@@ -506,6 +506,54 @@ Require Comp.LocationReads=2,"invalidated index reused stale geometry"
''')
@pytest.mark.parametrize(('tier', 'shared_uid'), [
('uid', True), ('refdes', False), ('refdes', True),
('location', False), ('location', True),
])
def test_component_lookup_rejects_ambiguous_lazy_buckets(tmp_path, tier, shared_uid):
run_vbs(tmp_path, 'preserve', '''
Dim Records, Record, Candidate, Other
Set Records=QPReadSnapshot(SnapshotPath)
Set Record=Records.Item("components").Item("0")
Set Other=New ValueComponent
Other.UID="other": Other.Refdes=Comp.Refdes
''' + ('Other.UID=Comp.UID\n' if shared_uid else '') + '''
QP_App.Components.Add Other,True
''' + ('Record("uid")="missing"\n' if tier != 'uid' else '') + '''
''' + ('Record("refdes")="missing"\nOther.Refdes="R99"\n' if tier == 'location' else '') + '''
QPInvalidateComponentIndex
On Error Resume Next
Set Candidate=QPFindUniqueByOldLocation(Record)
Failure=Err.Number
Err.Clear
On Error GoTo 0
Require Failure=vbObjectError+802,"ambiguous component association was accepted"
Require QP_App.TransactionCount=0,"ambiguous lookup started a write transaction"
Require Not QP_App.SaveCalled,"ambiguous lookup saved the project"
''')
def test_component_lookup_refreshes_lazy_geometry_when_project_context_changes(tmp_path):
run_vbs(tmp_path, 'preserve', '''
Dim Records, Record, Candidate
Set Records=QPReadSnapshot(SnapshotPath)
Set Record=Records.Item("components").Item("0")
Record("uid")="missing": Record("refdes")="missing"
QPInvalidateComponentIndex
Set Candidate=QPFindUniqueByOldLocation(Record)
Require Candidate Is Comp,"initial geometry fallback failed"
Comp.SetLocation 200,300
QP_App.ProjectPath="C:\\value-test\\two.prj"
On Error Resume Next
Set Candidate=QPFindUniqueByOldLocation(Record)
Failure=Err.Number
Err.Clear
On Error GoTo 0
Require Failure=vbObjectError+802,"changed project reused previous geometry index"
Require QP_App.TransactionCount=0,"changed context lookup started a write transaction"
''')
def test_pin_index_avoids_repeated_full_sheet_queries(tmp_path):
run_vbs(tmp_path, 'part_number', '''
QPInvalidatePinIndex