feat: integrate independent background checks and native management UI
This commit is contained in:
1 parent
da67de026f
commit
282be7be7f
27 files changed
+4716
-932
No files matched your search
+45
-32
@@ -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,17 @@ 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):
|
||||
from PySide6.QtWidgets import QMessageBox
|
||||
monkeypatch.setattr(QMessageBox, 'question', lambda *a, **k: QMessageBox.Yes)
|
||||
# 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((
|
||||
@@ -36,8 +47,8 @@ def test_global_icdb_action_confirms_and_includes_ready_rows(qtbot, tmp_path, mo
|
||||
assert calls == []
|
||||
monkeypatch.setattr(QMessageBox, 'question', lambda *a, **k: QMessageBox.Yes)
|
||||
window.icdb_repair_button.click()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
assert calls == ['READY', 'PENDING']
|
||||
qtbot.waitUntil(lambda: not window._icdb_active())
|
||||
assert calls == ['PENDING']
|
||||
|
||||
def test_global_icdb_action_disabled_without_library_or_while_busy(qtbot):
|
||||
window = MainWindow(reader=fake_reader)
|
||||
@@ -49,11 +60,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)
|
||||
@@ -61,13 +72,13 @@ def test_global_icdb_failure_clears_ready_and_stops_queue(qtbot, tmp_path, monke
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
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')
|
||||
qtbot.waitUntil(lambda: not window._icdb_active())
|
||||
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() == '未检查'
|
||||
|
||||
def test_global_icdb_progress_and_repair_summary(qtbot, tmp_path, monkeypatch):
|
||||
def test_global_icdb_progress_and_check_summary(qtbot, tmp_path, monkeypatch):
|
||||
from PySide6.QtWidgets import QMessageBox
|
||||
confirmations = []
|
||||
def confirm(*args, **kwargs):
|
||||
@@ -81,13 +92,14 @@ def test_global_icdb_progress_and_repair_summary(qtbot, tmp_path, monkeypatch):
|
||||
window.lmc_edit.setText('lib.lmc'); window.load_library()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
window.icdb_repair_button.click()
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
qtbot.waitUntil(lambda: not window._icdb_active())
|
||||
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 '无法确认 1' in window.status_label.text()
|
||||
assert '恢复备份待复核' not in window.status_label.text()
|
||||
assert window.summary.windowTitle() == 'ICDB 批量检查结果'
|
||||
reports = list((tmp_path/'reports').glob('icdb-*.json'))
|
||||
assert len(reports) == 1
|
||||
|
||||
@@ -102,7 +114,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 +168,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 +230,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 +241,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'
|
||||
|
||||
|
||||
@@ -271,7 +284,7 @@ def test_unc_library_uses_mentor_path_for_read_and_verify_and_releases_on_close(
|
||||
assert calls == [lease.mentor_path]
|
||||
assert window._request('CBB1').lmc_file == lease.mentor_path
|
||||
window.close()
|
||||
assert lease.closed
|
||||
qtbot.waitUntil(lambda: lease.closed)
|
||||
|
||||
|
||||
def test_advanced_options_are_copied_to_verify_request(qtbot, tmp_path):
|
||||
@@ -340,12 +353,12 @@ def test_ui_default_timeout_matches_request_and_labels_inactivity(qtbot):
|
||||
assert window.timeout_spin.value() == 600
|
||||
assert window.timeout_spin.value() == VerifyRequest(Path('lib.lmc'), 'CBB1', Path('data')).timeout_seconds
|
||||
assert '无进展' in window.timeout_spin.suffix()
|
||||
|
||||
|
||||
def test_batch_summary_exposes_failures_only_report(qtbot, tmp_path):
|
||||
window = MainWindow(reader=fake_reader, data_root=tmp_path)
|
||||
qtbot.addWidget(window)
|
||||
report=tmp_path/'reports/batch-20260929-test.log'
|
||||
window._batch_done(([VerifyResult('FAIL',stderr='Mentor error')],report))
|
||||
assert '仅失败日志' in window.summary.text()
|
||||
assert str(report.with_name('failures-20260929-test.log')) in window.summary.text()
|
||||
|
||||
|
||||
def test_batch_summary_exposes_failures_only_report(qtbot, tmp_path):
|
||||
window = MainWindow(reader=fake_reader, data_root=tmp_path)
|
||||
qtbot.addWidget(window)
|
||||
report=tmp_path/'reports/batch-20260929-test.log'
|
||||
window._batch_done(([VerifyResult('FAIL',stderr='Mentor error')],report))
|
||||
assert '仅失败日志' in window.summary.detailedText()
|
||||
assert str(report.with_name('failures-20260929-test.log')) in window.summary.detailedText()
|
||||
Reference in new issue
Block a user