Private
Public Access
0
0
Files
manual_slop/tests/test_auto_slices.py
T
ed b15955c80e chore: stage remaining post-de-cruft fixes (src/test artifacts)
Staged-but-not-yet-fixed file artifacts from the post_module_taxonomy_de_cruft
followup. These are mostly minor — direct-import migrations that landed in the
prior commits were not applied to a few remaining files because the broken-script
placement issues were non-trivial.

For Tier 1 followup:
- src/commands.py — unused 'from src import models' removed by migration
- src/mcp_client.py — verified to no longer have the circular self-import
- src/models.py — clean 38-line final state (Metadata alias + PROVIDERS lazy __getattr__)
- src/multi_agent_conductor.py, src/project_manager.py, src/rag_engine.py
  — bare 'from src import models' lines replaced with direct imports
- 12 test_*.py files — direct imports of moved classes added (FileItem,
  Ticket, MCPServerConfig, MCPConfiguration, load_mcp_config, RAGConfig,
  VectorStoreConfig, NamedViewPreset, ContextFileEntry, ContextPreset,
  Persona, BiasProfile, parse_history_entries)
- docs/type_registry/src_mcp_client.md — regenerated via type_registry script

No production behavior changes here. These are the residual direct-import
migrations the migration script already completed. Some are tracked in the
end_of_session report for Tier 1 followup.
2026-06-26 23:18:27 -04:00

110 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
from src.project_files import FileItem
@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"