Private
Public Access
0
0
Files
manual_slop/tests/test_view_presets.py
T
ed 9e07fac1db refactor(consumers): replace 'models.<moved_class>' with direct imports
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.
2026-06-26 14:06:03 -04:00

119 lines
3.8 KiB
Python

import os
import pytest
import copy
from src import models
from src.app_controller import AppController
@pytest.fixture
def controller(tmp_path):
# Create a mock project file
proj_path = tmp_path / "test_project.toml"
proj_path.write_text("[project]\nname = 'test'\n")
ctrl = AppController()
ctrl.active_project_path = str(proj_path)
ctrl.project = {"project": {"name": "test"}}
ctrl.view_presets = []
# Initialize missing attributes needed for flush/refresh
ctrl.ui_output_dir = "./md_gen"
ctrl.ui_files_base_dir = "."
ctrl.ui_shots_base_dir = "."
ctrl.ui_project_git_dir = ""
ctrl.ui_project_conductor_dir = "conductor"
ctrl.ui_project_system_prompt = ""
ctrl.ui_project_preset_name = None
ctrl.ui_gemini_cli_path = "gemini"
ctrl.ui_word_wrap = True
ctrl.ui_auto_add_history = False
ctrl.ui_auto_scroll_comms = True
ctrl.ui_auto_scroll_tool_calls = True
ctrl.ui_agent_tools = {}
ctrl.ui_epic_input = ""
ctrl.ui_active_context_preset = ""
ctrl.preset_manager = type('Mock', (), {'load_all': lambda self: {}, 'project_root': None})()
ctrl.tool_preset_manager = type('Mock', (), {'load_all_presets': lambda self: {}, 'load_all_bias_profiles': lambda self: {}, 'project_root': None})()
ctrl.persona_manager = type('Mock', (), {'load_all': lambda self: {}})()
return ctrl
def test_save_view_preset(controller):
f_item = FileItem(path="test.py", view_mode="skeleton")
f_item.ast_mask = {"test::func": "sig"}
f_item.custom_slices = [{"start_line": 1, "end_line": 10}]
controller._cb_save_view_preset("my_preset", f_item)
assert any(vp.name == "my_preset" for vp in controller.view_presets)
preset = next(vp for vp in controller.view_presets if vp.name == "my_preset")
assert preset.view_mode == "skeleton"
assert preset.ast_mask == {"test::func": "sig"}
assert preset.custom_slices == [{"start_line": 1, "end_line": 10}]
# Verify persistence
controller._flush_to_project()
assert "view_presets" in controller.project
assert isinstance(controller.project["view_presets"], list)
assert any(vp["name"] == "my_preset" for vp in controller.project["view_presets"])
def test_apply_view_preset(controller):
# Setup a preset
preset = NamedViewPreset(
name="my_preset",
view_mode="masked",
ast_mask={"main::run": "def"},
custom_slices=[{"start_line": 5, "end_line": 15}]
)
controller.view_presets.append(preset)
# Create a file item to apply to
f_item = FileItem(path="main.py", view_mode="summary")
controller._cb_apply_view_preset("my_preset", f_item)
assert f_item.view_mode == "masked"
assert f_item.ast_mask == {"main::run": "def"}
assert f_item.custom_slices == [{"start_line": 5, "end_line": 15}]
def test_delete_view_preset(controller):
preset = NamedViewPreset(name="to_del", view_mode="full")
controller.view_presets.append(preset)
controller._cb_delete_view_preset("to_del")
assert not any(vp.name == "to_del" for vp in controller.view_presets)
def test_load_presets_from_project_list(controller):
controller.project["view_presets"] = [
{
"name": "stored_preset",
"view_mode": "outline",
"ast_mask": {"a": "b"},
"custom_slices": []
}
]
controller._refresh_from_project()
assert any(vp.name == "stored_preset" for vp in controller.view_presets)
preset = next(vp for vp in controller.view_presets if vp.name == "stored_preset")
assert preset.view_mode == "outline"
assert preset.ast_mask == {"a": "b"}
def test_load_presets_from_project_legacy_dict(controller):
# Test backward compatibility
controller.project["view_presets"] = {
"legacy_preset": {
"view_mode": "full",
"ast_mask": {"c": "d"},
"custom_slices": []
}
}
controller._refresh_from_project()
assert any(vp.name == "legacy_preset" for vp in controller.view_presets)
preset = next(vp for vp in controller.view_presets if vp.name == "legacy_preset")
assert preset.view_mode == "full"
assert preset.ast_mask == {"c": "d"}