fix: reconcile reused identities and protect every native dispatch

This commit is contained in:
阿白叔 committed 2026-11-06 16:21:08 +08:00
1 parent cb11624b68
commit d9a79b6535
8 files changed
+159 -13

No files matched your search

+31
View File
@@ -429,6 +429,37 @@ def test_com_failure_without_owner_identity_cannot_claim_release(tmp_path, monke
assert native._catalog_native({}, tmp_path)['safe_to_continue'] is False
def test_pending_async_add_does_not_close_or_quit_library(tmp_path, monkeypatch):
import cbb_refresh_verify.native_management as native
import cbb_refresh_verify.mentor_adapter as mentor
import win32com.client
library_path = tmp_path/'lib.lmc'
running = []
class Library:
FullName = str(library_path)
FlowType = 1
def Close(self): pytest.fail('Close during pending Add')
class App:
def OpenLibrary(self, path): return Library()
def Quit(self): pytest.fail('Quit during pending Add')
def dispatch(*a): running.append(True); return App()
monkeypatch.setattr(win32com.client, 'DispatchEx', dispatch)
monkeypatch.setattr(native, 'validate_owned_fixture_add', lambda *a: None)
monkeypatch.setattr(native, '_current_desktop', lambda: (SimpleNamespace(EnumDesktopWindows=lambda: []), 'CbbManagement_test'))
monkeypatch.setattr(mentor, '_process_details', lambda _: [
(123, str(tmp_path/'lm/win32/bin/LibraryManager.exe'), '', 0)] if running else [])
def pending(app, job, *a, **kw):
job['_native_add_pending'] = True
raise TimeoutError('native result unknown')
monkeypatch.setattr(native, '_probe_add_dialog', pending)
result = native._catalog_com({'operation': 'add', 'library': str(library_path),
'desktop': 'CbbManagement_test', 'mentor_home': str(tmp_path),
'supervisor_pid': __import__('os').getpid()}, tmp_path)
assert result['success'] is False
assert result['native_pids'] == [123]
assert 'native result unknown' in result['detail']
@pytest.mark.parametrize('registered', [True, False])
def test_shared_add_reopens_exact_catalog_and_reports_identity_mismatch(tmp_path, monkeypatch, registered):
import cbb_refresh_verify.native_management as native