fix: reject native source renames before management writes

This commit is contained in:
阿白叔 committed 2026-11-17 01:22:57 +08:00
1 parent 36ff964230
commit d40fa3a750
7 files changed
+102 -20

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
"""EE7.9 imports by source PRJ name; reject rename before any native mutation."""
from dataclasses import replace
import pytest
from cbb_refresh_verify.management import ManagementRequest, run_management
from cbb_refresh_verify.native_management import NativeManagementAdapter
from test_management import project
@pytest.mark.parametrize('operation', ['add', 'update'])
def test_real_adapter_rejects_mismatched_source_before_native_catalog_or_remove(tmp_path, monkeypatch, operation):
library=tmp_path/'library/mentor.lmc';library.parent.mkdir();library.write_bytes(b'unchanged library')
target=project(library.parent/'ReusableBlocksLP/Block/Work','Block',b'unchanged target')
source=project(tmp_path/'source','Other')
adapter=NativeManagementAdapter()
monkeypatch.setattr(adapter,'_binary_capability',lambda:'')
calls=[]
monkeypatch.setattr(adapter,'_worker',lambda *args:calls.append(args) or pytest.fail('native boundary reached'))
request=ManagementRequest(operation,library,'Block',source=source,evidence_dir=tmp_path/'evidence')
result=run_management(request,adapter=adapter,idle_check=lambda *_:None)
assert result.safe_to_continue and 'SOURCE_NAME_MISMATCH' in result.detail
assert calls == []
assert library.read_bytes()==b'unchanged library'
assert (target.parent/'database/icdb.dat').read_bytes()==b'unchanged target'
def test_source_name_check_uses_windows_case_insensitive_identity(tmp_path):
source=project(tmp_path/'source','BLOCK')
request=ManagementRequest('update',tmp_path/'library.lmc','Block',source=source)
NativeManagementAdapter().validate_source(request)
def test_management_preview_reports_mismatch_and_allows_rechoose(qtbot,tmp_path,monkeypatch):
from PySide6.QtWidgets import QMessageBox
from cbb_refresh_verify.ui.management_dialog import ManagementDialog
from cbb_refresh_verify.ui import timed_prompt
wrong=project(tmp_path/'wrong','Other');right=project(tmp_path/'right','Block')
request=ManagementRequest('update',tmp_path/'library.lmc','Block',source=wrong)
dialog=ManagementDialog([request],adapter=NativeManagementAdapter())
qtbot.addWidget(dialog);dialog.show()
questions=[]
monkeypatch.setattr(timed_prompt,'question',lambda *a,**k:questions.append(a) or QMessageBox.No)
dialog.execute_button.click()
assert 'SOURCE_NAME_MISMATCH' in dialog.status_label.text()
assert not questions and dialog.execute_button.isEnabled()
dialog.table.item(0,2).setText(str(right))
dialog.execute_button.click()
assert len(questions)==1 and not dialog.busy