From eaff46e50e30afe979818881e29b781d27d5361a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E7=99=BD=E5=8F=94?= <11794527+absfan@user.noreply.gitee.com> Date: Tue, 17 Nov 2026 03:38:36 +0800 Subject: [PATCH] fix: renew metadata inactivity after completed occupancy checks --- src/cbb_refresh_verify/backup_recovery.py | 3 + src/cbb_refresh_verify/library_lock.py | 2 + tests/test_issue15_manifest_progress.py | 70 +++++++++++++++++++++++ 3 files changed, 75 insertions(+) diff --git a/src/cbb_refresh_verify/backup_recovery.py b/src/cbb_refresh_verify/backup_recovery.py index 2770295..cb5ad0e 100644 --- a/src/cbb_refresh_verify/backup_recovery.py +++ b/src/cbb_refresh_verify/backup_recovery.py @@ -33,6 +33,7 @@ def _idle_check(library, project, pcb, *, confirmation=None, evidence=None, bloc from .icdb_ownership import database_directories, unreleased_addresses from contextlib import ExitStack import win32con, win32file + from .operation_queue import note_metadata_progress directories = database_directories(library, project, pcb) scope = (Path(project).parent, *directories) def owners(): @@ -61,6 +62,7 @@ def _idle_check(library, project, pcb, *, confirmation=None, evidence=None, bloc unknown = owners() resources() # Never hold exclusive probe handles while waiting for a user. if not unknown: + note_metadata_progress() return if confirmation is None: from .write_admission import WriteAdmissionDeclined @@ -71,6 +73,7 @@ def _idle_check(library, project, pcb, *, confirmation=None, evidence=None, bloc if unknown and not confirmation.confirmed(library, unknown): raise ValueError('TARGET_NATIVE_OWNER_UNCONFIRMED: 占用确认后出现新的未知进程,请重新检查。') resources() + note_metadata_progress() def _native_scope_match(command, *, roots=(), files=()): diff --git a/src/cbb_refresh_verify/library_lock.py b/src/cbb_refresh_verify/library_lock.py index 278adc9..273090e 100644 --- a/src/cbb_refresh_verify/library_lock.py +++ b/src/cbb_refresh_verify/library_lock.py @@ -135,6 +135,8 @@ def recheck_previous_release(library, evidence_dir, *, block_name=None, required except Exception as error: notify('previous_release_unconfirmed', detail=str(error)) raise + from .operation_queue import note_metadata_progress + note_metadata_progress() notify('previous_release_confirmed', release_proof=proof, detail='已确认会话释放并归档历史记录;这不表示历史数据已恢复') return proof diff --git a/tests/test_issue15_manifest_progress.py b/tests/test_issue15_manifest_progress.py index f12ad2c..b42cbbb 100644 --- a/tests/test_issue15_manifest_progress.py +++ b/tests/test_issue15_manifest_progress.py @@ -63,3 +63,73 @@ def test_manifest_progress_does_not_interrupt_admitted_native_continuation(tmp_p effects.append('Add') context.run(transaction) assert effects == ['Remove', 'Add'] + + +def test_completed_release_and_idle_checks_outlive_aggregate_deadline(tmp_path, monkeypatch): + from cbb_refresh_verify import library_lock, owner_probe + from cbb_refresh_verify.backup_recovery import _idle_check + library = tmp_path/'library.lmc'; library.touch() + clock, offset = time.monotonic, [0] + monkeypatch.setattr(time, 'monotonic', lambda:clock()+offset[0]) + def released(*args, **kwargs): + offset[0] += 7 + return {'status': 'RELEASE_CONFIRMED'} + def owners(names): + offset[0] += 4 + time.sleep(.06) + return [] + monkeypatch.setattr(library_lock, 'release_retained_library', released) + monkeypatch.setattr(owner_probe, 'query_owners', owners) + context = BatchTaskContext(str(library), native_policy='external') + def prepare(): + library_lock.recheck_previous_release(library, tmp_path/'evidence', required=True) + for name in ('target', 'source'): + _idle_check(library, tmp_path/name/'main.prj', tmp_path/name/'PCB/main.pcb') + check_active() + return 'ready for native dispatch' + try: + assert context.run(prepare, timeout_seconds=10) == 'ready for native dispatch' + assert offset[0] == 15 + finally: + context.close(timeout_seconds=2) + + +@pytest.mark.parametrize('cancel', [False, True]) +def test_completed_idle_check_cannot_revive_stalled_or_cancelled_work(tmp_path, monkeypatch, cancel): + from cbb_refresh_verify import owner_probe + from cbb_refresh_verify.backup_recovery import _idle_check + from cbb_refresh_verify.operation_queue import QueueCancelled + library = tmp_path/'library.lmc'; library.touch() + release = Event(); writes = [] + context = BatchTaskContext(str(library), native_policy='external') + def owners(names): + if cancel: context.cancel() + else: assert release.wait(3) + return [] + monkeypatch.setattr(owner_probe, 'query_owners', owners) + def prepare(): + _idle_check(library, tmp_path/'main.prj', tmp_path/'PCB/main.pcb') + writes.append('dispatch') + try: + with pytest.raises(QueueCancelled): + context.run(prepare, timeout_seconds=.1) + release.set(); context.close(timeout_seconds=2) + assert writes == [] + finally: + release.set() + + +def test_successful_idle_check_does_not_abort_admitted_native_continuation(tmp_path, monkeypatch): + from cbb_refresh_verify import owner_probe + from cbb_refresh_verify.backup_recovery import _idle_check + from cbb_refresh_verify.operation_queue import native_phase + library = tmp_path/'library.lmc'; library.touch() + monkeypatch.setattr(owner_probe, 'query_owners', lambda names: []) + context = BatchTaskContext(str(library)); writes = [] + def transaction(): + with native_phase(): + writes.append('Remove'); context.cancel() + _idle_check(library, tmp_path/'main.prj', tmp_path/'PCB/main.pcb') + writes.append('Add') + context.run(transaction) + assert writes == ['Remove', 'Add']