From 87e10740f719d3aa69b2da40268b81de9b379400 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: Tue, 17 Nov 2026 01:22:58 +0800 Subject: [PATCH] fix: close only completed integration panels during native save --- src/cbb_refresh_verify/dialog_probe.py | 15 +++++++---- src/cbb_refresh_verify/dialog_rules.py | 15 +++++++++++ tests/test_dialog_probe.py | 10 +++++++ tests/test_dialog_rules.py | 36 ++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 5 deletions(-) diff --git a/src/cbb_refresh_verify/dialog_probe.py b/src/cbb_refresh_verify/dialog_probe.py index bf02987..49b9eb4 100644 --- a/src/cbb_refresh_verify/dialog_probe.py +++ b/src/cbb_refresh_verify/dialog_probe.py @@ -238,11 +238,16 @@ class WindowProbe: process_name = "" controls = tuple(self._win32_control(child) for child in self._children(hwnd)) diagnostics = [] - try: - uia_records = _bounded_call(lambda: self.uia.controls(hwnd), self.uia_timeout_seconds) - controls = self._merge_controls(controls, uia_records) - except Exception as error: - diagnostics.append(f"UIA_ERROR: {error}") + native_panel = (process_name.casefold() == 'expeditionpcb.exe' + and phase in (DialogPhase.SAVE, DialogPhase.CLOSE) + and gui.GetClassName(hwnd) == '#32770' and gui.GetWindowText(hwnd) == 'Project Integration') + # This native panel's exact control IDs/text are sufficient; its UIA tree can stall Save. + if not native_panel: + try: + uia_records = _bounded_call(lambda: self.uia.controls(hwnd), self.uia_timeout_seconds) + controls = self._merge_controls(controls, uia_records) + except Exception as error: + diagnostics.append(f"UIA_ERROR: {error}") owner = 0 try: owner = int(gui.GetWindow(hwnd, 4) or 0) # GW_OWNER diff --git a/src/cbb_refresh_verify/dialog_rules.py b/src/cbb_refresh_verify/dialog_rules.py index a92884d..fb652e8 100644 --- a/src/cbb_refresh_verify/dialog_rules.py +++ b/src/cbb_refresh_verify/dialog_rules.py @@ -220,6 +220,21 @@ def archive_version_choice(snapshot, root): def decide(snapshot: WindowSnapshot, rules: Sequence[DialogRule]) -> RuleDecision: + if (snapshot.title == 'Project Integration' and snapshot.phase in (DialogPhase.SAVE, DialogPhase.CLOSE) + and snapshot.process_name.casefold() == 'expeditionpcb.exe' and snapshot.process_role == 'pcb' + and snapshot.window_class == '#32770' and snapshot.owner_hwnd and not snapshot.diagnostics): + idle = {1033: 'No connectivity changes to be forward annotated', + 1032: 'No pending schematic CES changes to load into PCB', + 1035: 'No pending PCB changes to be back annotated', + 1034: 'No pending CES changes to load into PCB'} + complete = all(len(matches := [c for c in snapshot.controls if c.control_id == identifier]) == 1 + and matches[0].class_name == 'Static' and matches[0].name == text for identifier, text in idle.items()) + close = [c for c in snapshot.controls if c.control_id == 2] + if (complete and len(close) == 1 and close[0].class_name == 'Button' + and close[0].name.replace('&', '') == 'Close' and close[0].enabled): + return RuleDecision(rule_id='completed-integration-panel', category='SAFE_CONFIRM', + action='close_completed_integration', channels=('win32_button_click',), + target=(('control_id', 2),), postcondition='window_gone') # Windows Text Services Framework language-bar window exposed by Mentor's # process is not a Mentor modal: it has no controls and must not abort a run. if (snapshot.window_class.casefold() == 'cicerouiwndframe' diff --git a/tests/test_dialog_probe.py b/tests/test_dialog_probe.py index 736a6f4..500ddaa 100644 --- a/tests/test_dialog_probe.py +++ b/tests/test_dialog_probe.py @@ -179,3 +179,13 @@ def test_probe_skips_project_integration_panel_during_com_phase(): snapshots = make_probe(gui, (10,)).capture(DialogPhase.PROJECT_INTEGRATION) assert snapshots == () + + +def test_save_integration_panel_uses_complete_win32_controls_without_huge_uia_tree(): + gui=FakeGui({10:{'class_name':'#32770','text':'Project Integration','owner':99}, + 11:{'class_name':'Button','text':'&Close','control_id':2}},children={10:(11,)}) + probe=make_probe(gui,(10,),FakeUia(error=AssertionError('unnecessary large UIA panel scan'))) + probe.process_name_reader=lambda _: 'ExpeditionPCB.exe' + snapshot=probe.capture(DialogPhase.SAVE,pids={1010})[0] + assert snapshot.controls[0].control_id==2 + assert snapshot.diagnostics==() diff --git a/tests/test_dialog_rules.py b/tests/test_dialog_rules.py index 7e252f2..3f060fb 100644 --- a/tests/test_dialog_rules.py +++ b/tests/test_dialog_rules.py @@ -244,3 +244,39 @@ def test_database_open_failure_is_classified_and_declines_log_view(): assert decision.category == 'FATAL_ACK' assert decision.error_code == 'MENTOR_DATABASE_LOAD_FAILED' assert dict(decision.target)['control_id'] == 7 # IDNO, never launch another log viewer + + +def completed_integration_panel(): + texts={1033:'No connectivity changes to be forward annotated', + 1032:'No pending schematic CES changes to load into PCB', + 1035:'No pending PCB changes to be back annotated', + 1034:'No pending CES changes to load into PCB'} + return WindowSnapshot(hwnd=10,pid=20,process_name='ExpeditionPCB.exe',process_role='pcb', + window_class='#32770',title='Project Integration',phase=DialogPhase.SAVE,owner_hwnd=99, + controls=(ControlSnapshot(handle=12,control_id=2,class_name='Button',name='&Close'), + *(ControlSnapshot(handle=i,control_id=i,class_name='Static',name=text) for i,text in texts.items()))) + + +@pytest.mark.parametrize('phase',[DialogPhase.SAVE,DialogPhase.CLOSE]) +def test_completed_integration_panel_only_closes_its_exact_close_control(phase): + from dataclasses import replace + decision=decide(replace(completed_integration_panel(),phase=phase),load_rules(ASSETS/'dialog_rules.v1.json')) + assert decision.action=='close_completed_integration' + assert decision.channels==('win32_button_click',) + assert dict(decision.target)=={'control_id':2} + assert decision.postcondition=='window_gone' and not decision.error_code + + +@pytest.mark.parametrize('fault',['pending','missing','duplicate','partial','foreign','unowned','disabled','early']) +def test_integration_panel_without_complete_owned_idle_proof_never_closes(fault): + from dataclasses import replace + panel=completed_integration_panel() + if fault=='pending': panel=replace(panel,controls=(*panel.controls[:-1],replace(panel.controls[-1],name='CES changes are pending'))) + elif fault=='missing': panel=replace(panel,controls=panel.controls[:-1]) + elif fault=='duplicate': panel=replace(panel,controls=(*panel.controls,panel.controls[-1])) + elif fault=='partial': panel=replace(panel,diagnostics=('WINDOW_ENUM_INCOMPLETE',)) + elif fault=='foreign': panel=replace(panel,process_name='Unrelated.exe',process_role='unknown') + elif fault=='unowned': panel=replace(panel,owner_hwnd=0) + elif fault=='disabled': panel=replace(panel,controls=(replace(panel.controls[0],enabled=False),*panel.controls[1:])) + elif fault=='early': panel=replace(panel,phase=DialogPhase.DOCUMENT_ATTACH) + assert decide(panel,load_rules(ASSETS/'dialog_rules.v1.json')).action!='close_completed_integration'