fix: report pending PCB recovery version without obscuring native repair

This commit is contained in:
阿白叔 committed 2026-11-03 09:54:01 +08:00
1 parent 99a708b40c
commit d76475a1d7
8 files changed
+315 -3

No files matched your search

+183
View File
@@ -0,0 +1,183 @@
{
"hwnd": 100,
"pid": 20,
"process_name": "ExpeditionPCB.exe",
"process_role": "pcb",
"window_class": "#32770",
"title": "Database Restoration",
"phase": "PCB_STARTING",
"controls": [
{
"handle": 101,
"control_id": 65535,
"class_name": "Static",
"name": "",
"automation_id": "65535",
"control_type": "Image",
"enabled": true,
"selected": false,
"checked": false,
"patterns": []
},
{
"handle": 102,
"control_id": 6208,
"class_name": "Static",
"name": "The system has detected this design abnormally terminated the last time it was used. The user has to decide what database (if any) to associate with the design.",
"automation_id": "6208",
"control_type": "Text",
"enabled": true,
"selected": false,
"checked": false,
"patterns": []
},
{
"handle": 103,
"control_id": 6212,
"class_name": "Button",
"name": "Restore Database",
"automation_id": "6212",
"control_type": "Group",
"enabled": true,
"selected": false,
"checked": false,
"patterns": []
},
{
"handle": 104,
"control_id": 6213,
"class_name": "Button",
"name": "Load the last user saved database dated 2026/9/24 23:06.",
"automation_id": "6213",
"control_type": "RadioButton",
"enabled": true,
"selected": false,
"checked": false,
"patterns": [
"Invoke",
"SelectionItem"
]
},
{
"handle": 105,
"control_id": 6206,
"class_name": "Button",
"name": "Load the autosave database dated 2026/9/24 23:06.",
"automation_id": "6206",
"control_type": "RadioButton",
"enabled": true,
"selected": true,
"checked": true,
"patterns": [
"Invoke",
"SelectionItem"
]
},
{
"handle": 106,
"control_id": 6207,
"class_name": "Static",
"name": "This will restore the design to the last autosave state.",
"automation_id": "6207",
"control_type": "Text",
"enabled": true,
"selected": false,
"checked": false,
"patterns": []
},
{
"handle": 107,
"control_id": 6209,
"class_name": "Static",
"name": "This will restore the design to the data from the last user save.",
"automation_id": "6209",
"control_type": "Text",
"enabled": true,
"selected": false,
"checked": false,
"patterns": []
},
{
"handle": 108,
"control_id": 6210,
"class_name": "Static",
"name": "Autosaved changes will be lost.",
"automation_id": "6210",
"control_type": "Text",
"enabled": true,
"selected": false,
"checked": false,
"patterns": []
},
{
"handle": 109,
"control_id": 6211,
"class_name": "Static",
"name": "* Cancelling will load no design.",
"automation_id": "6211",
"control_type": "Text",
"enabled": true,
"selected": false,
"checked": false,
"patterns": []
},
{
"handle": 110,
"control_id": 1,
"class_name": "Button",
"name": "OK",
"automation_id": "1",
"control_type": "Button",
"enabled": true,
"selected": false,
"checked": false,
"patterns": [
"Invoke"
]
},
{
"handle": 111,
"control_id": 2,
"class_name": "Button",
"name": "Cancel",
"automation_id": "2",
"control_type": "Button",
"enabled": true,
"selected": false,
"checked": false,
"patterns": [
"Invoke"
]
},
{
"handle": 100,
"control_id": 0,
"class_name": "#32770",
"name": "Database Restoration",
"automation_id": "",
"control_type": "Window",
"enabled": true,
"selected": false,
"checked": false,
"patterns": [
"Window"
]
},
{
"handle": 0,
"control_id": 0,
"class_name": "",
"name": "",
"automation_id": "",
"control_type": "TitleBar",
"enabled": true,
"selected": false,
"checked": false,
"patterns": [
"Value"
]
}
],
"owner_hwnd": 90,
"diagnostics": []
}
+20
View File
@@ -270,3 +270,23 @@ def test_physical_release_alone_does_not_authorize_queue(case, monkeypatch, stat
assert result.safe_to_continue is expected_safe
assert result.recovery_attempts[0]['status'] == status
assert library_lock.has_blocker(request.lmc_file) is not expected_safe
def test_successful_icdb_repair_then_version_choice_reports_partial_completion(case, monkeypatch):
from cbb_refresh_verify import native_repair, verify_runner as runner
from test_native_repair import complete_native_success
request, _, address = case
def repair(target, *a, **k):
address.unlink()
return complete_native_success(target)
monkeypatch.setattr(native_repair, 'run_native_repair', repair)
monkeypatch.setattr(native_repair, 'repair_release_state', lambda req, target, result: result['release'])
monkeypatch.setattr(runner, '_run_verify_serialized', lambda *a, **k: runner.VerifyResult('FAIL',
error_category='PCB_VERSION_CHOICE_REQUIRED', stderr='PCB版本待选:最后用户保存/自动保存 2026/9/24 23:06',
safe_to_continue=False, evidence_path=request.evidence_dir/'verify/result.json'))
result = runner.run_verify(request)
assert result.status == 'FAIL' and not result.safe_to_continue
assert 'ICDB原生修复已完成' in result.stderr and '尚未校验通过' in result.stderr
assert result.recovery_attempts[0]['native_status'] == 'REPAIRED'
assert result.recovery_attempts[0]['status'] == 'PCB_VERSION_CHOICE_REQUIRED'
assert result.recovery_attempts[0]['validation_passed'] is False
+51
View File
@@ -0,0 +1,51 @@
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'