Private
Public Access
0
0

test: Implement comprehensive workspace isolation to protect user projects

- Add isolate_workspace autouse fixture in conftest.py.
- Monkeypatch SLOP_CONFIG and preset paths to point to a temporary test directory.
- Update test_history_management.py to use dynamic paths.get_config_path().
- Prevents tests from accidentally reading or modifying the active project.toml or config.toml.
This commit is contained in:
2026-06-02 01:27:32 -04:00
parent 3528d6eb03
commit b3b9baf91f
2 changed files with 28 additions and 4 deletions
+25
View File
@@ -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]:
"""
+3 -4
View File
@@ -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"""