160 lines
8.7 KiB
Python
160 lines
8.7 KiB
Python
"""Batch ICDB checks open diagnostically without dispatching Repair."""
|
|
from dataclasses import replace
|
|
import json
|
|
|
|
import pytest
|
|
|
|
from test_maintenance_entry import case, no_native_launch
|
|
|
|
|
|
@pytest.mark.parametrize('scenario,status,category,safe', [
|
|
('healthy', 'CHECKED', '', True),
|
|
('fault', 'FAIL', 'ICDB_REPAIR_REQUIRED', True),
|
|
('generic', 'FAIL', 'MENTOR_DATABASE_LOAD_FAILED', True),
|
|
('unreleased', 'FAIL', 'MENTOR_DATABASE_LOAD_FAILED', False),
|
|
('cancelled', 'CANCELLED', '', True),
|
|
])
|
|
def test_batch_check_opens_pcb_without_repair(case, monkeypatch, scenario, status, category, safe):
|
|
from cbb_refresh_verify import verify_runner as runner, native_repair, maintenance_entry as entry
|
|
from test_icdb_open_check import NATIVE_ERROR
|
|
request, _, address = case
|
|
calls = []
|
|
def open_pcb(probe, **kwargs):
|
|
assert probe.diagnostic_only and not probe.maintenance and not probe.auto_repair
|
|
calls.append('open')
|
|
return runner.VerifyResult('PASS' if scenario=='healthy' else 'CANCELLED' if scenario=='cancelled' else 'FAIL',
|
|
stderr=NATIVE_ERROR if scenario=='fault' else '' if scenario in ('healthy','cancelled') else 'Failed to open document.',
|
|
error_category='' if scenario in ('healthy','cancelled') else 'MENTOR_DATABASE_LOAD_FAILED',
|
|
safe_to_continue=scenario!='unreleased')
|
|
monkeypatch.setattr(runner,'_run_verify_serialized',open_pcb)
|
|
monkeypatch.setattr(native_repair,'run_native_repair',lambda *a,**k:pytest.fail('scan requested Project Backup'))
|
|
monkeypatch.setattr(entry,'assert_native_idle',lambda:pytest.fail('scan used host-wide owner gate'))
|
|
result=runner.run_verify(replace(request,auto_repair=True))
|
|
assert calls==['open']
|
|
assert (result.status,result.error_category,result.safe_to_continue)==(status,category,safe)
|
|
assert result.library_flag=='UNKNOWN' and result.recovery_attempts==()
|
|
assert address.read_bytes()==b'old server address - preserved'
|
|
record=json.loads(result.evidence_path.read_text('utf-8'))
|
|
assert record['operation']=='icdb_batch_check' and record['automatic_repair'] is False
|
|
|
|
|
|
@pytest.mark.parametrize('before_launch',[True,False])
|
|
def test_cancellation_never_dispatches_repair_or_reports_a_clean_check(case,monkeypatch,before_launch):
|
|
from threading import Event
|
|
from cbb_refresh_verify import verify_runner as runner
|
|
request,_,_=case
|
|
stop=Event();calls=[]
|
|
if before_launch:stop.set()
|
|
def open_pcb(probe,**kwargs):
|
|
calls.append('open');stop.set()
|
|
return runner.VerifyResult('PASS')
|
|
monkeypatch.setattr(runner,'_run_verify_serialized',open_pcb)
|
|
result=runner.run_verify(request,stop=stop)
|
|
assert result.status=='CANCELLED' and result.safe_to_continue
|
|
assert calls==([] if before_launch else ['open'])
|
|
|
|
|
|
def test_released_icdb_fault_continues_the_check_batch(case,monkeypatch):
|
|
from cbb_refresh_verify import verify_runner as runner
|
|
from test_icdb_open_check import NATIVE_ERROR
|
|
request,_,_=case
|
|
calls=[]
|
|
def open_pcb(probe,**kwargs):
|
|
calls.append('open')
|
|
return runner.VerifyResult('FAIL',stderr=NATIVE_ERROR) if len(calls)==1 else runner.VerifyResult('PASS')
|
|
monkeypatch.setattr(runner,'_run_verify_serialized',open_pcb)
|
|
results=runner.run_batch([request,request])
|
|
assert calls==['open','open']
|
|
assert [result.status for result in results]==['FAIL','CHECKED']
|
|
|
|
|
|
def test_inspection_ignores_other_pcb_and_skips_exclusive_repair_probe(tmp_path, monkeypatch):
|
|
import win32con
|
|
from test_native_repair import repair_worker_fixture
|
|
from test_native_occupancy import output
|
|
ui, root, job, actions = repair_worker_fixture(tmp_path, monkeypatch, 'active')
|
|
data = json.loads(job.read_text('utf-8')); data['inspection_only'] = True
|
|
job.write_text(json.dumps(data), encoding='utf-8')
|
|
monkeypatch.setattr('cbb_refresh_verify.mentor_adapter.pcb_processes', lambda: [(999, 'other.pcb', '')])
|
|
monkeypatch.setattr('cbb_refresh_verify.native_repair.check_repair_access',
|
|
lambda *a: pytest.fail('inspection used exclusive Repair admission'))
|
|
monkeypatch.setattr(ui, '_repair_command', lambda *a: pytest.fail('inspection resolved Repair command'))
|
|
monkeypatch.setattr(ui, '_native_output', lambda *_: output(data['project'], data['database'], busy=True))
|
|
assert ui.repair_worker_main(job) == 0
|
|
assert actions == [(100, win32con.WM_CLOSE)]
|
|
|
|
|
|
def test_ui_check_summary_reports_findings_and_never_claims_repair(qtbot, tmp_path, monkeypatch):
|
|
from test_ui_filters import load_window
|
|
from cbb_refresh_verify.verify_runner import VerifyResult
|
|
from PySide6.QtWidgets import QMessageBox
|
|
requests, prompts = [], []
|
|
window = load_window(qtbot, tmp_path, monkeypatch,
|
|
verifier=lambda req: (requests.append(req) or VerifyResult('FAIL',
|
|
error_category='ICDB_REPAIR_REQUIRED', stderr='发现 ICDB 问题,未执行修复。')),
|
|
status_refresher=lambda names, _: {name: 'PENDING' for name in names})
|
|
monkeypatch.setattr(QMessageBox, 'question', lambda *a, **k: (prompts.append(a[2]) or QMessageBox.Yes))
|
|
window.search_edit.setText('Beta')
|
|
window.icdb_repair_button.click(); qtbot.waitUntil(lambda: not window._icdb_active())
|
|
assert requests[0].maintenance and not requests[0].auto_repair
|
|
assert '批量检查' in window.icdb_repair_button.text()
|
|
assert not any('手动备份' in text for text in prompts)
|
|
assert window.summary.windowTitle() == 'ICDB 批量检查结果'
|
|
assert '发现问题 1' in window.summary.text()
|
|
assert '修复并校验通过' not in window.summary.detailedText()
|
|
|
|
|
|
@pytest.mark.parametrize('category,label', [('ICDB_DATABASE_IN_USE', '占用 1'),
|
|
('ICDB_INSPECTION_UNCONFIRMED', '无法确认 1')])
|
|
def test_busy_or_unknown_inspection_is_not_labelled_as_database_damage(qtbot, tmp_path, monkeypatch, category, label):
|
|
from test_ui_filters import load_window
|
|
from cbb_refresh_verify.verify_runner import VerifyResult
|
|
window = load_window(qtbot, tmp_path, monkeypatch,
|
|
verifier=lambda _: VerifyResult('FAIL', error_category=category, stderr='暂未完成检查。'),
|
|
status_refresher=lambda names, _: {name: 'PENDING' for name in names})
|
|
window.search_edit.setText('Beta')
|
|
window.icdb_repair_button.click(); qtbot.waitUntil(lambda: not window._icdb_active())
|
|
assert label in window.summary.text()
|
|
assert 'ICDB 问题' not in window.cbb_table.item(window._row_by_name['Beta'], 3).text()
|
|
|
|
|
|
def test_missing_pcb_is_skipped_from_icdb_batch_check_and_restore(qtbot, tmp_path, monkeypatch):
|
|
from test_ui_filters import load_window
|
|
from cbb_refresh_verify.models import CbbRecord
|
|
from cbb_refresh_verify.verify_runner import VerifyResult
|
|
calls = []
|
|
window = load_window(qtbot, tmp_path, monkeypatch,
|
|
records=(CbbRecord('Missing', 'Power', status='PENDING'),),
|
|
verifier=lambda req: (calls.append(req.block_name) or VerifyResult('CHECKED')),
|
|
status_refresher=lambda names, _: {name: 'PENDING' for name in names})
|
|
assert not window.icdb_repair_button.isEnabled()
|
|
assert not window.batch_button.isEnabled() and not window.backup_restore_button.isEnabled()
|
|
assert calls == []
|
|
|
|
|
|
def test_missing_project_rows_are_excluded_from_icdb_batch_check(qtbot, tmp_path, monkeypatch):
|
|
from test_ui_filters import load_window
|
|
from cbb_refresh_verify.models import CbbRecord
|
|
from cbb_refresh_verify.verify_runner import VerifyResult
|
|
window = load_window(qtbot, tmp_path, monkeypatch,
|
|
records=(CbbRecord('Missing', 'Power', status='PENDING'),
|
|
CbbRecord('Good', 'Power', status='PENDING')),
|
|
verifier=lambda req: VerifyResult('CHECKED'),
|
|
status_refresher=lambda names, _: {name: 'PENDING' for name in names})
|
|
window.skipped_names.add('Missing')
|
|
window._update()
|
|
assert window._maintenance_names() == ['Good']
|
|
|
|
|
|
def test_check_reports_describe_inspection_without_pcb_verification(case, tmp_path):
|
|
from cbb_refresh_verify.verify_runner import write_batch_report, failure_report_path, VerifyResult
|
|
request, _, _ = case
|
|
report = write_batch_report([request], [VerifyResult('FAIL',
|
|
error_category='ICDB_REPAIR_REQUIRED', stderr='发现 ICDB 问题,未执行修复。')], tmp_path/'reports')
|
|
full = report.read_text('utf-8-sig')
|
|
failed = failure_report_path(report).read_text('utf-8-sig')
|
|
assert 'ICDB 批量检查' in full and 'Project Integration' not in full
|
|
assert 'PCB 打开检查' in full and 'Project Backup 加载检查' not in full
|
|
assert 'ICDB 检查异常' in failed and '发现问题: 1' in failed
|
|
assert 'ICDB已修复待校验' not in failed
|