fix: report pending PCB recovery version without obscuring native repair
This commit is contained in:
1 parent
99a708b40c
commit
d76475a1d7
8 files changed
+315
-3
No files matched your search
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, fields, replace
|
||||
import json
|
||||
import re
|
||||
from pathlib import Path
|
||||
import sys
|
||||
from typing import Any, Sequence
|
||||
@@ -185,6 +186,39 @@ def _decision(rule: DialogRule) -> RuleDecision:
|
||||
)
|
||||
|
||||
|
||||
def pcb_version_choice(snapshot):
|
||||
"""Describe the captured native choice; never select or approve a version."""
|
||||
if (snapshot.title != 'Database Restoration' or snapshot.window_class != '#32770'
|
||||
or snapshot.process_name.casefold() != 'expeditionpcb.exe' or snapshot.process_role != 'pcb'
|
||||
or snapshot.phase != DialogPhase.PCB_STARTING):
|
||||
return None
|
||||
explanation = ('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.')
|
||||
if not any(c.control_id == 6208 and ' '.join(c.name.split()) == explanation for c in snapshot.controls):
|
||||
return None
|
||||
candidates = []
|
||||
for identifier, kind, prefix in ((6213, 'last_user_saved', 'Load the last user saved database dated '),
|
||||
(6206, 'autosave', 'Load the autosave database dated ')):
|
||||
controls = [c for c in snapshot.controls if c.control_id == identifier and c.class_name == 'Button']
|
||||
if len(controls) != 1: return None
|
||||
control = controls[0]
|
||||
match = re.fullmatch(re.escape(prefix) + r'(.+)\.', ' '.join(control.name.split()))
|
||||
if not match: return None
|
||||
candidates.append({'kind': kind, 'control_id': identifier, 'label': control.name,
|
||||
'date': match.group(1), 'enabled': control.enabled,
|
||||
'selected': control.selected or control.checked})
|
||||
return {'candidates': candidates, 'automatic_selection': False}
|
||||
|
||||
|
||||
def archive_version_choice(snapshot, root):
|
||||
choice = pcb_version_choice(snapshot)
|
||||
if choice is None: raise ValueError('Not the recognized native PCB version choice')
|
||||
path = Path(root)/'pcb-version-choice.json'
|
||||
path.write_text(json.dumps({**choice, 'snapshot': snapshot.to_record()},
|
||||
ensure_ascii=False, indent=2), encoding='utf-8')
|
||||
return path
|
||||
|
||||
|
||||
def decide(snapshot: WindowSnapshot, rules: Sequence[DialogRule]) -> RuleDecision:
|
||||
# Windows Text Services Framework language-bar window exposed by Mentor's
|
||||
# process is not a Mentor modal: it has no controls and must not abort a run.
|
||||
@@ -197,6 +231,12 @@ def decide(snapshot: WindowSnapshot, rules: Sequence[DialogRule]) -> RuleDecisio
|
||||
if parse_session_loss(combined):
|
||||
return RuleDecision(error_code=ERROR_CODE,
|
||||
detail=' | '.join(snapshot.texts) or snapshot.title)
|
||||
choice = pcb_version_choice(snapshot)
|
||||
if choice is not None:
|
||||
labels = {'last_user_saved': '最后用户保存', 'autosave': '自动保存'}
|
||||
detail = ';'.join(f'{labels[c["kind"]]}:{c["date"]}' for c in choice['candidates'])
|
||||
return RuleDecision(error_code='PCB_VERSION_CHOICE_REQUIRED',
|
||||
detail=f'PCB需选择恢复版本,尚未校验通过。候选版本:{detail}。未自动选择或确认任何版本。')
|
||||
# These prompts require knowledge of database ownership or a recovery
|
||||
# choice. A generic Yes/restore rule cannot establish either fact.
|
||||
if any(marker in combined for marker in (
|
||||
|
||||
@@ -12,10 +12,14 @@ def maintenance_counts(results):
|
||||
and result.safe_to_continue
|
||||
for result in results for attempt in result.recovery_attempts)
|
||||
review = sum(attempt.get('status') == 'RESTORED_REVIEW_REQUIRED' for attempt in attempts)
|
||||
version_choice = sum(attempt.get('status') == 'PCB_VERSION_CHOICE_REQUIRED'
|
||||
and attempt.get('native_status') == 'REPAIRED'
|
||||
and attempt.get('validation_passed') is False for attempt in attempts)
|
||||
return {'total': len(results), 'passed': sum(r.status == 'PASS' for r in results),
|
||||
'skipped': sum(r.status == 'SKIPPED' for r in results),
|
||||
'repaired': repaired, 'review_required': review,
|
||||
'repair_unconfirmed': len(attempts)-repaired-review}
|
||||
'version_choice_required': version_choice,
|
||||
'repair_unconfirmed': len(attempts)-repaired-review-version_choice}
|
||||
|
||||
|
||||
def write_maintenance_report(requests, results, batch_report, skipped_names):
|
||||
|
||||
@@ -205,6 +205,12 @@ def run_existing_address_maintenance(request, *, verify, progress=None):
|
||||
good = verified.status == 'PASS' and verified.library_flag == 'GREEN' and owner_safe
|
||||
recovery.update(status='REPAIRED' if good else 'REPAIR_VALIDATION_FAILED',
|
||||
validation_passed=good, validation_evidence=str(verified.evidence_path or ''))
|
||||
if verified.error_category == 'PCB_VERSION_CHOICE_REQUIRED':
|
||||
owner_safe = False
|
||||
good = False
|
||||
recovery.update(status='PCB_VERSION_CHOICE_REQUIRED', validation_passed=False)
|
||||
verified = replace(verified, safe_to_continue=False,
|
||||
stderr='ICDB原生修复已完成;PCB需选择恢复版本,尚未校验通过。\n' + verified.stderr)
|
||||
return save(replace(verified, status='PASS' if good else 'FAIL',
|
||||
recovery_attempts=(recovery,)))
|
||||
if recovery.get('status') == 'REPAIRED':
|
||||
|
||||
@@ -824,6 +824,7 @@ class MainWindow(QWidget):
|
||||
text = ('非 READY ICDB 检查已结束\n'
|
||||
f'校验通过 {passed},失败/受阻 {failed},队列未执行 {skipped}\n'
|
||||
f'原生修复完成 {counts["repaired"]},恢复备份待复核 {counts["review_required"]},'
|
||||
f'ICDB已修复/PCB版本待选 {counts["version_choice_required"]},'
|
||||
f'修复未确认 {counts["repair_unconfirmed"]}\n'
|
||||
f'完整日志:{report}\n仅失败日志:{failure_report_path(report)}')
|
||||
self.icdb_phase.setText('已停止,存在待处理项目' if failed or skipped else '已完成非 READY 检查')
|
||||
@@ -833,6 +834,7 @@ class MainWindow(QWidget):
|
||||
if self._global_icdb_run:
|
||||
status_text = (f'非 READY 检查结束:通过 {passed},失败/受阻 {failed},未执行 {skipped}。\n'
|
||||
f'原生修复 {counts["repaired"]},恢复备份待复核 {counts["review_required"]},'
|
||||
f'ICDB已修复/PCB版本待选 {counts["version_choice_required"]},'
|
||||
f'修复未确认 {counts["repair_unconfirmed"]}。')
|
||||
self.status_label.setText(status_text); self.output.append(text)
|
||||
self.summary = QMessageBox(self)
|
||||
|
||||
@@ -264,6 +264,8 @@ def read_library_flag_with_retry(reader, library, block_name, *, attempts=3,
|
||||
def classify_failure_category(detail):
|
||||
text = str(detail or '')
|
||||
lower = text.casefold()
|
||||
if 'pcb_version_choice_required' in lower:
|
||||
return 'PCB_VERSION_CHOICE_REQUIRED'
|
||||
from .icdb_recovery import ERROR_CODE, parse_session_loss
|
||||
if ERROR_CODE.casefold() in lower or parse_session_loss(text):
|
||||
return ERROR_CODE
|
||||
@@ -811,7 +813,7 @@ def _run_verify(request, *, timing, progress=None, flag_reader=None, process_run
|
||||
'start_gate': str(root/'start-worker.signal')}
|
||||
consent = None
|
||||
if request.post_repair_proof is not None:
|
||||
from .post_repair_consent import PostRepairProof, ConsentController
|
||||
from .post_repair_consent import PostRepairProof, ConsentController, exact_prompt
|
||||
if not isinstance(request.post_repair_proof, PostRepairProof):
|
||||
return finish(VerifyResult('BLOCKED', stderr='POST_REPAIR_PROOF_REQUIRED', safe_to_continue=False))
|
||||
job['post_repair_consent'] = request.post_repair_proof.for_job(job)
|
||||
@@ -938,12 +940,16 @@ def _run_verify(request, *, timing, progress=None, flag_reader=None, process_run
|
||||
dialog_result = dialog_supervisor.poll()
|
||||
if (consent is not None and dialog_agent is not None
|
||||
and dialog_result.error_code == 'DATABASE_RECOVERY_REQUIRED'
|
||||
and dialog_result.snapshot is not None):
|
||||
and dialog_result.snapshot is not None and exact_prompt(dialog_result.snapshot)):
|
||||
consent_snapshot = dialog_result.snapshot
|
||||
if consent_snapshot.hwnd in {int(h) for h in process.desktop.EnumDesktopWindows()}:
|
||||
dialog_result = consent.handle(consent_snapshot, dialog_result.observed_snapshots,
|
||||
target_pid=target_pid, launcher_pid=launcher_pid, worker_pid=process.pid,
|
||||
companion_pids=tuple(process.companion_pids), perform=dialog_supervisor.backend.perform)
|
||||
if dialog_result.error_code == 'PCB_VERSION_CHOICE_REQUIRED' and dialog_result.snapshot is not None:
|
||||
from .dialog_rules import archive_version_choice
|
||||
choice_path = archive_version_choice(dialog_result.snapshot, root)
|
||||
dialog_result = replace(dialog_result, detail=dialog_result.detail + f'\n版本候选与原生窗口证据:{choice_path}')
|
||||
# Normal progress stays in memory. Only actions/errors and the
|
||||
# last failure snapshots are persisted, not every elapsed tick.
|
||||
latest_snapshots = dialog_result.observed_snapshots
|
||||
|
||||
+183
@@ -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": []
|
||||
}
|
||||
@@ -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
|
||||
@@ -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'
|
||||
Reference in new issue
Block a user