fix: admit linked legacy ICDB projects and explain blocked actions

This commit is contained in:
阿白叔 committed 2026-11-03 13:51:05 +08:00
1 parent 5eac654c36
commit d36b6bcad0
8 files changed
+138 -18

No files matched your search

+3 -1
View File
@@ -209,7 +209,9 @@ def test_real_windows_job_abort_preserves_native_like_child(tmp_path):
script.write_text(
'import subprocess, sys, time\nfrom pathlib import Path\n'
'child = subprocess.Popen([sys.executable, "-c", "import time; time.sleep(30)"])\n'
f'Path({str(pid_path)!r}).write_text(str(child.pid))\n'
f'pid_file = Path({str(pid_path)!r})\n'
'pending = pid_file.with_suffix(".pending")\n'
'pending.write_text(str(child.pid)); pending.replace(pid_file)\n'
'time.sleep(30)\n', encoding='utf-8')
worker = DesktopWorker([sys.executable, str(script)], 'CbbSafetyTest_' + uuid.uuid4().hex[:8])
child_handle = None
+39 -1
View File
@@ -46,10 +46,13 @@ def case(tmp_path, monkeypatch):
if owner: owner['handle'].Close()
def test_explicit_maintenance_enters_official_repair_once_without_lostsession_fabrication(case, monkeypatch):
@pytest.mark.parametrize('pcb_config', ['standard', 'legacy_template'])
def test_explicit_maintenance_enters_official_repair_once_without_lostsession_fabrication(case, monkeypatch, pcb_config):
from cbb_refresh_verify import verify_runner as runner, native_repair
from test_native_repair import complete_native_success
request, project, address = case
if pcb_config == 'legacy_template':
(project.parent/'PCB/pcb.prj').rename(project.parent/'PCB/template.prj')
calls = []
def repair(target, root, **kwargs):
calls.append('repair')
@@ -79,6 +82,40 @@ def test_explicit_maintenance_enters_official_repair_once_without_lostsession_fa
assert 'session' not in record['maintenance_context']
@pytest.mark.parametrize('back_reference', ['', 'KEY ProjectFile "../other.prj"\n',
'KEY ProjectFile "../IP101GR.prj"\nKEY ProjectFile "../IP101GR.prj"\n'])
def test_legacy_maintenance_requires_unambiguous_pcb_back_reference(case, back_reference):
from cbb_refresh_verify.maintenance_entry import select_maintenance_target
request, project, _ = case
(project.parent/'PCB/pcb.prj').rename(project.parent/'PCB/template.prj')
(project.parent/'PCB/IP101GR.pcb').write_text(back_reference)
with pytest.raises(ValueError, match='MAINTENANCE_TARGET_UNCONFIRMED'):
select_maintenance_target(request)
def test_legacy_target_does_not_guess_template_for_physical_address(case):
from cbb_refresh_verify.maintenance_entry import select_maintenance_target
request, project, address = case
(project.parent/'PCB/pcb.prj').rename(project.parent/'PCB/template.prj')
address.unlink()
physical = project.parent/'PCB/database/cdbsvr/sAddress.adr'
physical.parent.mkdir(parents=True); physical.write_bytes(b'physical owner')
with pytest.raises(ValueError, match='SHARED_DATABASE_REPAIR_UNSUPPORTED'):
select_maintenance_target(request)
def test_optional_pcb_project_appearance_invalidates_maintenance_proof(case):
from cbb_refresh_verify.maintenance_entry import maintenance_target_guard
request, project, _ = case
config = project.parent/'PCB/pcb.prj'
config.rename(config.with_name('template.prj'))
with maintenance_target_guard(request) as proof:
before = proof['context']
config.write_text('KEY CentralLibrary "different.lmc"\n')
with pytest.raises(ValueError, match='MAINTENANCE_SOURCE_CHANGED'):
with maintenance_target_guard(request, before): pass
def test_ordinary_verify_still_blocks_existing_address_without_repair(case, monkeypatch):
from cbb_refresh_verify import verify_runner as runner, native_repair
request, _, address = case
@@ -114,6 +151,7 @@ def test_maintenance_guard_blocks_before_native(case, monkeypatch, obstacle):
try:
result = runner.run_verify(request)
assert result.status == 'BLOCKED' and not result.safe_to_continue
assert result.error_stage == 'preflight'
finally:
if handle: handle.Close()
+14
View File
@@ -53,6 +53,8 @@ def test_blocked_library_recovery_view_is_filesystem_only_and_maintenance_only(q
assert window.visible_records()[0].name == 'IP101GR'
assert window.visible_records()[0].status == 'UNKNOWN'
assert '未确认' in window.status_label.text()
assert 'ICDB' in window.management_capability_label.text()
assert '会话' in window.add_button.toolTip()
window.select_visible_button.click()
assert window.icdb_repair_button.isEnabled()
assert not any(button.isEnabled() for button in (window.batch_button, window.selected_batch_button,
@@ -65,6 +67,18 @@ def test_blocked_library_recovery_view_is_filesystem_only_and_maintenance_only(q
assert len(calls) == 1 and calls[0].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.text()
assert detail in window.status_label.text()
def test_safe_maintenance_reloads_authoritative_catalog_after_worker_finishes(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
+6 -1
View File
@@ -95,9 +95,14 @@ def test_prelaunch_proof_blocks_without_launch(context, monkeypatch, obstacle):
if handle: handle.Close()
def test_exact_dialog_after_bound_prelaunch_is_allowed_only_once(context, monkeypatch):
@pytest.mark.parametrize('pcb_config', ['standard', 'legacy_template'])
def test_exact_dialog_after_bound_prelaunch_is_allowed_only_once(context, monkeypatch, pcb_config):
from cbb_refresh_verify import post_repair_consent as consent
_, _, proof, job = context
if pcb_config == 'legacy_template':
pcb = Path(job['pcb'])
(pcb.parent/'pcb.prj').rename(pcb.parent/'template.prj')
pcb.write_text('KEY ProjectFile "../'+Path(job['project']).name+'"\n')
command = ['C:/Mentor/common/win32/bin/ExpeditionPCB.exe', job['pcb'], '-ReusableCircuit']
consent.prepare_launch(job, command)
controller = consent.ConsentController(proof, job)