fix: close only completed integration panels during native save

This commit is contained in:
阿白叔 committed 2026-11-17 01:22:58 +08:00
1 parent d40fa3a750
commit 87e10740f7
4 files changed
+71 -5

No files matched your search

+10 -5
View File
@@ -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
+15
View File
@@ -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'
+10
View File
@@ -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==()
+36
View File
@@ -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'