Private
Public Access
fix(imports): complete migration from 'from src import models' to direct subsystem imports
Replaces the broken-script-generated imports in src/ and tests/ with clean direct imports from the destination modules. Per user directive: 'we should adjust the tests instead' — no legacy __getattr__ shim is re-introduced. Key fixes: - src/mcp_client.py: remove self-import (MCPServerConfig etc. are defined locally; the script's module-top self-import caused the circular ImportError blocking all 11 test tiers) - src/gui_2.py: add missing module-top imports for FileItem, ContextFileEntry, ContextPreset, Tool, Persona, BiasProfile, parse_history_entries; remove broken-script local imports inside function bodies - src/app_controller.py: remove FileItem/FileItems from the type_aliases import block (was shadowing the direct import with the forward-reference TypeAlias string, breaking isinstance() calls); confirm isinstance() now works - src/commands.py: script correctly removed unused 'from src import models' - tests/test_models_no_top_level_tomli_w.py: import save_config_to_disk from src.project (no legacy shim back in models.py) - tests/test_rag_engine_ready_status_bug.py: import RAGConfig and VectorStoreConfig from src.mcp_client - tests/test_gui_2_result.py: patch src.gui_2.Persona/BiasProfile (gui_2 binds at module load; src.personas patch doesn't affect the gui_2 namespace) - tests/test_gui_2_result.py: patch src.gui_2.parse_diff (it lives in gui_2, not patch_modal) - tests/test_generate_type_registry.py: Metadata is now a dataclass in src_type_aliases.md (not a TypeAlias in type_aliases.md); src_models.md is no longer generated (src/models.py has no dataclasses after the de-cruft track) No local imports inside function bodies (per python.md §17.9a). All new imports are at module top with surgical edits.
This commit is contained in:
@@ -730,7 +730,7 @@ def test_phase_4_l3398_render_persona_editor_save_result_success():
|
||||
app._editing_persona_preferred_models_list = []
|
||||
mock_persona = MagicMock(name="mock_persona")
|
||||
mock_persona.name = "test_persona"
|
||||
with patch.object(gui_2.models, "Persona", return_value=mock_persona):
|
||||
with patch("src.gui_2.Persona", return_value=mock_persona):
|
||||
result = gui_2._render_persona_editor_save_result(app)
|
||||
assert result.ok, f"Expected ok=True on success, got errors: {result.errors}"
|
||||
assert result.data is True
|
||||
@@ -756,7 +756,7 @@ def test_phase_4_l3398_render_persona_editor_save_result_failure():
|
||||
app._editing_persona_context_preset_id = ""
|
||||
app._editing_persona_aggregation_strategy = ""
|
||||
app._editing_persona_preferred_models_list = []
|
||||
with patch.object(gui_2.models, "Persona", side_effect=RuntimeError("validation failed")):
|
||||
with patch("src.gui_2.Persona", side_effect=RuntimeError("validation failed")):
|
||||
result = gui_2._render_persona_editor_save_result(app)
|
||||
assert not result.ok, f"Expected ok=False on failure, got data: {result.data}"
|
||||
assert result.errors, "Expected at least one error on failure"
|
||||
@@ -1095,7 +1095,7 @@ def test_phase_5_l1428_request_patch_from_tier4_result_success():
|
||||
patch_text = "--- a/foo.py\n+++ b/foo.py\n@@ -1 +1 @@\n-old\n+new\n"
|
||||
mock_diff_files = [MagicMock(old_path="/proj/foo/foo.py", new_path="/proj/foo/foo.py")]
|
||||
with patch.object(gui_2.ai_client, "run_tier4_patch_generation", return_value=patch_text), \
|
||||
patch("src.diff_viewer.parse_diff", return_value=mock_diff_files):
|
||||
patch("src.gui_2.parse_diff", return_value=mock_diff_files):
|
||||
result = gui_2.request_patch_from_tier4_result(app, "boom", "/proj/foo/foo.py")
|
||||
assert result.ok, f"Expected ok=True on success, got errors: {result.errors}"
|
||||
assert result.data is True
|
||||
@@ -1141,7 +1141,7 @@ def test_phase_5_l3163_render_tool_preset_bias_save_result_success():
|
||||
app._editing_tool_preset_scope = "project"
|
||||
mock_profile = MagicMock()
|
||||
mock_profile.name = "test_bias"
|
||||
with patch.object(gui_2.models, "BiasProfile", return_value=mock_profile):
|
||||
with patch("src.gui_2.BiasProfile", return_value=mock_profile):
|
||||
result = gui_2._render_tool_preset_bias_save_result(app)
|
||||
assert result.ok, f"Expected ok=True on success, got errors: {result.errors}"
|
||||
assert result.data is True
|
||||
@@ -1163,7 +1163,7 @@ def test_phase_5_l3163_render_tool_preset_bias_save_result_failure():
|
||||
app._editing_bias_profile_tool_weights = {"foo": 2}
|
||||
app._editing_bias_profile_category_multipliers = {"bar": 1.5}
|
||||
app._editing_tool_preset_scope = "project"
|
||||
with patch.object(gui_2.models, "BiasProfile", side_effect=RuntimeError("bias validation failed")):
|
||||
with patch("src.gui_2.BiasProfile", side_effect=RuntimeError("bias validation failed")):
|
||||
result = gui_2._render_tool_preset_bias_save_result(app)
|
||||
assert not result.ok, f"Expected ok=False on failure, got data: {result.data}"
|
||||
assert result.errors, "Expected at least one error on failure"
|
||||
|
||||
Reference in New Issue
Block a user