feat: scope CBB search selection and maintenance to visible non-READY rows
This commit is contained in:
1 parent
c823a4b92d
commit
747ce1add2
5 files changed
+572
-106
No files matched your search
@@ -1,4 +1,4 @@
|
||||
"""Reports for the explicit full-library maintenance action."""
|
||||
"""Reports for the explicit visible non-READY maintenance action."""
|
||||
from dataclasses import asdict
|
||||
import json
|
||||
|
||||
@@ -20,8 +20,9 @@ def maintenance_counts(results):
|
||||
|
||||
def write_maintenance_report(requests, results, batch_report, skipped_names):
|
||||
path = batch_report.with_name(batch_report.name.replace('batch-', 'icdb-', 1)).with_suffix('.json')
|
||||
record = {'operation': 'full_library_icdb_check_and_repair',
|
||||
'library': str(requests[0].lmc_file), 'includes_ready': True,
|
||||
record = {'operation': 'visible_non_ready_icdb_check_and_repair',
|
||||
'library': str(requests[0].lmc_file), 'includes_ready': False,
|
||||
'target_names': [request.block_name for request in requests],
|
||||
'shared_database_repair_supported': False,
|
||||
'preflight_skipped': sorted(skipped_names), 'counts': maintenance_counts(results),
|
||||
'results': [{'block': req.block_name, **asdict(result)}
|
||||
|
||||
@@ -3,12 +3,13 @@ from threading import Event
|
||||
import os
|
||||
import time
|
||||
from collections import Counter
|
||||
from dataclasses import replace
|
||||
|
||||
from PySide6.QtCore import QObject, QThreadPool, Signal, Qt
|
||||
from PySide6.QtGui import QColor, QIcon
|
||||
from PySide6.QtWidgets import (QWidget, QLineEdit, QPushButton, QFormLayout,
|
||||
QTextEdit, QFileDialog, QHBoxLayout, QLabel, QSpinBox, QMessageBox, QToolButton,
|
||||
QTableWidget, QTableWidgetItem, QHeaderView, QCheckBox, QGroupBox, QVBoxLayout, QProgressBar)
|
||||
QTableWidget, QTableWidgetItem, QHeaderView, QCheckBox, QGroupBox, QVBoxLayout, QProgressBar, QComboBox)
|
||||
from PySide6.QtWidgets import QStyle
|
||||
try:
|
||||
from dx_productivity.trial_task_center.ui.workers import ServiceWorker
|
||||
@@ -45,7 +46,7 @@ def application_icon_path():
|
||||
|
||||
class MainWindow(QWidget):
|
||||
def __init__(self, reader=None, verifier=None, logging_context=None, data_root=None,
|
||||
authoritative_status=True, path_lease_factory=None):
|
||||
authoritative_status=True, path_lease_factory=None, status_refresher=None):
|
||||
super().__init__()
|
||||
self.setWindowTitle('CBB 刷新校验')
|
||||
icon_path = application_icon_path()
|
||||
@@ -78,6 +79,9 @@ class MainWindow(QWidget):
|
||||
self.pool = QThreadPool(self); self.pool.setMaxThreadCount(1)
|
||||
self.busy = False; self.loaded_path = None; self.stop = Event(); self.ready_names = set()
|
||||
self._row_by_name = {}
|
||||
self._records_by_name = {}
|
||||
self.status_refresher = status_refresher or (lambda names, path: authoritative_status_map(
|
||||
names, path, self.data_root / 'status-refresh.jsonl'))
|
||||
self.skipped_names = set(); self.skip_reasons = {}
|
||||
self._global_icdb_run = False
|
||||
self._icdb_completed = 0
|
||||
@@ -109,13 +113,26 @@ class MainWindow(QWidget):
|
||||
self.cbb_table.setSelectionBehavior(QTableWidget.SelectRows)
|
||||
self.cbb_table.setMinimumHeight(150)
|
||||
self.cbb_table.itemChanged.connect(lambda _item: self._update())
|
||||
self.search_edit = QLineEdit()
|
||||
self.search_edit.setPlaceholderText('按 CBB 名称或分区搜索')
|
||||
self.status_filter = QComboBox()
|
||||
for label, key in (('全部', 'all'), ('READY', 'ready'), ('非 READY(含未确认)', 'non_ready'),
|
||||
('PENDING', 'pending'), ('未知 / 读取异常', 'errors'), ('缺少工程', 'missing')):
|
||||
self.status_filter.addItem(label, key)
|
||||
self.counts_label = QLabel()
|
||||
self.select_visible_button = QPushButton('选择可见项')
|
||||
self.clear_selection_button = QPushButton('清空选择')
|
||||
self.select_visible_button.clicked.connect(lambda: self._check_visible(Qt.Checked))
|
||||
self.clear_selection_button.clicked.connect(lambda: self._check_visible(Qt.Unchecked))
|
||||
self.search_edit.textChanged.connect(self._apply_filters)
|
||||
self.status_filter.currentIndexChanged.connect(self._apply_filters)
|
||||
self.timeout_spin = QSpinBox(); self.timeout_spin.setRange(30, 1800); self.timeout_spin.setValue(DEFAULT_TIMEOUT_SECONDS); self.timeout_spin.setSuffix(' 秒 / 无进展')
|
||||
self.load_button = QPushButton('读取 CBB'); self.load_button.clicked.connect(self.load_library)
|
||||
self.browse_button = QPushButton('选择'); self.browse_button.clicked.connect(self.choose_library)
|
||||
self.selected_batch_button = QPushButton('批量校验已选'); self.selected_batch_button.clicked.connect(self.verify_selected)
|
||||
self.batch_button = QPushButton('批量校验全部 CBB'); self.batch_button.clicked.connect(self.verify_all)
|
||||
self.icdb_repair_button = QPushButton('全库 ICDB 检查与修复'); self.icdb_repair_button.clicked.connect(self.repair_icdb_all)
|
||||
self.icdb_repair_button.setToolTip('重新检查所有可用 CBB,包含 Ready 项;确认工程数据库失联后备份并尝试原生修复。')
|
||||
self.batch_button = QPushButton('校验可见非 READY'); self.batch_button.clicked.connect(self.verify_all)
|
||||
self.icdb_repair_button = QPushButton('非 READY ICDB 检查与修复'); self.icdb_repair_button.clicked.connect(self.repair_icdb_all)
|
||||
self.icdb_repair_button.setToolTip('检查可见非 READY 项;有勾选时仅处理其中可用项。未确认状态不等于损坏。')
|
||||
self.backup_restore_button = QPushButton('从备份恢复 CBB…')
|
||||
self.backup_restore_button.clicked.connect(self.restore_backup)
|
||||
self.stop_button = QPushButton('当前项完成后停止'); self.stop_button.clicked.connect(self.request_stop)
|
||||
@@ -144,6 +161,11 @@ class MainWindow(QWidget):
|
||||
layout = QFormLayout(self)
|
||||
row = QHBoxLayout(); row.addWidget(self.lmc_edit); row.addWidget(self.browse_button); row.addWidget(self.load_button)
|
||||
layout.addRow('中心库 .lmc', row); layout.addRow(self.advanced_toggle); layout.addRow(self.advanced_panel)
|
||||
filters = QHBoxLayout()
|
||||
for widget in (self.search_edit, self.status_filter, self.select_visible_button, self.clear_selection_button):
|
||||
filters.addWidget(widget)
|
||||
layout.addRow('搜索 / 筛选', filters)
|
||||
layout.addRow(self.counts_label)
|
||||
layout.addRow('CBB 清单(勾选后可批量)', self.cbb_table); layout.addRow('超时', self.timeout_spin)
|
||||
layout.addRow(QLabel('逐个刷新:命令行启动 ReusableCircuit PCB → Project Integration → 保存并关闭,全程不切换桌面、不移动鼠标。'
|
||||
'填写 LibSpec 与 DMS 登录配置后,会先执行一次 ReuseBlockImporter 内容检查。'))
|
||||
@@ -154,7 +176,7 @@ class MainWindow(QWidget):
|
||||
maintenance_layout = QVBoxLayout(maintenance)
|
||||
maintenance_row = QHBoxLayout()
|
||||
maintenance_row.addWidget(self.icdb_repair_button)
|
||||
description = QLabel('包含 Ready 项,逐个重新校验。确认工程数据库失联后,先备份再修复。\n共享符号库需另行处理;无法确认会话安全时停止。')
|
||||
description = QLabel('处理可见非 READY 项;有勾选时仅处理勾选中的可用项。未确认不等于损坏。\n确认工程数据库失联后先备份再修复;无法确认会话安全时停止。')
|
||||
description.setWordWrap(True)
|
||||
maintenance_row.addWidget(description, 1)
|
||||
maintenance_layout.addLayout(maintenance_row)
|
||||
@@ -179,6 +201,7 @@ class MainWindow(QWidget):
|
||||
if self.loaded_path is not None and self.lmc_edit.text() != self.loaded_path:
|
||||
self._release_library_lease()
|
||||
self.loaded_path = None; self.mentor_lmc_path = None; self.cbb_table.setRowCount(0); self._row_by_name = {}
|
||||
self._records_by_name = {}
|
||||
self.ready_names = set(); self.skipped_names = set(); self.skip_reasons = {}; self._update()
|
||||
self._global_icdb_run = False
|
||||
self.icdb_progress.hide(); self.icdb_phase.hide()
|
||||
@@ -197,19 +220,75 @@ class MainWindow(QWidget):
|
||||
# The refresh flow needs only the library and a CBB; LibSpec/DMS config
|
||||
# are optional and only enable the extra contents check.
|
||||
ready = not self.busy and self.loaded_path == self.lmc_edit.text() and self.cbb_table.rowCount() > 0
|
||||
self.batch_button.setEnabled(ready and any(self.cbb_table.item(row, 0).text() not in self.ready_names
|
||||
and self.cbb_table.item(row, 0).text() not in self.skipped_names
|
||||
for row in range(self.cbb_table.rowCount())))
|
||||
self.selected_batch_button.setEnabled(ready and bool(self._selected_names()))
|
||||
self.icdb_repair_button.setEnabled(ready and any(
|
||||
self.cbb_table.item(row, 0).text() not in self.skipped_names
|
||||
for row in range(self.cbb_table.rowCount())))
|
||||
self.backup_restore_button.setEnabled(ready)
|
||||
self.batch_button.setEnabled(ready and bool(self._eligible_names()))
|
||||
self.selected_batch_button.setEnabled(ready and bool(self._eligible_names(checked_only=True)))
|
||||
self.icdb_repair_button.setEnabled(ready and bool(self._maintenance_names()))
|
||||
self.backup_restore_button.setEnabled(ready and bool(self._maintenance_names()))
|
||||
for widget in (self.lmc_edit, self.browse_button, self.load_button, self.cbb_table,
|
||||
self.timeout_spin, self.advanced_toggle, self.advanced_panel):
|
||||
self.timeout_spin, self.advanced_toggle, self.advanced_panel,
|
||||
self.search_edit, self.status_filter, self.select_visible_button, self.clear_selection_button):
|
||||
widget.setEnabled(not self.busy)
|
||||
counts = self.visible_counts()
|
||||
self.counts_label.setText(f'可见 {counts["visible"]} / {len(self._records_by_name)} · '
|
||||
f'READY {counts["ready"]} · 异常/待确认 {counts["error"]}')
|
||||
self.stop_button.setEnabled(self.busy and self.loaded_path is not None and not self.stop.is_set())
|
||||
|
||||
def visible_records(self):
|
||||
"""Cached records in table order, restricted to the current local view."""
|
||||
return tuple(record for name, record in self._records_by_name.items()
|
||||
if not self.cbb_table.isRowHidden(self._row_by_name[name]))
|
||||
|
||||
def selected_records(self):
|
||||
"""Visible checked management records, including READY/missing projects."""
|
||||
return tuple(record for record in self.visible_records()
|
||||
if self.cbb_table.item(self._row_by_name[record.name], 0).checkState() == Qt.Checked)
|
||||
|
||||
def visible_counts(self):
|
||||
records = self.visible_records()
|
||||
return {'visible': len(records), 'ready': sum(r.status == 'READY' for r in records),
|
||||
'error': sum(r.status not in {'READY', 'PENDING'} or r.name in self.skipped_names
|
||||
for r in records)}
|
||||
|
||||
def _eligible_names(self, *, checked_only=False):
|
||||
records = self.selected_records() if checked_only else self.visible_records()
|
||||
return [r.name for r in records if r.status != 'READY' and r.name not in self.skipped_names]
|
||||
|
||||
def _maintenance_names(self):
|
||||
return self._eligible_names(checked_only=bool(self.selected_records()))
|
||||
|
||||
def _check_visible(self, state):
|
||||
self.cbb_table.blockSignals(True)
|
||||
try:
|
||||
for record in self.visible_records():
|
||||
self.cbb_table.item(self._row_by_name[record.name], 0).setCheckState(state)
|
||||
finally:
|
||||
self.cbb_table.blockSignals(False)
|
||||
self._update()
|
||||
|
||||
def _apply_filters(self, *_):
|
||||
keyword = self.search_edit.text().strip().casefold()
|
||||
mode = self.status_filter.currentData()
|
||||
self.cbb_table.blockSignals(True)
|
||||
self.cbb_table.setUpdatesEnabled(False)
|
||||
try:
|
||||
for name, record in self._records_by_name.items():
|
||||
matches = (not keyword or keyword in record.name.casefold()
|
||||
or keyword in record.partition_name.casefold())
|
||||
matches = matches and (mode == 'all'
|
||||
or mode == 'ready' and record.status == 'READY'
|
||||
or mode == 'non_ready' and record.status != 'READY'
|
||||
or mode == 'pending' and record.status == 'PENDING'
|
||||
or mode == 'errors' and record.status not in {'READY', 'PENDING'}
|
||||
or mode == 'missing' and name in self.skipped_names)
|
||||
row = self._row_by_name[name]
|
||||
if not matches:
|
||||
self.cbb_table.item(row, 0).setCheckState(Qt.Unchecked)
|
||||
self.cbb_table.setRowHidden(row, not matches)
|
||||
finally:
|
||||
self.cbb_table.setUpdatesEnabled(True)
|
||||
self.cbb_table.blockSignals(False)
|
||||
self._update()
|
||||
|
||||
def choose_library(self):
|
||||
path = QFileDialog.getOpenFileName(self, '选择中心库', '', 'LMC (*.lmc)')[0]
|
||||
if path: self.lmc_edit.setText(path); self.load_library()
|
||||
@@ -228,6 +307,7 @@ class MainWindow(QWidget):
|
||||
self.icdb_progress.hide(); self.icdb_phase.hide()
|
||||
self._release_library_lease()
|
||||
self.loaded_path = None; self.cbb_table.setRowCount(0); self._row_by_name = {}; self.ready_names = set()
|
||||
self._records_by_name = {}
|
||||
self.skipped_names = set(); self.skip_reasons = {}
|
||||
path = self.lmc_edit.text()
|
||||
self.status_label.setText('正在读取中心库…')
|
||||
@@ -281,6 +361,7 @@ class MainWindow(QWidget):
|
||||
self.ready_names = {r.name for r in result.records if r.status == 'READY' and r.name not in skip_reasons}
|
||||
self.skip_reasons = dict(skip_reasons)
|
||||
self.skipped_names = set(skip_reasons)
|
||||
self._records_by_name = {record.name: record for record in result.records}
|
||||
# Populating a large library emits itemChanged for every cell.
|
||||
# Block those signals and refresh controls once after the batch;
|
||||
# otherwise _update() repeatedly scans the growing table (O(n^2)).
|
||||
@@ -291,17 +372,15 @@ class MainWindow(QWidget):
|
||||
for row, record in enumerate(result.records):
|
||||
self._row_by_name[record.name] = row
|
||||
item = QTableWidgetItem(record.name)
|
||||
if record.status == 'READY' or record.name in self.skipped_names:
|
||||
# Already green: nothing left to verify, so it cannot be queued.
|
||||
item.setFlags(item.flags() & ~Qt.ItemIsUserCheckable)
|
||||
else:
|
||||
item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
|
||||
# Management selection includes READY and missing projects;
|
||||
# operation queues independently enforce eligibility.
|
||||
item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
|
||||
item.setCheckState(Qt.Unchecked)
|
||||
self.cbb_table.setItem(row, 0, item)
|
||||
self.cbb_table.setItem(row, 1, QTableWidgetItem(record.partition_name))
|
||||
status_text = STATUS_LABELS.get(record.status, record.status)
|
||||
if record.name in self.skipped_names:
|
||||
status_text = '跳过:缺少工程/PCB'
|
||||
status_text += ' · 缺少工程/PCB'
|
||||
self.cbb_table.setItem(row, 2, QTableWidgetItem(status_text))
|
||||
# Preflight touches each CBB's project and was previously run
|
||||
# synchronously in this GUI callback, making large libraries
|
||||
@@ -332,6 +411,7 @@ class MainWindow(QWidget):
|
||||
self.status_label.setText(
|
||||
f'已读取 {len(result.records)} 个 CBB,其中 Ready {ready_count} 个,'
|
||||
f'缺文件跳过 {len(self.skipped_names)} 个。{suffix}')
|
||||
self._apply_filters()
|
||||
self._start(read, loaded)
|
||||
|
||||
def _request(self, name):
|
||||
@@ -345,56 +425,58 @@ class MainWindow(QWidget):
|
||||
native_lm_verify=self.native_lm_verify_check.isChecked())
|
||||
|
||||
def _selected_names(self):
|
||||
names = []
|
||||
for row in range(self.cbb_table.rowCount()):
|
||||
item = self.cbb_table.item(row, 0)
|
||||
if item and item.checkState() == Qt.Checked and (item.flags() & Qt.ItemIsUserCheckable):
|
||||
names.append(item.text())
|
||||
return names
|
||||
return [record.name for record in self.selected_records()]
|
||||
|
||||
def verify_selected(self):
|
||||
self._run(self._selected_names())
|
||||
self._run(self._eligible_names(checked_only=True))
|
||||
|
||||
def verify_all(self):
|
||||
names = [self.cbb_table.item(row, 0).text() for row in range(self.cbb_table.rowCount())]
|
||||
self._run([name for name in names if name not in self.ready_names and name not in self.skipped_names])
|
||||
self._run(self._eligible_names())
|
||||
|
||||
def repair_icdb_all(self):
|
||||
if self.busy or not self.loaded_path: return
|
||||
names = [self.cbb_table.item(row, 0).text() for row in range(self.cbb_table.rowCount())
|
||||
if self.cbb_table.item(row, 0).text() not in self.skipped_names]
|
||||
names = self._maintenance_names()
|
||||
if not names: return
|
||||
answer = QMessageBox.question(self, '全库 ICDB 检查与修复',
|
||||
answer = QMessageBox.question(self, '非 READY ICDB 检查与修复',
|
||||
f'当前中心库:{self.loaded_path}\n\n'
|
||||
f'将检查 {len(names)} 个 CBB,其中 Ready {len(self.ready_names)} 个;'
|
||||
f'缺少工程文件跳过 {len(self.skipped_names)} 个。\n'
|
||||
f'将检查 {len(names)} 个可见非 READY CBB'
|
||||
f'{"(仅勾选项)" if self.selected_records() else ""}。未确认状态不等于损坏。\n'
|
||||
'操作会重新校验并保存工程。确认失联问题后,完整备份目标工程并尝试一次原生修复。\n'
|
||||
'共享符号库不支持自动修复。若原生工具恢复了旧备份,需人工核对版本;'
|
||||
'会话安全无法确认时停止队列。\n\n是否开始检查与修复?', QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
|
||||
if answer == QMessageBox.Yes:
|
||||
self._run(names, include_ready=True)
|
||||
self._run(names, maintenance=True)
|
||||
|
||||
def restore_backup(self):
|
||||
if self.busy or not self.loaded_path:
|
||||
return
|
||||
from .backup_recovery_dialog import BackupRecoveryDialog
|
||||
names = [self.cbb_table.item(row, 0).text() for row in range(self.cbb_table.rowCount())]
|
||||
names = self._maintenance_names()
|
||||
if not names:
|
||||
return
|
||||
self.backup_dialog = BackupRecoveryDialog(names, self._request, self)
|
||||
self.backup_dialog = BackupRecoveryDialog(names, self._backup_request, self)
|
||||
row = self.cbb_table.currentRow()
|
||||
if row >= 0:
|
||||
if row >= 0 and self.cbb_table.item(row, 0).text() in names:
|
||||
self.backup_dialog.block_combo.setCurrentText(self.cbb_table.item(row, 0).text())
|
||||
self.backup_dialog.started.connect(self._backup_started)
|
||||
self.backup_dialog.completed.connect(self._backup_completed)
|
||||
self.backup_dialog.finished.connect(lambda _code: self._finished())
|
||||
self.backup_dialog.finished.connect(lambda _code: self._backup_dialog_closed())
|
||||
self.backup_dialog.setModal(True)
|
||||
self.backup_dialog.show()
|
||||
|
||||
def _backup_request(self, name):
|
||||
# A still-open dialog must recheck a target after an earlier recovery
|
||||
# or an authoritative refresh changed its eligibility.
|
||||
if self.busy or name not in self._maintenance_names():
|
||||
raise ValueError('目标需为当前可见、可用的非 READY CBB;请重新选择。')
|
||||
return self._request(name)
|
||||
|
||||
def _backup_started(self, name):
|
||||
self.busy = True
|
||||
self._global_icdb_run = False
|
||||
self.ready_names.discard(name)
|
||||
if name in self._records_by_name:
|
||||
self._records_by_name[name] = replace(self._records_by_name[name], status='UNKNOWN')
|
||||
row = self._row_by_name.get(name)
|
||||
if row is not None:
|
||||
self.cbb_table.item(row, 2).setText('恢复中 / 需确认')
|
||||
@@ -413,27 +495,37 @@ class MainWindow(QWidget):
|
||||
self.cbb_table.item(row, 2).setText('未知 / 需确认')
|
||||
self._progress({'block': name, 'stage': result.status, 'detail': result.stderr,
|
||||
'evidence': str(result.evidence_path or '')})
|
||||
if result.safe_to_continue:
|
||||
self.busy = False
|
||||
self.refresh_affected_records([name])
|
||||
else:
|
||||
self._defer_status_refresh([name])
|
||||
|
||||
def _run(self, names, *, include_ready=False):
|
||||
def _backup_dialog_closed(self):
|
||||
if not getattr(self, '_refreshing_records', False):
|
||||
self._finished()
|
||||
|
||||
def _run(self, names, *, maintenance=False):
|
||||
if self.busy or not self.loaded_path: return
|
||||
names = [name for name in names if (include_ready or name not in self.ready_names) and name not in self.skipped_names]
|
||||
eligible = set(self._eligible_names())
|
||||
names = [name for name in names if name in eligible]
|
||||
if not names:
|
||||
self.status_label.setText('没有需要校验的 CBB(全部已经是绿色 / Ready)。')
|
||||
self.status_label.setText('当前可见选择中没有可校验的非 READY CBB。')
|
||||
self._update()
|
||||
return
|
||||
requests = [self._request(name) for name in names]
|
||||
self._global_icdb_run = include_ready
|
||||
self._global_icdb_run = maintenance
|
||||
self._icdb_completed = 0
|
||||
self.icdb_progress.setVisible(include_ready)
|
||||
self.icdb_phase.setVisible(include_ready)
|
||||
if include_ready:
|
||||
self.icdb_progress.setVisible(maintenance)
|
||||
self.icdb_phase.setVisible(maintenance)
|
||||
if maintenance:
|
||||
self.icdb_progress.setRange(0, len(requests))
|
||||
self.icdb_progress.setValue(0)
|
||||
self.icdb_progress.setFormat('已处理 %v / %m 个 CBB')
|
||||
self.icdb_phase.setText('准备检查…')
|
||||
self.stop.clear(); self.recovery_path = None; self.recovery_button.setEnabled(False)
|
||||
self.output.clear(); self.status_label.setText(
|
||||
f'正在全库 ICDB 检查与修复:共 {len(names)} 个 CBB' if include_ready
|
||||
f'正在非 READY ICDB 检查与修复:共 {len(names)} 个 CBB' if maintenance
|
||||
else f'正在校验:共 {len(names)} 个 CBB')
|
||||
def action():
|
||||
from cbb_refresh_verify.verify_runner import read_library_flag_if_available, run_verify
|
||||
@@ -441,18 +533,99 @@ class MainWindow(QWidget):
|
||||
req, progress=lambda e: self.signals.event.emit(e),
|
||||
flag_reader=read_library_flag_if_available))
|
||||
def verifier(req):
|
||||
if include_ready:
|
||||
if maintenance:
|
||||
self.signals.event.emit({'block': req.block_name, 'stage': 'icdb_check_start'})
|
||||
return verify(req)
|
||||
results = run_batch(requests, verifier=verifier, stop=self.stop,
|
||||
progress=lambda name, result: self.signals.event.emit({'block': name, 'stage': result.status, 'detail': result.stderr, 'evidence': str(result.evidence_path or '')}))
|
||||
report = write_batch_report(requests, results, self.data_root/'reports')
|
||||
if include_ready:
|
||||
if maintenance:
|
||||
from cbb_refresh_verify.icdb_maintenance import write_maintenance_report
|
||||
write_maintenance_report(requests, results, report, self.skipped_names)
|
||||
return results, report
|
||||
write_maintenance_report(requests, results, report, ())
|
||||
affected = [req.block_name for req, result in zip(requests, results) if result.status != 'SKIPPED']
|
||||
safe = all(result.safe_to_continue for result in results)
|
||||
refresh = self._read_affected_records(affected) if safe else None
|
||||
return results, report, affected, refresh
|
||||
self._start(action, self._batch_done)
|
||||
|
||||
def _read_affected_records(self, names):
|
||||
"""Worker-only read; never derive library state from action outcomes."""
|
||||
import pythoncom
|
||||
pythoncom.CoInitialize()
|
||||
try:
|
||||
path = Path(self.mentor_lmc_path or self.loaded_path)
|
||||
try:
|
||||
statuses = self.status_refresher(tuple(names), path)
|
||||
reasons = {name: reason for name in names
|
||||
if (reason := preflight_skip_reason(path, name))}
|
||||
return tuple(names), statuses, reasons, ''
|
||||
except Exception as error:
|
||||
return tuple(names), {}, None, str(error)
|
||||
finally:
|
||||
pythoncom.CoUninitialize()
|
||||
|
||||
def _apply_refreshed_records(self, payload):
|
||||
names, statuses, reasons, error = payload
|
||||
self.cbb_table.blockSignals(True)
|
||||
try:
|
||||
for name in names:
|
||||
if name not in self._records_by_name:
|
||||
continue
|
||||
status = statuses.get(name, 'UNKNOWN')
|
||||
if status not in STATUS_LABELS:
|
||||
status = 'UNKNOWN'
|
||||
self._records_by_name[name] = replace(self._records_by_name[name], status=status)
|
||||
self.ready_names.discard(name)
|
||||
if reasons is not None:
|
||||
self.skip_reasons.pop(name, None)
|
||||
if name in reasons:
|
||||
self.skip_reasons[name] = reasons[name]
|
||||
self.skipped_names = set(self.skip_reasons)
|
||||
row = self._row_by_name[name]
|
||||
text = STATUS_LABELS[status]
|
||||
if name in self.skipped_names:
|
||||
text += ' · 缺少工程/PCB'
|
||||
self.cbb_table.item(row, 2).setText(text)
|
||||
self.cbb_table.item(row, 2).setToolTip(error or self.skip_reasons.get(name, ''))
|
||||
if status == 'READY' and name not in self.skipped_names:
|
||||
self.ready_names.add(name)
|
||||
self._mark_row_ready(row)
|
||||
else:
|
||||
for column in range(self.cbb_table.columnCount()):
|
||||
self.cbb_table.item(row, column).setBackground(QColor('#FFF8E1'))
|
||||
finally:
|
||||
self.cbb_table.blockSignals(False)
|
||||
if error:
|
||||
self.output.append(f'状态复核未完成 / 需确认:{error}')
|
||||
self._apply_filters()
|
||||
return tuple(self._records_by_name[name] for name in names if name in self._records_by_name)
|
||||
|
||||
def _defer_status_refresh(self, names):
|
||||
self._apply_refreshed_records((tuple(names), {}, None,
|
||||
'会话或数据库安全未确认;暂缓原生状态复核,请确认释放后重新读取。'))
|
||||
|
||||
def refresh_affected_records(self, names, callback=None):
|
||||
"""Start an affected-only authoritative refresh once native owners release.
|
||||
|
||||
Return True if scheduled, False if busy/unloaded/empty. Callback receives
|
||||
tuple[CbbRecord, ...] on the GUI thread after applying refreshed statuses
|
||||
(UNKNOWN on read failure). It runs before the worker's finished signal.
|
||||
Search, filter, original logical_type and action-result cells are retained.
|
||||
"""
|
||||
if self.busy or not self.loaded_path:
|
||||
return False
|
||||
targets = tuple(dict.fromkeys(name for name in names if name in self._records_by_name))
|
||||
if not targets:
|
||||
return False
|
||||
self._refreshing_records = True
|
||||
def refreshed(payload):
|
||||
records = self._apply_refreshed_records(payload)
|
||||
self._refreshing_records = False
|
||||
if callback:
|
||||
callback(records)
|
||||
self._start(lambda: self._read_affected_records(targets), refreshed)
|
||||
return True
|
||||
|
||||
def _progress(self, event):
|
||||
line = f"{event.get('block', '')} | {event.get('stage', '')}"
|
||||
for key in ('detail', 'error', 'action', 'statuses', 'evidence'):
|
||||
@@ -474,40 +647,31 @@ class MainWindow(QWidget):
|
||||
if block and stage in {'PASS', 'FAIL', 'BLOCKED', 'TIMEOUT', 'SKIPPED'}:
|
||||
row = self._row_by_name.get(block)
|
||||
if row is not None:
|
||||
if stage == 'PASS':
|
||||
self.cbb_table.item(row, 2).setText('绿色 / Ready')
|
||||
self.cbb_table.item(row, 3).setText('PASS')
|
||||
self.ready_names.add(block)
|
||||
self._mark_row_ready(row)
|
||||
else:
|
||||
if getattr(self, '_global_icdb_run', False) and stage != 'SKIPPED':
|
||||
self.ready_names.discard(block)
|
||||
self.cbb_table.item(row, 2).setText('未知 / 需确认')
|
||||
item = self.cbb_table.item(row, 0)
|
||||
item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
|
||||
for column in range(self.cbb_table.columnCount()):
|
||||
self.cbb_table.item(row, column).setBackground(QColor('#FFF8E1'))
|
||||
detail = str(event.get('detail') or event.get('error') or '').strip()
|
||||
label = str(stage) if not detail else f'{stage}: {detail[:96]}'
|
||||
self.cbb_table.item(row, 3).setText(label)
|
||||
if detail:
|
||||
self.cbb_table.item(row, 3).setToolTip(detail)
|
||||
detail = str(event.get('detail') or event.get('error') or '').strip()
|
||||
label = str(stage) if not detail else f'{stage}: {detail[:96]}'
|
||||
self.cbb_table.item(row, 3).setText(label)
|
||||
self.cbb_table.item(row, 3).setToolTip(detail)
|
||||
if self.logging_context: self.logging_context.logger.info('cbb_progress %s', line)
|
||||
|
||||
def _mark_row_ready(self, row):
|
||||
"""Make a verified row visibly complete and remove it from the queue."""
|
||||
"""Color authoritative READY rows while retaining management selection."""
|
||||
name_item = self.cbb_table.item(row, 0)
|
||||
if name_item is None:
|
||||
return
|
||||
name_item.setCheckState(Qt.Unchecked)
|
||||
name_item.setFlags(name_item.flags() & ~Qt.ItemIsUserCheckable)
|
||||
name_item.setFlags(name_item.flags() | Qt.ItemIsUserCheckable)
|
||||
for column in range(self.cbb_table.columnCount()):
|
||||
cell = self.cbb_table.item(row, column)
|
||||
if cell is not None:
|
||||
cell.setBackground(QColor('#E8F5E9'))
|
||||
|
||||
def _batch_done(self, outcome):
|
||||
results, report = outcome
|
||||
results, report = outcome[:2]
|
||||
if len(outcome) > 2:
|
||||
_, _, affected, refresh = outcome
|
||||
if refresh is None:
|
||||
self._defer_status_refresh(affected)
|
||||
else:
|
||||
self._apply_refreshed_records(refresh)
|
||||
if self.library_lease is not None and any(not result.safe_to_continue for result in results):
|
||||
self.library_lease.retain_for_recovery()
|
||||
for result in results:
|
||||
@@ -522,22 +686,22 @@ class MainWindow(QWidget):
|
||||
if self._global_icdb_run:
|
||||
from cbb_refresh_verify.icdb_maintenance import maintenance_counts
|
||||
counts = maintenance_counts(results)
|
||||
text = ('全库 ICDB 检查已结束\n'
|
||||
f'校验通过 {passed},失败/受阻 {failed},队列未执行 {skipped},预检跳过 {len(self.skipped_names)}\n'
|
||||
text = ('非 READY ICDB 检查已结束\n'
|
||||
f'校验通过 {passed},失败/受阻 {failed},队列未执行 {skipped}\n'
|
||||
f'原生修复完成 {counts["repaired"]},恢复备份待复核 {counts["review_required"]},'
|
||||
f'修复未确认 {counts["repair_unconfirmed"]}\n'
|
||||
f'完整日志:{report}\n仅失败日志:{failure_report_path(report)}')
|
||||
self.icdb_phase.setText('已停止,存在待处理项目' if failed or skipped else '已完成全库检查')
|
||||
self.icdb_phase.setText('已停止,存在待处理项目' if failed or skipped else '已完成非 READY 检查')
|
||||
if any(not result.safe_to_continue for result in results):
|
||||
text += '\n未确认数据库或会话安全,已停止剩余校验。请查看恢复现场。'
|
||||
status_text = text
|
||||
if self._global_icdb_run:
|
||||
status_text = (f'全库检查结束:通过 {passed},失败/受阻 {failed},未执行 {skipped}。\n'
|
||||
status_text = (f'非 READY 检查结束:通过 {passed},失败/受阻 {failed},未执行 {skipped}。\n'
|
||||
f'原生修复 {counts["repaired"]},恢复备份待复核 {counts["review_required"]},'
|
||||
f'修复未确认 {counts["repair_unconfirmed"]}。')
|
||||
self.status_label.setText(status_text); self.output.append(text)
|
||||
self.summary = QMessageBox(self)
|
||||
self.summary.setWindowTitle('全库 ICDB 检查与修复结果' if self._global_icdb_run else 'CBB 校验结果'); self.summary.setText(text)
|
||||
self.summary.setWindowTitle('非 READY ICDB 检查与修复结果' if self._global_icdb_run else 'CBB 校验结果'); self.summary.setText(text)
|
||||
self.summary.setIcon(QMessageBox.Warning if failed else QMessageBox.Information)
|
||||
# Modeless notification: do not force activation or steal keyboard focus.
|
||||
from PySide6.QtCore import Qt
|
||||
|
||||
@@ -51,11 +51,12 @@ def test_backup_dialog_keeps_ui_responsive_and_cannot_close_during_restore(qtbot
|
||||
assert dialog.close_button.isEnabled()
|
||||
|
||||
|
||||
def test_main_window_opens_simple_dialog_and_failure_clears_ready(qtbot, tmp_path):
|
||||
def test_main_window_opens_non_ready_dialog_and_failure_retains_ready_untargeted(qtbot, tmp_path):
|
||||
from cbb_refresh_verify.ui.main_window import MainWindow
|
||||
from cbb_refresh_verify.library_reader import CbbRecord, LibraryReadResult
|
||||
window = MainWindow(reader=lambda _: LibraryReadResult((
|
||||
CbbRecord('A', 'LP', status='READY'), CbbRecord('B', 'LP'))), data_root=tmp_path)
|
||||
CbbRecord('A', 'LP', status='READY'), CbbRecord('B', 'LP'))), data_root=tmp_path,
|
||||
status_refresher=lambda names, _: {name: 'UNKNOWN' for name in names})
|
||||
qtbot.addWidget(window)
|
||||
window.lmc_edit.setText('lib.lmc'); window.load_library()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
@@ -63,12 +64,12 @@ def test_main_window_opens_simple_dialog_and_failure_clears_ready(qtbot, tmp_pat
|
||||
window.backup_restore_button.click()
|
||||
dialog = window.backup_dialog
|
||||
assert dialog.isVisible()
|
||||
assert dialog.block_combo.currentText() == 'A'
|
||||
dialog.started.emit('A')
|
||||
assert dialog.block_combo.currentText() == 'B'
|
||||
dialog.started.emit('B')
|
||||
assert window.busy
|
||||
assert 'A' not in window.ready_names
|
||||
dialog.completed.emit('A', VerifyResult('FAIL', stderr='损坏'))
|
||||
assert window.cbb_table.item(0, 2).text() == '未知 / 需确认'
|
||||
assert 'A' in window.ready_names
|
||||
dialog.completed.emit('B', VerifyResult('FAIL', stderr='无法确认', safe_to_continue=False))
|
||||
assert window.cbb_table.item(1, 2).text() == '未知 / 需确认'
|
||||
dialog.reject()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
|
||||
|
||||
+27
-17
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
os.environ.setdefault('QT_QPA_PLATFORM','offscreen')
|
||||
from cbb_refresh_verify.models import CbbRecord, LibraryReadResult
|
||||
@@ -21,7 +22,15 @@ def test_application_palette_keeps_table_text_readable(qtbot):
|
||||
|
||||
def fake_reader(_): return LibraryReadResult((CbbRecord('CBB1','Reusable Blocks'),))
|
||||
|
||||
def test_global_icdb_action_confirms_and_includes_ready_rows(qtbot, tmp_path, monkeypatch):
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def isolate_authoritative_native_refresh(monkeypatch):
|
||||
# Production refresh crosses the native Mentor boundary; these are UI tests.
|
||||
monkeypatch.setattr('cbb_refresh_verify.ui.main_window.authoritative_status_map',
|
||||
lambda names, *_: {name: 'READY' for name in names})
|
||||
|
||||
|
||||
def test_global_icdb_action_confirms_and_excludes_ready_rows(qtbot, tmp_path, monkeypatch):
|
||||
from PySide6.QtWidgets import QMessageBox
|
||||
calls = []
|
||||
window = MainWindow(reader=lambda _: LibraryReadResult((
|
||||
@@ -37,7 +46,7 @@ def test_global_icdb_action_confirms_and_includes_ready_rows(qtbot, tmp_path, mo
|
||||
monkeypatch.setattr(QMessageBox, 'question', lambda *a, **k: QMessageBox.Yes)
|
||||
window.icdb_repair_button.click()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
assert calls == ['READY', 'PENDING']
|
||||
assert calls == ['PENDING']
|
||||
|
||||
def test_global_icdb_action_disabled_without_library_or_while_busy(qtbot):
|
||||
window = MainWindow(reader=fake_reader)
|
||||
@@ -49,11 +58,11 @@ def test_global_icdb_action_disabled_without_library_or_while_busy(qtbot):
|
||||
window.busy = True; window._update()
|
||||
assert not window.icdb_repair_button.isEnabled()
|
||||
|
||||
def test_global_icdb_failure_clears_ready_and_stops_queue(qtbot, tmp_path, monkeypatch):
|
||||
def test_global_icdb_failure_preserves_untargeted_ready_and_stops_queue(qtbot, tmp_path, monkeypatch):
|
||||
from PySide6.QtWidgets import QMessageBox
|
||||
calls = []
|
||||
window = MainWindow(reader=lambda _: LibraryReadResult((
|
||||
CbbRecord('A', 'LP', status='READY'), CbbRecord('B', 'LP'))),
|
||||
CbbRecord('A', 'LP', status='READY'), CbbRecord('B', 'LP'), CbbRecord('C', 'LP'))),
|
||||
verifier=lambda req: (calls.append(req.block_name) or VerifyResult(
|
||||
'FAIL', stderr='unconfirmed', safe_to_continue=False)), data_root=tmp_path)
|
||||
qtbot.addWidget(window)
|
||||
@@ -62,10 +71,10 @@ def test_global_icdb_failure_clears_ready_and_stops_queue(qtbot, tmp_path, monke
|
||||
monkeypatch.setattr(QMessageBox, 'question', lambda *a, **k: QMessageBox.Yes)
|
||||
window.icdb_repair_button.click()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
assert calls == ['A']
|
||||
assert 'A' not in window.ready_names
|
||||
assert window.cbb_table.item(0, 2).text() == '未知 / 需确认'
|
||||
assert window.cbb_table.item(1, 3).text().startswith('SKIPPED')
|
||||
assert calls == ['B']
|
||||
assert 'A' in window.ready_names
|
||||
assert window.cbb_table.item(1, 2).text() == '未知 / 需确认'
|
||||
assert window.cbb_table.item(2, 3).text().startswith('SKIPPED')
|
||||
|
||||
def test_global_icdb_progress_and_repair_summary(qtbot, tmp_path, monkeypatch):
|
||||
from PySide6.QtWidgets import QMessageBox
|
||||
@@ -83,11 +92,11 @@ def test_global_icdb_progress_and_repair_summary(qtbot, tmp_path, monkeypatch):
|
||||
window.icdb_repair_button.click()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
assert 'lib.lmc' in confirmations[0]
|
||||
assert 'Ready' in confirmations[0]
|
||||
assert '非 READY' in confirmations[0]
|
||||
assert window.icdb_progress.value() == 1
|
||||
assert window.icdb_progress.maximum() == 1
|
||||
assert '恢复备份待复核 1' in window.status_label.text()
|
||||
assert window.summary.windowTitle() == '全库 ICDB 检查与修复结果'
|
||||
assert window.summary.windowTitle() == '非 READY ICDB 检查与修复结果'
|
||||
reports = list((tmp_path/'reports').glob('icdb-*.json'))
|
||||
assert len(reports) == 1
|
||||
|
||||
@@ -102,7 +111,7 @@ def test_ready_row_missing_project_is_skipped_by_global_maintenance(qtbot, tmp_p
|
||||
assert window.skipped_names == {'MISSING'}
|
||||
assert 'MISSING' not in window.ready_names
|
||||
assert not window.icdb_repair_button.isEnabled()
|
||||
assert window.cbb_table.item(0, 2).text().startswith('跳过')
|
||||
assert '缺少工程' in window.cbb_table.item(0, 2).text()
|
||||
|
||||
def test_verify_requires_loaded_library_and_invalidates_on_path_change(qtbot):
|
||||
window=MainWindow(reader=fake_reader, verifier=lambda _: VerifyResult('PASS')); qtbot.addWidget(window)
|
||||
@@ -156,8 +165,8 @@ def test_import_incomplete_rows_are_skipped_and_disabled(qtbot, tmp_path):
|
||||
window.lmc_edit.setText(str(lmc))
|
||||
window.load_library()
|
||||
qtbot.waitUntil(lambda: window.batch_button.isEnabled())
|
||||
assert window.cbb_table.item(0, 2).text().startswith('跳过:')
|
||||
assert not (window.cbb_table.item(0, 0).flags() & Qt.ItemIsUserCheckable)
|
||||
assert '缺少工程' in window.cbb_table.item(0, 2).text()
|
||||
assert window.cbb_table.item(0, 0).flags() & Qt.ItemIsUserCheckable
|
||||
window.verify_all()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
assert calls == ['VALID_CBB']
|
||||
@@ -218,7 +227,7 @@ def test_large_library_load_does_not_update_controls_for_every_table_cell(qtbot,
|
||||
assert window._row_by_name['CBB_0299'] == 299
|
||||
assert len(calls) < 20
|
||||
|
||||
def test_ready_rows_show_status_and_cannot_be_selected_or_verified(qtbot, tmp_path):
|
||||
def test_ready_rows_allow_management_selection_but_cannot_be_verified(qtbot, tmp_path):
|
||||
def reader(_):
|
||||
return LibraryReadResult((CbbRecord('READY_CBB', 'LP', status='READY'), CbbRecord('PENDING_CBB', 'LP', status='PENDING')))
|
||||
calls = []
|
||||
@@ -229,15 +238,16 @@ def test_ready_rows_show_status_and_cannot_be_selected_or_verified(qtbot, tmp_pa
|
||||
qtbot.waitUntil(lambda: window.batch_button.isEnabled())
|
||||
assert window.cbb_table.columnCount() == 4
|
||||
assert window.cbb_table.item(0, 2).text() == '绿色 / Ready'
|
||||
assert not (window.cbb_table.item(0, 0).flags() & Qt.ItemIsUserCheckable)
|
||||
assert window.cbb_table.item(0, 0).flags() & Qt.ItemIsUserCheckable
|
||||
assert window.cbb_table.item(0, 0).background().color().name().lower() == '#e8f5e9'
|
||||
window.cbb_table.item(0, 0).setCheckState(Qt.Checked)
|
||||
assert 'READY_CBB' not in window._selected_names()
|
||||
assert 'READY_CBB' in window._selected_names()
|
||||
assert not window.selected_batch_button.isEnabled()
|
||||
window.verify_all()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
assert calls == ['PENDING_CBB']
|
||||
assert window.cbb_table.item(1, 0).checkState() == Qt.Unchecked
|
||||
assert not (window.cbb_table.item(1, 0).flags() & Qt.ItemIsUserCheckable)
|
||||
assert window.cbb_table.item(1, 0).flags() & Qt.ItemIsUserCheckable
|
||||
assert window.cbb_table.item(1, 0).background().color().name().lower() == '#e8f5e9'
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,290 @@
|
||||
"""Local catalog scope and authoritative status refresh regression tests."""
|
||||
import json
|
||||
import time
|
||||
from threading import Event
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtWidgets import QMessageBox
|
||||
|
||||
from cbb_refresh_verify.models import CbbRecord, LibraryReadResult
|
||||
from cbb_refresh_verify.ui.main_window import MainWindow
|
||||
from cbb_refresh_verify.verify_runner import VerifyResult
|
||||
|
||||
|
||||
MIXED = (
|
||||
CbbRecord('Alpha', 'Power', status='READY'),
|
||||
CbbRecord('Beta', 'Power', status='PENDING'),
|
||||
CbbRecord('Gamma', 'Analog', status='UNKNOWN'),
|
||||
CbbRecord('Delta', 'Analog', status='ERROR'),
|
||||
CbbRecord('Missing', 'Power', status='READY'),
|
||||
)
|
||||
|
||||
|
||||
def load_window(qtbot, tmp_path, monkeypatch, records=MIXED, **kwargs):
|
||||
import cbb_refresh_verify.ui.main_window as ui
|
||||
monkeypatch.setattr(ui, 'preflight_skip_reason',
|
||||
lambda _, name: 'missing project' if name == 'Missing' else None)
|
||||
lease = SimpleNamespace(mentor_path=Path('test.lmc'), close=lambda: None,
|
||||
retain_for_recovery=lambda: None)
|
||||
window = MainWindow(reader=lambda _: LibraryReadResult(records), data_root=tmp_path,
|
||||
path_lease_factory=lambda _: lease, **kwargs)
|
||||
qtbot.addWidget(window)
|
||||
window.lmc_edit.setText('test.lmc')
|
||||
window.load_library()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
return window
|
||||
|
||||
|
||||
def names(records):
|
||||
return [record.name for record in records]
|
||||
|
||||
|
||||
def test_search_and_filters_use_cached_catalog_and_count_visible_states(qtbot, tmp_path, monkeypatch):
|
||||
window = load_window(qtbot, tmp_path, monkeypatch)
|
||||
window.reader = lambda _: pytest.fail('filter reread Mentor')
|
||||
assert window.visible_counts() == {'visible': 5, 'ready': 2, 'error': 3}
|
||||
expected = {
|
||||
'ready': ['Alpha', 'Missing'], 'non_ready': ['Beta', 'Gamma', 'Delta'],
|
||||
'pending': ['Beta'], 'errors': ['Gamma', 'Delta'], 'missing': ['Missing'],
|
||||
}
|
||||
for mode, wanted in expected.items():
|
||||
window.status_filter.setCurrentIndex(window.status_filter.findData(mode))
|
||||
assert names(window.visible_records()) == wanted
|
||||
window.status_filter.setCurrentIndex(window.status_filter.findData('all'))
|
||||
window.search_edit.setText(' ANALOG ')
|
||||
assert names(window.visible_records()) == ['Gamma', 'Delta']
|
||||
assert window.visible_counts() == {'visible': 2, 'ready': 0, 'error': 2}
|
||||
window.search_edit.setText('aLpH')
|
||||
assert names(window.visible_records()) == ['Alpha']
|
||||
assert '1' in window.counts_label.text()
|
||||
|
||||
|
||||
def test_management_selection_includes_ready_and_missing_but_hiding_clears_checks(qtbot, tmp_path, monkeypatch):
|
||||
window = load_window(qtbot, tmp_path, monkeypatch)
|
||||
window.select_visible_button.click()
|
||||
assert names(window.selected_records()) == ['Alpha', 'Beta', 'Gamma', 'Delta', 'Missing']
|
||||
assert window.selected_records()[0].logical_type == 'LP'
|
||||
window.search_edit.setText('power')
|
||||
assert names(window.selected_records()) == ['Alpha', 'Beta', 'Missing']
|
||||
window.search_edit.clear()
|
||||
assert names(window.selected_records()) == ['Alpha', 'Beta', 'Missing']
|
||||
window.clear_selection_button.click()
|
||||
assert window.selected_records() == ()
|
||||
|
||||
|
||||
def test_verify_all_and_selected_only_target_visible_non_ready_with_projects(qtbot, tmp_path, monkeypatch):
|
||||
calls = []
|
||||
window = load_window(qtbot, tmp_path, monkeypatch,
|
||||
verifier=lambda req: (calls.append(req.block_name) or VerifyResult('PASS')),
|
||||
status_refresher=lambda names, _: {name: 'READY' for name in names})
|
||||
window.search_edit.setText('power')
|
||||
window.select_visible_button.click()
|
||||
window.verify_selected()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
assert calls == ['Beta']
|
||||
window.search_edit.setText('analog')
|
||||
window.verify_all()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
assert calls == ['Beta', 'Gamma', 'Delta']
|
||||
|
||||
|
||||
def test_maintenance_confirmation_progress_and_report_use_visible_checked_subset(qtbot, tmp_path, monkeypatch):
|
||||
calls, confirmations, refreshes = [], [], []
|
||||
def refresh(targets, _):
|
||||
refreshes.append(tuple(targets))
|
||||
return {name: 'PENDING' for name in targets}
|
||||
window = load_window(qtbot, tmp_path, monkeypatch,
|
||||
verifier=lambda req: (calls.append(req.block_name) or VerifyResult('PASS')),
|
||||
status_refresher=refresh)
|
||||
window.search_edit.setText('analog')
|
||||
window.cbb_table.item(3, 0).setCheckState(Qt.Checked)
|
||||
monkeypatch.setattr(QMessageBox, 'question', lambda *args, **_: (
|
||||
confirmations.append(args[2]) or QMessageBox.Yes))
|
||||
window.repair_icdb_all()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
assert calls == ['Delta']
|
||||
assert refreshes == [('Delta',)]
|
||||
assert '1' in confirmations[0] and '非 READY' in confirmations[0]
|
||||
assert window.icdb_progress.maximum() == 1 and window.icdb_progress.value() == 1
|
||||
report = json.loads(next((tmp_path/'reports').glob('icdb-*.json')).read_text(encoding='utf-8'))
|
||||
assert report['includes_ready'] is False
|
||||
assert report['target_names'] == ['Delta']
|
||||
assert report['preflight_skipped'] == []
|
||||
assert report['counts']['total'] == 1
|
||||
assert window.search_edit.text() == 'analog'
|
||||
assert window.cbb_table.item(3, 3).text() == 'PASS'
|
||||
assert names(window.visible_records()) == ['Gamma', 'Delta']
|
||||
assert window.visible_records()[1].status == 'PENDING'
|
||||
|
||||
|
||||
def test_maintenance_defaults_to_visible_eligible_and_ready_only_checks_do_not_fallback(qtbot, tmp_path, monkeypatch):
|
||||
calls = []
|
||||
window = load_window(qtbot, tmp_path, monkeypatch,
|
||||
verifier=lambda req: (calls.append(req.block_name) or VerifyResult('PASS')),
|
||||
status_refresher=lambda targets, _: {name: 'PENDING' for name in targets})
|
||||
monkeypatch.setattr(QMessageBox, 'question', lambda *_, **__: QMessageBox.Yes)
|
||||
window.cbb_table.item(0, 0).setCheckState(Qt.Checked)
|
||||
window.repair_icdb_all()
|
||||
assert not window.busy and calls == []
|
||||
window.clear_selection_button.click()
|
||||
window.search_edit.setText('power')
|
||||
window.repair_icdb_all()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
assert calls == ['Beta']
|
||||
|
||||
|
||||
def test_recovery_defaults_to_visible_checked_non_ready_and_skips_ready(qtbot, tmp_path, monkeypatch):
|
||||
window = load_window(qtbot, tmp_path, monkeypatch)
|
||||
window.search_edit.setText('power')
|
||||
window.restore_backup()
|
||||
assert [window.backup_dialog.block_combo.itemText(i)
|
||||
for i in range(window.backup_dialog.block_combo.count())] == ['Beta']
|
||||
window.backup_dialog.reject()
|
||||
window.search_edit.clear()
|
||||
window.cbb_table.item(3, 0).setCheckState(Qt.Checked)
|
||||
window.restore_backup()
|
||||
assert window.backup_dialog.block_combo.currentText() == 'Delta'
|
||||
assert window.backup_dialog.block_combo.count() == 1
|
||||
window.backup_dialog.reject()
|
||||
|
||||
|
||||
def test_action_pass_does_not_promote_pending_without_authoritative_ready(qtbot, tmp_path, monkeypatch):
|
||||
entered = []
|
||||
window = load_window(qtbot, tmp_path, monkeypatch,
|
||||
status_refresher=lambda targets, _: (entered.extend(targets) or {'Beta': 'READY'}))
|
||||
window.status_filter.setCurrentIndex(window.status_filter.findData('pending'))
|
||||
window.cbb_table.item(1, 0).setCheckState(Qt.Checked)
|
||||
window._progress({'block': 'Beta', 'stage': 'PASS'})
|
||||
assert names(window.visible_records()) == ['Beta']
|
||||
assert window.visible_records()[0].status == 'PENDING'
|
||||
window.refresh_affected_records(['Beta'])
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
assert entered == ['Beta']
|
||||
assert window.visible_records() == ()
|
||||
assert window.selected_records() == ()
|
||||
assert window.status_filter.currentData() == 'pending'
|
||||
window.status_filter.setCurrentIndex(window.status_filter.findData('ready'))
|
||||
assert names(window.visible_records()) == ['Alpha', 'Beta', 'Missing']
|
||||
assert window.cbb_table.item(1, 3).text() == 'PASS'
|
||||
|
||||
|
||||
def test_refresh_failure_demotes_affected_without_losing_other_statuses(qtbot, tmp_path, monkeypatch):
|
||||
def fail(*_):
|
||||
raise OSError('bridge unavailable')
|
||||
window = load_window(qtbot, tmp_path, monkeypatch, status_refresher=fail)
|
||||
window.refresh_affected_records(['Alpha'])
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
assert window.visible_records()[0].status == 'UNKNOWN'
|
||||
assert window.visible_records()[1].status == 'PENDING'
|
||||
assert 'Alpha' not in window.ready_names
|
||||
assert 'bridge unavailable' in window.output.toPlainText()
|
||||
|
||||
|
||||
def test_unsafe_result_defers_native_refresh_and_retains_action_evidence(qtbot, tmp_path, monkeypatch):
|
||||
window = load_window(qtbot, tmp_path, monkeypatch,
|
||||
verifier=lambda _: VerifyResult('FAIL', stderr='owner release unconfirmed',
|
||||
safe_to_continue=False, evidence_path=tmp_path/'evidence.json'),
|
||||
status_refresher=lambda *_: pytest.fail('unsafe owner was reopened'))
|
||||
window.search_edit.setText('beta')
|
||||
window.verify_all()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
assert window.visible_records()[0].status == 'UNKNOWN'
|
||||
assert window.cbb_table.item(1, 3).text() == 'FAIL: owner release unconfirmed'
|
||||
assert str(tmp_path/'evidence.json') in window.output.toPlainText()
|
||||
assert '暂缓原生状态复核' in window.cbb_table.item(1, 2).toolTip()
|
||||
|
||||
|
||||
def test_refresh_callback_uses_only_known_affected_records_and_preserves_logical_type(qtbot, tmp_path, monkeypatch):
|
||||
observed, callbacks = [], []
|
||||
def refresh(targets, path):
|
||||
observed.append((targets, path))
|
||||
return {'X': 'READY'}
|
||||
window = load_window(qtbot, tmp_path, monkeypatch,
|
||||
records=(CbbRecord('X', 'Display label', logical_type='RULP', status='PENDING'),),
|
||||
status_refresher=refresh)
|
||||
assert window.refresh_affected_records(['unknown']) is False
|
||||
assert window.refresh_affected_records(['X', 'X', 'unknown'], callbacks.append) is True
|
||||
assert window.refresh_affected_records(['X']) is False
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
assert observed == [(('X',), Path('test.lmc'))]
|
||||
assert callbacks == [(CbbRecord('X', 'Display label', logical_type='RULP', status='READY'),)]
|
||||
|
||||
|
||||
def test_backup_completion_refreshes_status_without_dialog_close_unlocking_pending_refresh(qtbot, tmp_path, monkeypatch):
|
||||
entered, release = Event(), Event()
|
||||
def refresh(targets, _):
|
||||
entered.set()
|
||||
release.wait(3)
|
||||
return {name: 'PENDING' for name in targets}
|
||||
window = load_window(qtbot, tmp_path, monkeypatch, status_refresher=refresh)
|
||||
window.search_edit.setText('beta')
|
||||
window.restore_backup()
|
||||
window.backup_dialog.started.emit('Beta')
|
||||
window.backup_dialog.completed.emit('Beta', VerifyResult('PASS'))
|
||||
try:
|
||||
qtbot.waitUntil(entered.is_set)
|
||||
window.backup_dialog.reject()
|
||||
assert window.busy
|
||||
finally:
|
||||
release.set()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
assert window.visible_records()[0].status == 'PENDING'
|
||||
assert window.cbb_table.item(1, 3).text() == 'PASS'
|
||||
|
||||
|
||||
def test_missing_project_keeps_explicit_authoritative_status(qtbot, tmp_path, monkeypatch):
|
||||
window = load_window(qtbot, tmp_path, monkeypatch)
|
||||
assert 'Ready' in window.cbb_table.item(4, 2).text()
|
||||
assert '缺少工程' in window.cbb_table.item(4, 2).text()
|
||||
|
||||
|
||||
def test_open_backup_dialog_cannot_restore_target_that_became_ready(qtbot, tmp_path, monkeypatch):
|
||||
calls = []
|
||||
window = load_window(qtbot, tmp_path, monkeypatch,
|
||||
status_refresher=lambda targets, _: {name: 'READY' for name in targets})
|
||||
window.search_edit.setText('beta')
|
||||
window.restore_backup()
|
||||
dialog = window.backup_dialog
|
||||
source = tmp_path/'Beta.prj'
|
||||
source.touch()
|
||||
dialog.source_edit.setText(str(source))
|
||||
dialog.recoverer = lambda *_, **__: (calls.append('restore') or VerifyResult('PASS'))
|
||||
window.refresh_affected_records(['Beta'])
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
dialog.restore_button.click()
|
||||
qtbot.waitUntil(lambda: not dialog.busy)
|
||||
assert calls == []
|
||||
assert '非 READY' in dialog.status_label.text()
|
||||
dialog.reject()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('status', ['UNKNOWN', 'UNAVAILABLE', 'ERROR', 'TIMEOUT', 'MALFORMED', 'CRASHED',
|
||||
'UNRECOGNIZED'])
|
||||
def test_unconfirmed_statuses_are_non_ready_and_error_filter_candidates(qtbot, tmp_path, monkeypatch, status):
|
||||
window = load_window(qtbot, tmp_path, monkeypatch, records=(CbbRecord('X', 'LP', status=status),))
|
||||
window.status_filter.setCurrentIndex(window.status_filter.findData('non_ready'))
|
||||
assert names(window.visible_records()) == ['X']
|
||||
window.status_filter.setCurrentIndex(window.status_filter.findData('errors'))
|
||||
assert names(window.visible_records()) == ['X']
|
||||
|
||||
|
||||
@pytest.mark.parametrize('size', [381, 3000])
|
||||
def test_large_catalog_local_filter_and_selection_remain_responsive(qtbot, tmp_path, monkeypatch, size):
|
||||
records = tuple(CbbRecord(f'CBB{i:04}', 'Power' if i % 2 else 'Analog',
|
||||
status='READY' if i % 3 == 0 else 'PENDING') for i in range(size))
|
||||
start = time.perf_counter()
|
||||
window = load_window(qtbot, tmp_path, monkeypatch, records=records)
|
||||
loaded = time.perf_counter() - start
|
||||
window.reader = lambda _: pytest.fail('local actions reread Mentor')
|
||||
start = time.perf_counter()
|
||||
window.search_edit.setText('power')
|
||||
window.select_visible_button.click()
|
||||
window.status_filter.setCurrentIndex(window.status_filter.findData('pending'))
|
||||
window.clear_selection_button.click()
|
||||
elapsed = time.perf_counter() - start
|
||||
print(f'catalog rows={size} load={loaded:.3f}s local_actions={elapsed:.3f}s')
|
||||
assert elapsed < 2.0
|
||||
assert window.selected_records() == ()
|
||||
Reference in new issue
Block a user