Files
cbb-refresh-verify-795/tests/test_pcb_version_choice.py
T

52 lines
2.7 KiB
Python

from dataclasses import replace
import json
from pathlib import Path
from cbb_refresh_verify.dialog_models import WindowSnapshot
def captured():
path = Path(__file__).parent/'fixtures/pcb-version-choice-sanitized.json'
return WindowSnapshot.from_record(json.loads(path.read_text(encoding='utf-8')))
def test_actual_version_choice_is_descriptive_fatal_without_action(tmp_path):
from cbb_refresh_verify.dialog_rules import decide, pcb_version_choice, archive_version_choice
from cbb_refresh_verify.post_repair_consent import exact_prompt
value = captured()
decision = decide(value, ())
assert decision.error_code == 'PCB_VERSION_CHOICE_REQUIRED' and not decision.action and not decision.channels
assert '2026/9/24 23:06' in decision.detail
assert '最后用户保存' in decision.detail and '自动保存' in decision.detail
assert not exact_prompt(value)
choice = pcb_version_choice(value)
assert [c['kind'] for c in choice['candidates']] == ['last_user_saved', 'autosave']
assert [c['date'] for c in choice['candidates']] == ['2026/9/24 23:06'] * 2
assert [c['selected'] for c in choice['candidates']] == [False, True]
path = archive_version_choice(value, tmp_path)
record = json.loads(path.read_text(encoding='utf-8'))
assert WindowSnapshot.from_record(record['snapshot']) == value
assert record['candidates'] == choice['candidates']
assert record['automatic_selection'] is False
def test_nonmatching_restoration_remains_blocked_with_original_context():
from cbb_refresh_verify.dialog_rules import decide, pcb_version_choice
value = replace(captured(), title='Other recovery choice')
decision = decide(value, ())
assert pcb_version_choice(value) is None
assert decision.error_code == 'DATABASE_RECOVERY_REQUIRED' and not decision.action
assert 'last user saved' in decision.detail
def test_version_choice_counts_as_pending_review_not_unknown_native_repair():
from cbb_refresh_verify.icdb_maintenance import maintenance_counts
from cbb_refresh_verify.verify_runner import VerifyResult, classify_failure_category
result = VerifyResult('FAIL', error_category='PCB_VERSION_CHOICE_REQUIRED', safe_to_continue=False,
recovery_attempts=({'status': 'PCB_VERSION_CHOICE_REQUIRED', 'native_status': 'REPAIRED',
'validation_passed': False},))
counts = maintenance_counts([result])
assert counts['repaired'] == 0 and counts['version_choice_required'] == 1
assert counts['repair_unconfirmed'] == 0 and counts['passed'] == 0
assert classify_failure_category('PCB_VERSION_CHOICE_REQUIRED: version pending\nPCB_RELEASE_UNCONFIRMED') == 'PCB_VERSION_CHOICE_REQUIRED'