perf: replace automatic backups with manual backup reminders

This commit is contained in:
阿白叔 committed 2026-11-03 16:44:30 +08:00
1 parent 7527800128
commit c85696080d
26 files changed
+385 -102

No files matched your search

+30 -6
View File
@@ -234,7 +234,7 @@ def test_retained_importer_blocks_repair_even_without_an_open_database_handle(tm
assert 'IMPORTER_RELEASE_UNCONFIRMED' in outcome['detail']
def test_repair_cancellation_during_backup_prevents_native_launch(tmp_path, monkeypatch):
def test_repair_cancellation_during_access_check_prevents_native_launch(tmp_path, monkeypatch):
from cbb_refresh_verify import native_repair_ui as ui, native_repair, mentor_adapter
request, record, target = target_fixture(tmp_path)
root = tmp_path/'worker'
@@ -251,15 +251,15 @@ def test_repair_cancellation_during_backup_prevents_native_launch(tmp_path, monk
monkeypatch.setattr(ui, '_repair_command', lambda *_: 32924)
monkeypatch.setattr(mentor_adapter, 'pcb_processes', lambda: [])
monkeypatch.setattr(mentor_adapter, '_process_details', lambda *_: [])
def backup(*a):
assert calls == ['watchdog'], 'Watch supervisor before the potentially long backup'
def check(*a):
assert calls == ['watchdog'], 'Watch supervisor before filesystem checks'
cancel.touch()
calls.append('backup')
monkeypatch.setattr(native_repair, 'backup_project', backup)
calls.append('check')
monkeypatch.setattr(native_repair, 'check_repair_access', check)
monkeypatch.setattr(ui.subprocess, 'Popen', lambda *a, **kw: pytest.fail('Repair must not start'))
assert ui.repair_worker_main(job) == 1
outcome = json.loads((root/'repair-result.json').read_text('utf-8'))
assert 'REPAIR_CANCELLED_AFTER_BACKUP' in outcome['detail']
assert 'REPAIR_CANCELLED_BEFORE_LAUNCH' in outcome['detail']
def test_repair_worker_refuses_the_input_desktop_before_backup(tmp_path, monkeypatch):
@@ -425,6 +425,30 @@ def test_native_worker_preserves_success_and_historical_restore_distinction(tmp_
assert native_success_confirmed(target, result) is (scenario == 'success')
def test_repair_skips_application_backup_but_keeps_native_repair_backup(tmp_path, monkeypatch):
ui, root, job, actions = repair_worker_fixture(tmp_path, monkeypatch, 'success')
monkeypatch.setattr('cbb_refresh_verify.native_repair.backup_project',
lambda *a: pytest.fail('application project backup must not run'))
assert ui.repair_worker_main(job) == 0
result = json.loads((root/'repair-result.json').read_text('utf-8'))
assert result['evidence']['native_backup'] is True
assert not (root/'complete-backup').exists()
def test_repair_without_application_backup_still_rejects_busy_database(tmp_path, monkeypatch):
import win32con, win32file
ui, root, job, actions = repair_worker_fixture(tmp_path, monkeypatch, 'success')
database = Path(json.loads(job.read_text())['database'])/'icdb.dat'
handle = win32file.CreateFile(str(database), win32con.GENERIC_READ, 0, None,
win32con.OPEN_EXISTING, win32con.FILE_ATTRIBUTE_NORMAL, None)
try:
monkeypatch.setattr(ui.subprocess, 'Popen', lambda *a, **kw: pytest.fail('busy database launched'))
assert ui.repair_worker_main(job) == 1
assert 'REPAIR_DATABASE_IN_USE' in json.loads((root/'repair-result.json').read_text())['detail']
finally:
handle.Close()
def test_native_busy_project_on_load_never_invokes_repair(tmp_path, monkeypatch):
ui, root, job, actions = repair_worker_fixture(tmp_path, monkeypatch, 'busy_before')
assert ui.repair_worker_main(job) == 1