8f11340b38
Per post_module_taxonomy_de_cruft_20260627 Phase 2 (FR7). Each
'from src.models import X' for a moved class is rewritten to
'from src.<destination> import X':
Ticket, Track, WorkerContext, TrackState, TrackMetadata,
ThinkingSegment, EMPTY_TRACK_STATE -> src.mma
ProjectContext, ProjectMeta, ProjectOutput, ProjectFiles,
ProjectScreenshots, ProjectDiscussion, EMPTY_PROJECT_CONTEXT -> src.project
FileItem, Preset, ContextPreset, ContextFileEntry,
NamedViewPreset -> src.project_files
Tool, ToolPreset -> src.tool_presets
BiasProfile -> src.tool_bias
TextEditorConfig, ExternalEditorConfig,
EMPTY_TEXT_EDITOR_CONFIG -> src.external_editor
Persona -> src.personas
WorkspaceProfile -> src.workspace_manager
MCPServerConfig, MCPConfiguration, VectorStoreConfig,
RAGConfig, load_mcp_config -> src.mcp_client
NOT touched (kept on src.models; Phase 3 or Phase 4 will move them):
GenerateRequest, ConfirmRequest, DEFAULT_TOOL_CATEGORIES, Metadata, PROVIDERS
Migration was performed by the one-time script
scripts/tier2/artifacts/post_module_taxonomy_de_cruft_20260627/migrate_imports.py
which uses a class-to-module map and re.sub() to rewrite each
'from src.models import X' line.
Total: 85 import lines rewritten across 71 files.
Note: this commit depends on the v2 SHIPPED work
(origin/tier2/module_taxonomy_refactor_20260627) being merged into
this branch NEXT. On master (without the v2 SHIPPED commits), the
destination modules do not exist and these imports would fail.
104 lines
3.5 KiB
Python
104 lines
3.5 KiB
Python
import pytest
|
|
from src.context_presets import ContextPresetManager
|
|
from src.project_files import ContextPreset, ContextFileEntry
|
|
from src.app_controller import AppController
|
|
from pathlib import Path
|
|
import tomli_w
|
|
import os
|
|
from unittest.mock import MagicMock
|
|
|
|
@pytest.fixture
|
|
def project_dict():
|
|
return {
|
|
"context_presets": {
|
|
"test_preset": {
|
|
"files": [{"path": "file1.py"}, {"path": "file2.py"}],
|
|
"screenshots": ["shot1.png"],
|
|
"description": "Test description"
|
|
}
|
|
}
|
|
}
|
|
|
|
def test_manager_load_all(project_dict):
|
|
manager = ContextPresetManager()
|
|
result = manager.load_all(project_dict)
|
|
assert result.ok, f"load_all failed: {result.errors}"
|
|
presets = result.data
|
|
assert "test_preset" in presets
|
|
assert len(presets["test_preset"].files) == 2
|
|
assert presets["test_preset"].files[0].path == "file1.py"
|
|
assert presets["test_preset"].screenshots == ["shot1.png"]
|
|
assert presets["test_preset"].description == "Test description"
|
|
|
|
def test_manager_save_preset(project_dict):
|
|
manager = ContextPresetManager()
|
|
new_preset = ContextPreset(
|
|
name="new_preset",
|
|
files=[ContextFileEntry(path="new.py")],
|
|
screenshots=["new.png"],
|
|
description="New desc"
|
|
)
|
|
manager.save_preset(project_dict, new_preset)
|
|
assert "new_preset" in project_dict["context_presets"]
|
|
assert project_dict["context_presets"]["new_preset"]["description"] == "New desc"
|
|
# ContextFileEntry.to_dict() includes view_mode and custom_slices
|
|
assert project_dict["context_presets"]["new_preset"]["files"][0]["path"] == "new.py"
|
|
assert project_dict["context_presets"]["new_preset"]["files"][0]["view_mode"] == "summary"
|
|
|
|
def test_manager_delete_preset(project_dict):
|
|
manager = ContextPresetManager()
|
|
manager.delete_preset(project_dict, "test_preset")
|
|
assert "test_preset" not in project_dict["context_presets"]
|
|
|
|
def test_app_controller_save_load(tmp_path, monkeypatch):
|
|
# Setup a dummy project
|
|
project_file = tmp_path / "test_project.toml"
|
|
project_data = {
|
|
"project": {"name": "test"},
|
|
"discussion": {"active": "main", "discussions": {"main": {"history": []}}},
|
|
"files": {"paths": []},
|
|
"screenshots": {"paths": []}
|
|
}
|
|
with open(project_file, "wb") as f:
|
|
tomli_w.dump(project_data, f)
|
|
|
|
# Mock directories to avoid issues during AppController init
|
|
monkeypatch.setenv("SLOP_LOGS_DIR", str(tmp_path / "logs"))
|
|
monkeypatch.setenv("SLOP_SCRIPTS_DIR", str(tmp_path / "scripts"))
|
|
|
|
# Mocking some parts of AppController that might fail without full environment
|
|
monkeypatch.setattr("src.paths.get_config_path", lambda: tmp_path / "config.toml")
|
|
|
|
# Create dummy config
|
|
with open(tmp_path / "config.toml", "wb") as f:
|
|
tomli_w.dump({"ui": {"theme": "dark"}, "projects": []}, f)
|
|
|
|
controller = AppController()
|
|
controller.active_project_path = str(project_file)
|
|
# We don't call init_state() as it does too much, we manually setup what we need
|
|
controller.project = project_data
|
|
controller._save_active_project = MagicMock()
|
|
|
|
# Save preset
|
|
preset = ContextPreset(
|
|
name="saved_preset",
|
|
files=[ContextFileEntry(path="app.py")],
|
|
screenshots=["app.png"]
|
|
)
|
|
controller.save_context_preset(preset)
|
|
|
|
# Verify in project dict
|
|
assert "saved_preset" in controller.project["context_presets"]
|
|
controller._save_active_project.assert_called_once()
|
|
|
|
# Change state
|
|
controller.context_files = []
|
|
controller.screenshots = []
|
|
|
|
# Load preset
|
|
loaded = controller.load_context_preset("saved_preset")
|
|
assert loaded.name == "saved_preset"
|
|
assert [f.path for f in controller.context_files] == ["app.py"]
|
|
assert controller.screenshots == ["app.png"]
|
|
controller._save_active_project.assert_called()
|