76 lines
3.8 KiB
Python
76 lines
3.8 KiB
Python
import json
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from PySide6.QtCore import Qt
|
|
from PySide6.QtWidgets import QMessageBox
|
|
|
|
|
|
def test_only_confirmed_maintenance_sets_explicit_flag(qtbot, tmp_path, monkeypatch):
|
|
from test_ui_filters import load_window
|
|
from cbb_refresh_verify.verify_runner import VerifyResult
|
|
calls = []
|
|
window = load_window(qtbot, tmp_path, monkeypatch,
|
|
verifier=lambda req: (calls.append(req) or VerifyResult('FAIL', safe_to_continue=True)),
|
|
status_refresher=lambda names, path: {name: 'PENDING' for name in names})
|
|
window.search_edit.setText('Beta')
|
|
window.verify_all(); qtbot.waitUntil(lambda: not window.busy)
|
|
assert calls and calls[-1].maintenance is False
|
|
monkeypatch.setattr(QMessageBox, 'question', lambda *a, **k: QMessageBox.No)
|
|
window.repair_icdb_all(); assert len(calls) == 1
|
|
monkeypatch.setattr(QMessageBox, 'question', lambda *a, **k: QMessageBox.Yes)
|
|
window.repair_icdb_all(); qtbot.waitUntil(lambda: not window._icdb_active())
|
|
assert len(calls) == 2 and calls[-1].maintenance is True
|
|
|
|
|
|
|
|
|
|
def test_maintenance_summary_exposes_first_failure_reason(qtbot, tmp_path):
|
|
from cbb_refresh_verify.ui.main_window import MainWindow
|
|
from cbb_refresh_verify.verify_runner import VerifyResult
|
|
window = MainWindow(data_root=tmp_path)
|
|
qtbot.addWidget(window)
|
|
window._global_icdb_run = True
|
|
detail = 'MAINTENANCE_TARGET_UNCONFIRMED: PCB 引用与当前工程不一致'
|
|
window._batch_done(([VerifyResult('BLOCKED', stderr=detail, safe_to_continue=False)], tmp_path/'batch.log'))
|
|
assert detail in window.summary.detailedText()
|
|
assert detail in window.output.toPlainText()
|
|
assert detail not in window.summary.text()
|
|
assert str(tmp_path) not in window.summary.text()
|
|
assert detail not in window.status_label.text()
|
|
assert '无法确认 1' in window.summary.text()
|
|
|
|
|
|
def test_open_check_preserves_verify_state_without_starting_an_extra_catalog_read(qtbot, tmp_path, monkeypatch):
|
|
from cbb_refresh_verify.library_lock import LibraryLock, blocker_path, _owners, _guard
|
|
from cbb_refresh_verify.ui.main_window import MainWindow
|
|
from cbb_refresh_verify.models import LibraryReadResult, CbbRecord
|
|
from cbb_refresh_verify.verify_runner import VerifyResult
|
|
import cbb_refresh_verify.ui.main_window as ui
|
|
library = tmp_path/'library/mentor.lmc'; library.parent.mkdir(); library.touch()
|
|
(library.parent/'ReusableBlocksLP/IP101GR').mkdir(parents=True)
|
|
with LibraryLock(library, safe_to_release=lambda: False) as lease: pass
|
|
with _guard:
|
|
owner = _owners.pop(lease.key, None)
|
|
if owner: owner['handle'].Close()
|
|
reads = []
|
|
def reader(path):
|
|
reads.append(path)
|
|
return LibraryReadResult((CbbRecord('IP101GR', 'Reusable Blocks', status='PENDING'),))
|
|
def verify(req):
|
|
assert req.maintenance
|
|
blocker_path(library).unlink() # Simulate normal cleanup at the injected boundary.
|
|
return VerifyResult('CHECKED')
|
|
monkeypatch.setattr(ui, 'preflight_skip_reason', lambda *a: None)
|
|
monkeypatch.setattr(QMessageBox, 'question', lambda *a, **k: QMessageBox.Yes)
|
|
window = MainWindow(reader=reader, verifier=verify, data_root=tmp_path/'data',
|
|
status_refresher=lambda *a: pytest.fail('An open check must not start a second native status read'))
|
|
qtbot.addWidget(window)
|
|
window.lmc_edit.setText(str(library)); window.load_library(); qtbot.waitUntil(lambda: not window.busy)
|
|
assert len(reads) == 1
|
|
window.search_edit.setText('IP101')
|
|
window.repair_icdb_all()
|
|
qtbot.waitUntil(lambda: not window._icdb_active())
|
|
assert window.visible_records()[0].status == 'PENDING' and len(reads) == 1
|
|
assert not window._maintenance_recovery_view and window.search_edit.text() == 'IP101'
|