Private
Public Access
feat(paths): remove SLOP_CONFIG env-var fallback; add --config CLI flag (FR2)
This commit is contained in:
@@ -147,4 +147,48 @@ def test_sandbox_allows_pytest_cache_write() -> None:
|
||||
probe.write_text("ok", encoding="utf-8")
|
||||
assert probe.read_text(encoding="utf-8") == "ok"
|
||||
finally:
|
||||
probe.unlink(missing_ok=True)
|
||||
probe.unlink(missing_ok=True)
|
||||
|
||||
|
||||
def test_config_override_via_cli_flag(tmp_path) -> None:
|
||||
"""paths.set_config_override(path) makes get_config_path() return that path."""
|
||||
from src import paths
|
||||
config_path = tmp_path / "my_config.toml"
|
||||
config_path.write_text("[ai]\nprovider='gemini'\n", encoding="utf-8")
|
||||
original = paths._CONFIG_OVERRIDE
|
||||
try:
|
||||
paths.set_config_override(config_path)
|
||||
assert paths.get_config_path() == config_path
|
||||
finally:
|
||||
paths.set_config_override(original)
|
||||
|
||||
|
||||
def test_paths_get_config_path_no_env_fallback(monkeypatch) -> None:
|
||||
"""Without an override AND without SLOP_CONFIG, get_config_path returns default."""
|
||||
monkeypatch.delenv("SLOP_CONFIG", raising=False)
|
||||
from src import paths
|
||||
original = paths._CONFIG_OVERRIDE
|
||||
try:
|
||||
paths.set_config_override(None)
|
||||
expected = Path(__file__).resolve().parent.parent / "config.toml"
|
||||
assert paths.get_config_path() == expected
|
||||
finally:
|
||||
paths.set_config_override(original)
|
||||
|
||||
|
||||
def test_sloppy_py_parses_config_flag() -> None:
|
||||
"""sloppy.py has a --config argparse argument that calls set_config_override."""
|
||||
import ast
|
||||
sloppy = Path(__file__).resolve().parent.parent / "sloppy.py"
|
||||
tree = ast.parse(sloppy.read_text(encoding="utf-8"))
|
||||
found_config_arg = False
|
||||
found_set_override_call = False
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, ast.Constant) and node.value == "--config":
|
||||
found_config_arg = True
|
||||
if isinstance(node, ast.Call):
|
||||
func = node.func
|
||||
if isinstance(func, ast.Name) and func.id == "set_config_override":
|
||||
found_set_override_call = True
|
||||
assert found_config_arg, "sloppy.py must have a --config argparse argument"
|
||||
assert found_set_override_call, "sloppy.py must call paths.set_config_override(args.config)"
|
||||
Reference in New Issue
Block a user