9e07fac1db
Per post_module_taxonomy_de_cruft_20260627 Phase 2 (FR7 continued).
The previous migration commit (8f11340b) handled the
'from src.models import X' pattern (85 sites). This commit handles
the 'models.<moved_class>' attribute access pattern (44 sites in 20
files), which the __getattr__ shim previously supported.
The migration was performed by the one-time script
scripts/tier2/artifacts/post_module_taxonomy_de_cruft_20260627/migrate_models_attr.py
which:
1. For each 'models.<moved_class>' reference, replaces it with the
bare class name (e.g., 'models.MCPConfiguration' -> 'MCPConfiguration')
2. Adds the import 'from src.<destination> import <moved_class>' at
the top of the file (deduplicated if the import already exists)
3. Skips moved classes that the file already imports directly
The migration script inserts the import after the 'from __future__
import annotations' line if present; otherwise it adds the import
to the destination module's existing import block. Two files
required manual fixes because the script's regex didn't handle them:
- src/rag_engine.py: uses 'from src import models' (not 'from
src.models import X'); the class is accessed
via 'models.RAGConfig'. Replaced with a
direct 'from src.mcp_client import RAGConfig'
import and removed the 'from src import models'.
- tests/test_project_context_20260627.py: uses the parens-style
multi-line 'from src.models import (X, Y, Z)'.
Replaced with the parens-style direct import.
After this commit:
- 'models.MCPConfiguration', 'models.FileItem', 'models.Ticket', etc.
no longer work in src/ and tests/ (the AttributeError raises
because models.py no longer has the __getattr__ entries for
moved classes)
- All consumer files have direct imports of the moved classes
Total: 44 'models.<moved_class>' references rewritten across 20 files.
109 lines
4.1 KiB
Python
109 lines
4.1 KiB
Python
import pytest
|
|
from unittest.mock import MagicMock, patch, mock_open
|
|
from src.gui_2 import App
|
|
from src import models
|
|
|
|
@pytest.fixture
|
|
def mock_app():
|
|
with (
|
|
patch('src.app_controller.AppController.load_config', return_value={
|
|
"ai": {"provider": "gemini", "model": "model-1"},
|
|
"projects": {"paths": [], "active": ""},
|
|
"gui": {"show_windows": {}}
|
|
}),
|
|
patch('src.project_manager.load_project', return_value={}),
|
|
patch('src.project_manager.migrate_from_legacy_config', return_value={}),
|
|
patch('src.project_manager.save_project'),
|
|
patch('src.session_logger.open_session'),
|
|
patch('src.session_logger.reset_session'),
|
|
patch('src.app_controller.AppController._init_ai_and_hooks'),
|
|
patch('src.app_controller.AppController._fetch_models'),
|
|
patch('src.gui_2.App._load_fonts'),
|
|
patch('src.gui_2.App._post_init')
|
|
):
|
|
app = App()
|
|
app.files = []
|
|
app.context_files = []
|
|
return app
|
|
|
|
def test_populate_auto_slices_basic(mock_app: App) -> None:
|
|
f_item = FileItem(path="test.py")
|
|
mock_outline = "[Class] MyClass (Lines 1-10)\n[Method] my_method (Lines 2-5)\n[Func] top_func (Lines 12-15)"
|
|
|
|
with (
|
|
patch('src.mcp_client.configure') as mock_conf,
|
|
patch('src.mcp_client.py_get_code_outline', return_value=mock_outline) as mock_outline_tool,
|
|
patch('builtins.open', mock_open(read_data="dummy content"))
|
|
):
|
|
mock_app._populate_auto_slices(f_item)
|
|
|
|
assert len(f_item.custom_slices) == 3
|
|
s0 = f_item.custom_slices[0]
|
|
assert s0["start_line"] == 1
|
|
assert s0["end_line"] == 10
|
|
assert s0["tag"] == 'auto-ast'
|
|
assert s0["comment"] == "MyClass"
|
|
|
|
def test_add_selected_triggers_auto_slices(mock_app):
|
|
f_mock = MagicMock()
|
|
f_mock.path = "test.py"
|
|
mock_app.files = [f_mock]
|
|
mock_app._ui_picker_selected = {"test.py"}
|
|
|
|
with patch('src.gui_2.imgui') as mock_imgui, \
|
|
patch('src.gui_2.imscope') as mock_imscope:
|
|
mock_imgui.begin_popup_modal.return_value = (True, True)
|
|
mock_imgui.button.side_effect = lambda label, size=None: label == "Add Selected"
|
|
mock_imgui.checkbox.return_value = (False, False)
|
|
mock_imgui.begin_child.return_value = True
|
|
mock_imgui.ImVec2 = MagicMock()
|
|
mock_imgui.WindowFlags_ = MagicMock()
|
|
|
|
# Setup imscope mocks to act as context managers
|
|
mock_imscope.table.return_value.__enter__.return_value = True
|
|
mock_imscope.tree_node_ex.return_value.__enter__.return_value = True
|
|
mock_imscope.child.return_value.__enter__.return_value = True
|
|
mock_imscope.window.return_value.__enter__.return_value = (True, True)
|
|
|
|
with patch.object(mock_app, '_populate_auto_slices') as mock_populate:
|
|
import src.gui_2
|
|
src.gui_2.render_add_context_files_modal(mock_app)
|
|
|
|
assert mock_populate.called
|
|
assert len(mock_app.context_files) == 1
|
|
assert mock_app.context_files[0].path == "test.py"
|
|
|
|
def test_add_all_triggers_auto_slices(mock_app):
|
|
f_mock = MagicMock()
|
|
f_mock.path = "test_all.py"
|
|
mock_app.files = [f_mock]
|
|
mock_app.context_files = []
|
|
|
|
with patch('src.gui_2.imgui') as mock_imgui, \
|
|
patch('src.gui_2.imscope') as mock_imscope:
|
|
mock_imgui.button.side_effect = lambda label, size=None: label == "Add All##addall"
|
|
mock_imgui.collapsing_header.return_value = True
|
|
mock_imgui.begin_child.return_value = True
|
|
mock_imgui.begin_table.return_value = True
|
|
mock_imgui.tree_node_ex.return_value = False
|
|
mock_imgui.checkbox.return_value = (False, False)
|
|
mock_imgui.combo.return_value = (False, 0)
|
|
mock_imgui.input_text.return_value = (False, "")
|
|
mock_imgui.TableFlags_ = MagicMock()
|
|
mock_imgui.TableColumnFlags_ = MagicMock()
|
|
mock_imgui.TreeNodeFlags_ = MagicMock()
|
|
|
|
# Setup imscope mocks to act as context managers
|
|
mock_imscope.table.return_value.__enter__.return_value = True
|
|
mock_imscope.tree_node_ex.return_value.__enter__.return_value = True
|
|
mock_imscope.child.return_value.__enter__.return_value = True
|
|
mock_imscope.window.return_value.__enter__.return_value = (True, True)
|
|
|
|
with patch.object(mock_app, '_populate_auto_slices') as mock_populate:
|
|
import src.gui_2
|
|
src.gui_2.render_context_composition_panel(mock_app)
|
|
|
|
assert mock_populate.called
|
|
assert len(mock_app.context_files) == 1
|
|
assert mock_app.context_files[0].path == "test_all.py"
|