fix: report known catalog conflicts before WMI startup

This commit is contained in:
阿白叔 committed 2026-11-25 11:53:07 +08:00
1 parent 0ee24d7beb
commit 75612cd4da
4 files changed
+88 -17

No files matched your search

+24 -2
View File
@@ -27,7 +27,7 @@ def test_status_scan_delivers_progress_after_each_record(tmp_path):
def test_catalog_registration_only_skips_project_identities(tmp_path, monkeypatch, include_identity, unknown_foreign):
import win32com.client
import win32process
from cbb_refresh_verify import mentor_adapter
from cbb_refresh_verify import mentor_adapter, owner_probe
lmc = tmp_path / 'lib.lmc'
lmc.touch()
@@ -46,6 +46,7 @@ def test_catalog_registration_only_skips_project_identities(tmp_path, monkeypatc
previous = [(321, str(exe), '', 0)] if unknown_foreign else []
snapshots = iter([previous, [*previous, (123, str(exe), '', 0)]])
monkeypatch.setattr(mentor_adapter, '_process_details', lambda _: next(snapshots))
monkeypatch.setattr(owner_probe, 'snapshot_process_ids', lambda _: [])
if unknown_foreign:
exe.parent.mkdir(parents=True)
exe.write_bytes(b'library manager')
@@ -66,6 +67,26 @@ def test_catalog_registration_only_skips_project_identities(tmp_path, monkeypatc
assert hashed == ([project] if include_identity else [])
def test_catalog_reports_exact_same_library_before_slow_owner_lookup(tmp_path, monkeypatch):
import win32com.client
from cbb_refresh_verify import mentor_adapter, owner_probe
library = tmp_path / 'lib.lmc'
library.touch()
monkeypatch.setattr(native, '_current_desktop', lambda: (None, 'CbbManagement_test'))
monkeypatch.setattr(owner_probe, 'snapshot_process_ids', lambda name: [123], raising=False)
monkeypatch.setattr(native, '_open_catalog_manager_library', lambda pid: library)
monkeypatch.setattr(mentor_adapter, '_process_details', lambda name: pytest.fail('slow owner lookup'))
monkeypatch.setattr(win32com.client, 'DispatchEx', lambda name: pytest.fail('busy library was opened'))
with pytest.raises(native.NativeOperationError, match='LIBRARY_MANAGER_BUSY.*123') as caught:
native._catalog_com({'operation': 'catalog', 'worker_role': 'catalog_readonly',
'include_engineering_identity': False, 'library': str(library),
'desktop': 'CbbManagement_test', 'mentor_home': str(tmp_path)}, tmp_path)
assert caught.value.safe_to_continue is True
assert caught.value.blocking_manager_pids == (123,)
@pytest.mark.parametrize('scope', ['foreign', 'same', 'shared', 'unknown', 'switched', 'occupied'])
def test_catalog_distinguishes_foreign_and_conflicting_manager(tmp_path, monkeypatch, scope):
target = tmp_path/'target'/'lib.lmc'
@@ -99,7 +120,7 @@ def test_catalog_distinguishes_foreign_and_conflicting_manager(tmp_path, monkeyp
@pytest.mark.parametrize('title_resolved', [True, False])
def test_catalog_rejects_reused_foreign_com_proxy_without_mutating_it(tmp_path, monkeypatch, title_resolved):
import win32com.client
from cbb_refresh_verify import mentor_adapter
from cbb_refresh_verify import mentor_adapter, owner_probe
target = tmp_path/'target'/'lib.lmc'
other = tmp_path/'other'/'lib.lmc'
@@ -112,6 +133,7 @@ def test_catalog_rejects_reused_foreign_com_proxy_without_mutating_it(tmp_path,
monkeypatch.setitem(native._BINARY_PROOF, 'lm/win32/bin/LibraryManager.exe', native.hash_file(exe))
before = [(123, 'LibraryManager.exe', f'LibraryManager.exe "{other}"', 0)]
monkeypatch.setattr(mentor_adapter, '_process_details', lambda _: before)
monkeypatch.setattr(owner_probe, 'snapshot_process_ids', lambda _: [])
monkeypatch.setattr(native, '_open_catalog_manager_library', lambda _: other if title_resolved else None)
monkeypatch.setattr(native, '_current_desktop',
lambda: (SimpleNamespace(EnumDesktopWindows=lambda: []), 'CbbManagement_test'))
+12 -13
View File
@@ -326,20 +326,19 @@ def test_recovery_scope_uses_interrupted_block_instead_of_new_selection(tmp_path
def test_probe_timeout_reports_last_io_phase_and_path(tmp_path, monkeypatch):
from cbb_refresh_verify import file_probe
import sys
script = tmp_path/'slow_probe.py'
from pathlib import Path
from types import SimpleNamespace
library = tmp_path/'lib.lmc'
script.write_text(
"import json, sys, time\n"
"from pathlib import Path\n"
"job = Path(sys.argv[-1])\n"
"job.with_name('progress.json').write_text(json.dumps("
"{'stage': 'open_exclusive', 'path': 'SymbolLibs/icdb.dat'}))\n"
"time.sleep(30)\n",
encoding='utf-8')
start = file_probe.subprocess.Popen
monkeypatch.setattr(file_probe.subprocess, 'Popen',
lambda command, **kwargs: start([sys.executable, str(script), command[-1]], **kwargs))
def start(command, **kwargs):
Path(command[-1]).with_name('progress.json').write_text(
'{"stage": "open_exclusive", "path": "SymbolLibs/icdb.dat"}', 'utf-8')
return SimpleNamespace(stdin=SimpleNamespace(close=lambda: None), wait=lambda _: 0)
monkeypatch.setattr(file_probe.subprocess, 'Popen', start)
ticks = iter([0., 1., 1.])
monkeypatch.setattr(file_probe.time, 'monotonic', lambda: next(ticks))
with pytest.raises(TimeoutError, match=r'FILE_PROBE_TIMEOUT.*open_exclusive.*SymbolLibs/icdb.dat'):
with file_probe.hold_release_files(library, timeout_seconds=.7):
pytest.fail('a timed-out probe cannot prove release')