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

+40
View File
@@ -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 (
+5 -1
View File
@@ -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':
+2
View File
@@ -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)
+8 -2
View File
@@ -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