Files
cbb-refresh-verify-795/tests/test_issue15_native_source_name.py

70 lines
3.5 KiB
Python

"""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
def test_source_name_preview_does_not_resolve_files_on_gui_thread(qtbot,tmp_path,monkeypatch):
from pathlib import Path
from PySide6.QtWidgets import QMessageBox
from cbb_refresh_verify.ui.management_dialog import ManagementDialog
from cbb_refresh_verify.ui import timed_prompt
source=project(tmp_path/'source','Block')
request=ManagementRequest('update',tmp_path/'library.lmc','Block',source=source)
dialog=ManagementDialog([request],adapter=NativeManagementAdapter())
qtbot.addWidget(dialog);dialog.show()
original=Path.resolve
def resolve(path,*args,**kw):
assert path!=source,'GUI preview touched potentially stalled source metadata'
return original(path,*args,**kw)
monkeypatch.setattr(Path,'resolve',resolve)
questions=[]
monkeypatch.setattr(timed_prompt,'question',lambda *a,**k:questions.append(a) or QMessageBox.No)
dialog._execute()
assert len(questions)==1