fix: normalize native editor handles before UIA calls

This commit is contained in:
阿白叔 committed 2026-11-02 22:36:23 +08:00
1 parent 1f69480ed8
commit bb98fe66dd
2 files changed
+31 -1

No files matched your search

+1 -1
View File
@@ -275,7 +275,7 @@ def _probe_add_dialog_impl(app, job, desktop, owned_pids, root, *, library=None)
for hwnd in desktop.EnumDesktopWindows():
if (win32process.GetWindowThreadProcessId(hwnd)[1] in owned_pids
and win32gui.IsWindowVisible(hwnd) and win32gui.GetWindowText(hwnd) == title):
return hwnd
return int(hwnd)
return None
def await_window(title):
while time.monotonic() < deadline:
+30
View File
@@ -106,3 +106,33 @@ def test_probe_preloads_uia_before_com_proxy_creation_but_catalog_stays_read_onl
else:
assert result['exception']['hresult'] == -2147220995
assert result['exception']['args'] == ['controlled native failure']
def test_probe_converts_desktop_pyhandle_before_uia_boundary(tmp_path, monkeypatch):
import sys, win32gui, win32process
import cbb_refresh_verify.native_management as native
import cbb_refresh_verify.management as management
import cbb_refresh_verify.backup_recovery as recovery
source = tmp_path/'source/Block.prj'
pcb = source.parent/'PCB/Block.pcb'
root = tmp_path/'native-add'; root.mkdir()
class Handle:
def __int__(self): return 200
handle = Handle()
desktop = SimpleNamespace(EnumDesktopWindows=lambda: [handle])
monkeypatch.setattr(win32process, 'GetWindowThreadProcessId', lambda hwnd: (1, 9))
monkeypatch.setattr(win32gui, 'IsWindowVisible', lambda hwnd: True)
monkeypatch.setattr(win32gui, 'GetWindowText', lambda hwnd: 'Reusable Blocks')
monkeypatch.setattr(management, 'source_project', lambda *a: (source, pcb, 'Block'))
monkeypatch.setattr(recovery, '_align_library', lambda *a: None)
class Desktop:
def __init__(self, **kwargs): pass
def window(self, *, handle):
assert type(handle) is int and handle == 200
raise RuntimeError('integer UIA boundary reached')
monkeypatch.setitem(sys.modules, 'pywinauto', SimpleNamespace(Desktop=Desktop))
app = SimpleNamespace(OnReusableBlocksEditor=lambda: None)
job = {'operation': 'probe_create_add', 'source': str(source), 'name': 'Block',
'library': str(root/'fixture/mentor_lib.lmc'), 'timeout_seconds': 5}
with pytest.raises(RuntimeError, match='integer UIA boundary reached'):
native._probe_add_dialog_impl(app, job, desktop, {9}, root)