From 998d78dbc0e92511acfaf7f969251205cee85712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E7=99=BD=E5=8F=94?= <11794527+absfan@user.noreply.gitee.com> Date: Mon, 19 Oct 2026 10:14:49 +0800 Subject: [PATCH] test(execution): cover lazy association collisions and context refresh --- tests/integration/test_quick_value_modes.py | 48 +++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/integration/test_quick_value_modes.py b/tests/integration/test_quick_value_modes.py index bc2213c..3172da9 100644 --- a/tests/integration/test_quick_value_modes.py +++ b/tests/integration/test_quick_value_modes.py @@ -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