diff --git a/src/cbb_refresh_verify/native_management.py b/src/cbb_refresh_verify/native_management.py index 571ca2a..1721f9a 100644 --- a/src/cbb_refresh_verify/native_management.py +++ b/src/cbb_refresh_verify/native_management.py @@ -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: diff --git a/tests/test_management_diagnostics.py b/tests/test_management_diagnostics.py index aa52c73..e1dfd5d 100644 --- a/tests/test_management_diagnostics.py +++ b/tests/test_management_diagnostics.py @@ -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)