Private
Public Access
test(sandbox): update v3 paths-aware tests for FR1+FR3 invariants
- test_paths.py: explicit initialize_paths(<empty_config>) instead of
SLOP_CONFIG env var (v3 design); add restore_paths fixture so other
tests keep their conftest workspace init.
- test_summary_cache.py: use tmp_path (under ./tests/) instead of
hardcoded Path('.test_cache') that FR1 blocks.
- test_orchestrator_pm_history.py: use tempfile.mkdtemp() instead of
writing to project-root 'test_conductor/' that FR1 blocks.
- test_gui_paths.py::test_save_paths: mock src.paths.initialize_paths
instead of src.paths.reset_paths (v3 entry point).
All 12 tests pass in the Tier 2 clone after these fixes.
This commit is contained in:
+32
-16
@@ -1,29 +1,42 @@
|
||||
import os
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
from src import paths
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def reset_paths():
|
||||
paths.reset_paths()
|
||||
def restore_paths():
|
||||
# v3 paths.py: PathsConfig is frozen at init time. Save the pre-test
|
||||
# config path so we can restore after this test (other tests rely on
|
||||
# the conftest-initialized workspace). The fixtures themselves call
|
||||
# paths.initialize_paths(<tmp_config>) to control resolution.
|
||||
pre = paths.get_config_path()
|
||||
yield
|
||||
paths.reset_paths()
|
||||
paths.initialize_paths(pre)
|
||||
|
||||
def test_default_paths(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("SLOP_CONFIG", str(tmp_path / "non_existent.toml"))
|
||||
def test_default_paths(tmp_path):
|
||||
# v3 paths.py: when config has no [paths] section, paths come from
|
||||
# defaults. Pass a config that does NOT define [paths].
|
||||
root_dir = Path(paths.__file__).resolve().parent.parent
|
||||
assert paths.get_logs_dir() == root_dir / "logs/sessions"
|
||||
assert paths.get_scripts_dir() == root_dir / "scripts/generated"
|
||||
# config path should be what we set in env
|
||||
assert paths.get_config_path() == tmp_path / "non_existent.toml"
|
||||
empty_config = tmp_path / "empty.toml"
|
||||
empty_config.write_text("# no [paths] section here\n")
|
||||
paths.initialize_paths(empty_config)
|
||||
|
||||
assert paths.get_logs_dir() == root_dir / "logs" / "sessions"
|
||||
assert paths.get_scripts_dir() == root_dir / "scripts" / "generated"
|
||||
assert paths.get_config_path() == empty_config.resolve()
|
||||
|
||||
def test_env_var_overrides(tmp_path, monkeypatch):
|
||||
# Absolute env var
|
||||
# v3 paths.py: env var wins over config and default. Set env var, then
|
||||
# init with a config that does NOT define [paths] (so only env + default apply).
|
||||
abs_logs = (tmp_path / "abs_logs").resolve()
|
||||
monkeypatch.setenv("SLOP_LOGS_DIR", str(abs_logs))
|
||||
empty_config = tmp_path / "empty.toml"
|
||||
empty_config.write_text("# no [paths] section\n")
|
||||
paths.initialize_paths(empty_config)
|
||||
assert paths.get_logs_dir() == abs_logs
|
||||
|
||||
def test_config_overrides(tmp_path, monkeypatch):
|
||||
def test_config_overrides(tmp_path):
|
||||
# v3 paths.py: [paths] section in config overrides default. Relative
|
||||
# paths in config are resolved against project root.
|
||||
root_dir = Path(paths.__file__).resolve().parent.parent
|
||||
config_file = tmp_path / "custom_config.toml"
|
||||
content = """
|
||||
@@ -32,12 +45,13 @@ logs_dir = "cfg_logs"
|
||||
scripts_dir = "cfg_scripts"
|
||||
"""
|
||||
config_file.write_text(content)
|
||||
monkeypatch.setenv("SLOP_CONFIG", str(config_file))
|
||||
paths.initialize_paths(config_file)
|
||||
|
||||
assert paths.get_logs_dir() == root_dir / "cfg_logs"
|
||||
assert paths.get_scripts_dir() == root_dir / "cfg_scripts"
|
||||
|
||||
def test_precedence(tmp_path, monkeypatch):
|
||||
# v3 paths.py: env var SLOP_LOGS_DIR wins over [paths] config entry.
|
||||
root_dir = Path(paths.__file__).resolve().parent.parent
|
||||
config_file = tmp_path / "custom_config.toml"
|
||||
content = """
|
||||
@@ -45,11 +59,13 @@ def test_precedence(tmp_path, monkeypatch):
|
||||
logs_dir = "cfg_logs"
|
||||
"""
|
||||
config_file.write_text(content)
|
||||
monkeypatch.setenv("SLOP_CONFIG", str(config_file))
|
||||
monkeypatch.setenv("SLOP_LOGS_DIR", "env_logs")
|
||||
# Use absolute env_logs path so _resolve_path returns it as-is.
|
||||
env_logs = (root_dir / "env_logs").resolve()
|
||||
monkeypatch.setenv("SLOP_LOGS_DIR", str(env_logs))
|
||||
paths.initialize_paths(config_file)
|
||||
|
||||
# Env var should take precedence over config
|
||||
assert paths.get_logs_dir() == (root_dir / "env_logs").resolve()
|
||||
assert paths.get_logs_dir() == env_logs
|
||||
|
||||
def test_conductor_dir_project_relative(tmp_path):
|
||||
# Should default to tmp_path/conductor
|
||||
|
||||
Reference in New Issue
Block a user