diff --git a/tests/conftest.py b/tests/conftest.py index 372e1500..bac107ea 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -67,6 +67,31 @@ class VerificationLogger: f.write(f"{status} {self.test_name} ({result_msg})\n\n") print(f"[FINAL] {self.test_name}: {status} - {result_msg}") +@pytest.fixture(autouse=True) +def isolate_workspace(tmp_path_factory, monkeypatch) -> Generator[None, None, None]: + """ + Autouse fixture to isolate tests from the active user workspace. + Protects the real config.toml and manual_slop.toml from being overwritten. + """ + test_workspace = tmp_path_factory.mktemp("isolated_workspace") + + config_path = test_workspace / "config.toml" + import tomli_w + with open(config_path, "wb") as f: + tomli_w.dump({ + 'ai': {'provider': 'gemini', 'model': 'gemini-2.5-flash-lite'}, + 'projects': {'paths': [], 'active': ''}, + 'gui': {'show_windows': {}} + }, f) + + monkeypatch.setenv("SLOP_CONFIG", str(config_path)) + monkeypatch.setenv("SLOP_GLOBAL_PRESETS", str(test_workspace / "presets.toml")) + monkeypatch.setenv("SLOP_GLOBAL_TOOL_PRESETS", str(test_workspace / "tool_presets.toml")) + monkeypatch.setenv("SLOP_GLOBAL_PERSONAS", str(test_workspace / "personas.toml")) + monkeypatch.setenv("SLOP_GLOBAL_WORKSPACE_PROFILES", str(test_workspace / "workspace_profiles.toml")) + + yield + @pytest.fixture(autouse=True) def reset_paths() -> Generator[None, None, None]: """ diff --git a/tests/test_history_management.py b/tests/test_history_management.py index 1357648f..ab6a957d 100644 --- a/tests/test_history_management.py +++ b/tests/test_history_management.py @@ -28,11 +28,10 @@ def test_aggregate_includes_segregated_history() -> None: def test_mcp_blacklist() -> None: """Tests that the MCP client correctly blacklists files""" from src import mcp_client - from src.models import CONFIG_PATH - # CONFIG_PATH is usually something like 'config.toml' - assert mcp_client._is_allowed(Path("src/gui_2.py")) is True + from src import paths # config.toml should be blacklisted for reading by the AI - assert mcp_client._is_allowed(Path(CONFIG_PATH)) is False + assert mcp_client._is_allowed(Path("src/gui_2.py")) is True + assert mcp_client._is_allowed(paths.get_config_path()) is False def test_aggregate_blacklist() -> None: """Tests that aggregate correctly excludes blacklisted files"""