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.
123 lines
3.4 KiB
Python
123 lines
3.4 KiB
Python
import pytest
|
|
import tomli_w
|
|
from pathlib import Path
|
|
from src.tool_presets import ToolPresetManager
|
|
from src.tool_bias import BiasProfile
|
|
from src.tool_presets import ToolPreset, Tool
|
|
from src import paths
|
|
|
|
@pytest.fixture
|
|
def temp_paths(tmp_path, monkeypatch):
|
|
global_dir = tmp_path / "global"
|
|
global_dir.mkdir()
|
|
project_dir = tmp_path / "project"
|
|
project_dir.mkdir()
|
|
|
|
global_presets = global_dir / "tool_presets.toml"
|
|
project_presets = project_dir / "project_tool_presets.toml"
|
|
|
|
monkeypatch.setattr(paths, "get_global_tool_presets_path", lambda: global_presets)
|
|
monkeypatch.setattr(paths, "get_project_tool_presets_path", lambda _: project_presets)
|
|
|
|
return {
|
|
"global_dir": global_dir,
|
|
"project_dir": project_dir,
|
|
"global_presets": global_presets,
|
|
"project_presets": project_presets
|
|
}
|
|
|
|
def test_load_all_presets_merged(temp_paths):
|
|
# Setup global presets
|
|
global_data = {
|
|
"presets": {
|
|
"default": {
|
|
"categories": {
|
|
"General": [{"name": "read_file", "approval": "auto"}]
|
|
}
|
|
},
|
|
"global_only": {
|
|
"categories": {"Web": [{"name": "web_search", "approval": "ask"}]}
|
|
}
|
|
}
|
|
}
|
|
with open(temp_paths["global_presets"], "wb") as f:
|
|
tomli_w.dump(global_data, f)
|
|
|
|
# Setup project presets (overrides 'default')
|
|
project_data = {
|
|
"presets": {
|
|
"default": {
|
|
"categories": {
|
|
"General": [{"name": "read_file", "approval": "auto", "weight": 5}]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
with open(temp_paths["project_presets"], "wb") as f:
|
|
tomli_w.dump(project_data, f)
|
|
|
|
manager = ToolPresetManager(project_root=temp_paths["project_dir"])
|
|
all_presets = manager.load_all_presets()
|
|
|
|
assert "default" in all_presets
|
|
assert isinstance(all_presets["default"].categories["General"][0], Tool)
|
|
assert all_presets["default"].categories["General"][0].weight == 5
|
|
assert "global_only" in all_presets
|
|
|
|
def test_bias_profiles_merged(temp_paths):
|
|
# Setup global biases
|
|
global_data = {
|
|
"bias_profiles": {
|
|
"Discovery": {
|
|
"tool_weights": {"web_search": 5},
|
|
"category_multipliers": {"Web": 1.5}
|
|
}
|
|
}
|
|
}
|
|
with open(temp_paths["global_presets"], "wb") as f:
|
|
tomli_w.dump(global_data, f)
|
|
|
|
# Setup project biases
|
|
project_data = {
|
|
"bias_profiles": {
|
|
"Execution": {
|
|
"tool_weights": {"run_powershell": 5}
|
|
}
|
|
}
|
|
}
|
|
with open(temp_paths["project_presets"], "wb") as f:
|
|
tomli_w.dump(project_data, f)
|
|
|
|
manager = ToolPresetManager(project_root=temp_paths["project_dir"])
|
|
profiles = manager.load_all_bias_profiles()
|
|
|
|
assert "Discovery" in profiles
|
|
assert profiles["Discovery"].category_multipliers["Web"] == 1.5
|
|
assert "Execution" in profiles
|
|
assert profiles["Execution"].tool_weights["run_powershell"] == 5
|
|
|
|
def test_save_bias_profile(temp_paths):
|
|
manager = ToolPresetManager(project_root=temp_paths["project_dir"])
|
|
profile = BiasProfile(name="Custom", tool_weights={"test": 1})
|
|
|
|
manager.save_bias_profile(profile, scope="project")
|
|
|
|
loaded = manager.load_all_bias_profiles()
|
|
assert "Custom" in loaded
|
|
assert loaded["Custom"].tool_weights["test"] == 1
|
|
|
|
def test_delete_bias_profile(temp_paths):
|
|
project_data = {
|
|
"bias_profiles": {
|
|
"to_delete": {"tool_weights": {}}
|
|
}
|
|
}
|
|
with open(temp_paths["project_presets"], "wb") as f:
|
|
tomli_w.dump(project_data, f)
|
|
|
|
manager = ToolPresetManager(project_root=temp_paths["project_dir"])
|
|
manager.delete_bias_profile("to_delete", scope="project")
|
|
|
|
profiles = manager.load_all_bias_profiles()
|
|
assert "to_delete" not in profiles
|