Private
Public Access
0
0
Files
manual_slop/tests/test_workspace_manager.py
T
ed 8f11340b38 refactor(consumers): migrate 85 'from src.models import' sites to direct subsystem imports
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.
2026-06-26 13:34:03 -04:00

116 lines
4.1 KiB
Python

import pytest
from pathlib import Path
from src.workspace_manager import WorkspaceManager
from src.workspace_manager import WorkspaceProfile
from src import paths
def test_load_all_profiles_merged(tmp_path, monkeypatch):
global_profiles_path = tmp_path / "global_workspace_profiles.toml"
project_root = tmp_path / "project"
project_root.mkdir()
project_profiles_path = project_root / ".ai" / "workspace_profiles.toml"
project_profiles_path.parent.mkdir()
monkeypatch.setattr(paths, "get_global_workspace_profiles_path", lambda: global_profiles_path)
monkeypatch.setattr(paths, "get_project_workspace_profiles_path", lambda p: project_profiles_path)
global_content = """
[profiles.GlobalOnly]
ini_content = "global_ini"
show_windows = { "win1" = true }
panel_states = { "p1" = 1 }
[profiles.Overridden]
ini_content = "global_ini_to_be_overridden"
show_windows = { "win2" = false }
panel_states = { "p2" = 2 }
"""
global_profiles_path.write_text(global_content)
project_content = """
[profiles.ProjectOnly]
ini_content = "project_ini"
show_windows = { "win3" = true }
panel_states = { "p3" = 3 }
[profiles.Overridden]
ini_content = "project_ini_override"
show_windows = { "win2" = true }
panel_states = { "p2" = 22 }
"""
project_profiles_path.write_text(project_content)
wm = WorkspaceManager(project_root=project_root)
profiles = wm.load_all_profiles()
assert len(profiles) == 3
assert "GlobalOnly" in profiles
assert "ProjectOnly" in profiles
assert "Overridden" in profiles
assert profiles["GlobalOnly"].ini_content == "global_ini"
assert profiles["ProjectOnly"].ini_content == "project_ini"
assert profiles["Overridden"].ini_content == "project_ini_override"
assert profiles["Overridden"].show_windows["win2"] is True
assert profiles["Overridden"].panel_states["p2"] == 22
def test_save_profile_global_and_project(tmp_path, monkeypatch):
global_profiles_path = tmp_path / "global_workspace_profiles.toml"
project_root = tmp_path / "project"
project_root.mkdir()
project_profiles_path = project_root / ".ai" / "workspace_profiles.toml"
project_profiles_path.parent.mkdir()
monkeypatch.setattr(paths, "get_global_workspace_profiles_path", lambda: global_profiles_path)
monkeypatch.setattr(paths, "get_project_workspace_profiles_path", lambda p: project_profiles_path)
wm = WorkspaceManager(project_root=project_root)
profile_global = WorkspaceProfile(name="MyGlobal", ini_content="g_ini", show_windows={}, panel_states={})
wm.save_profile(profile_global, scope="global")
assert global_profiles_path.exists()
loaded_global = wm.load_all_profiles()
assert "MyGlobal" in loaded_global
assert loaded_global["MyGlobal"].ini_content == "g_ini"
profile_project = WorkspaceProfile(name="MyProject", ini_content="p_ini", show_windows={}, panel_states={})
wm.save_profile(profile_project, scope="project")
assert project_profiles_path.exists()
loaded_all = wm.load_all_profiles()
assert "MyGlobal" in loaded_all
assert "MyProject" in loaded_all
assert loaded_all["MyProject"].ini_content == "p_ini"
def test_delete_profile(tmp_path, monkeypatch):
global_profiles_path = tmp_path / "global_workspace_profiles.toml"
project_root = tmp_path / "project"
project_root.mkdir()
project_profiles_path = project_root / ".ai" / "workspace_profiles.toml"
project_profiles_path.parent.mkdir()
monkeypatch.setattr(paths, "get_global_workspace_profiles_path", lambda: global_profiles_path)
monkeypatch.setattr(paths, "get_project_workspace_profiles_path", lambda p: project_profiles_path)
wm = WorkspaceManager(project_root=project_root)
p1 = WorkspaceProfile(name="P1", ini_content="1", show_windows={}, panel_states={})
p2 = WorkspaceProfile(name="P2", ini_content="2", show_windows={}, panel_states={})
wm.save_profile(p1, scope="global")
wm.save_profile(p2, scope="project")
profiles = wm.load_all_profiles()
assert "P1" in profiles
assert "P2" in profiles
wm.delete_profile("P2", scope="project")
profiles = wm.load_all_profiles()
assert "P1" in profiles
assert "P2" not in profiles
wm.delete_profile("P1", scope="global")
profiles = wm.load_all_profiles()
assert "P1" not in profiles