feat: offer explicit copy recovery after failed ICDB maintenance

This commit is contained in:
阿白叔 committed 2026-11-04 14:16:00 +08:00
1 parent e14a864b37
commit 29959e2988
7 files changed
+520 -27

No files matched your search

+48 -3
View File
@@ -118,9 +118,8 @@ def test_explicit_release_requires_fresh_proof_and_never_deletes_sidecar(tmp_pat
def test_release_proof_checks_addresses_and_exclusive_databases(tmp_path, monkeypatch):
import cbb_refresh_verify.library_lock as locks
import win32com.client
from types import SimpleNamespace
monkeypatch.setattr(win32com.client, 'GetObject', lambda *_: SimpleNamespace(ExecQuery=lambda *_: []))
import cbb_refresh_verify.owner_probe as probe
monkeypatch.setattr(probe, 'query_owners', lambda *_: [])
library = tmp_path/'lib.lmc'; library.touch()
address = tmp_path/'database/cdbsvr/sAddress.adr'; address.parent.mkdir(parents=True)
address.touch()
@@ -138,6 +137,52 @@ def test_release_proof_checks_addresses_and_exclusive_databases(tmp_path, monkey
assert proof['exclusive_files'] == [str(library)]
def test_release_probe_timeout_does_not_clear_retained_checkpoint(tmp_path, monkeypatch):
import cbb_refresh_verify.library_lock as locks
import cbb_refresh_verify.owner_probe as probe
library = tmp_path/'library/lib.lmc'; library.parent.mkdir(); library.touch()
with locks.LibraryLock(library, safe_to_release=lambda: False) as lease: pass
marker = locks.blocker_path(library)
before = marker.read_bytes()
def timeout(*args): raise RuntimeError('OWNER_QUERY_TIMEOUT')
monkeypatch.setattr(probe, 'query_owners', timeout)
try:
with pytest.raises(RuntimeError, match='OWNER_QUERY_TIMEOUT'):
locks.release_retained_library(library, tmp_path/'release')
assert marker.read_bytes() == before
finally:
with locks._guard:
owner = locks._owners.pop(lease.key, None)
if owner: owner['handle'].Close()
@pytest.mark.parametrize('name,command', [
('cscript.exe', 'cscript.exe close_failed_block.vbs'),
('python.exe', 'python.exe -m cbb_refresh_verify --repair-worker job.json'),
])
def test_release_proof_waits_for_late_operation_helpers(tmp_path, monkeypatch, name, command):
import cbb_refresh_verify.library_lock as locks
import cbb_refresh_verify.owner_probe as probe
library = tmp_path/'lib.lmc'; library.touch()
monkeypatch.setattr(probe, 'query_owners', lambda names:
[{'pid': 123456, 'name': name, 'command': command}] if name in names else [])
with pytest.raises(locks.LibraryBusy, match='123456'):
with locks._prove_library_released(library): pass
def test_release_rechecks_owners_after_database_handles_are_acquired(tmp_path, monkeypatch):
import cbb_refresh_verify.library_lock as locks
import cbb_refresh_verify.owner_probe as probe
library = tmp_path/'lib.lmc'; library.touch()
calls = []
def query(names):
calls.append(1)
return [] if len(calls) == 1 else [{'pid': 123456, 'name': 'cscript.exe', 'command': 'helper'}]
monkeypatch.setattr(probe, 'query_owners', query)
with pytest.raises(locks.LibraryBusy, match='123456'):
with locks._prove_library_released(library): pass
def test_public_verify_initializes_com_in_its_operation_thread(tmp_path, monkeypatch):
import ctypes
import cbb_refresh_verify.verify_runner as runner