fix(paths): module-level default init so subprocess imports don't crash

This commit is contained in:
ed
2026-06-19 10:55:54 -04:00
parent 83722bc0e8
commit e1d4c1dc9d
2 changed files with 58 additions and 3 deletions
+25 -3
View File
@@ -181,14 +181,36 @@ def test_paths_runtime_refresh_atomic_swap(tmp_path) -> None:
def test_paths_uninitialized_raises(tmp_path) -> None:
"""Calling a path getter before initialize_paths() raises RuntimeError
(not silent fallback). This is the contract that enforces explicit init.
"""After explicit paths.reset_paths() (i.e., user CLEARED the singleton
after a previous init), a getter raises RuntimeError. This is the
"bad programmer" detection — once cleared, you must re-init.
[C: src/paths.py:_cfg]"""
from src import paths
paths.initialize_paths(tmp_path / "dummy.toml")
paths.reset_paths()
with pytest.raises(RuntimeError, match="not initialized"):
paths.get_logs_dir()
paths.reset_paths()
def test_paths_module_load_initializes_defaults(tmp_path) -> None:
"""src/paths.py initializes _PATHS_CONFIG with defaults at module load.
This means subprocess imports that don't go through conftest.py (e.g.,
_run_in_subprocess tests) still have valid paths for any src/* module
that triggers a paths getter at import time (e.g., theme_2.load_themes).
[C: src/paths.py:_module_init_default]"""
import importlib
import src.paths as paths_module
# Reload to simulate fresh module load in subprocess
importlib.reload(paths_module)
# After module reload, defaults should be set
assert paths_module._PATHS_CONFIG is not None, (
"src.paths must initialize _PATHS_CONFIG at module load "
"so subprocess imports don't trigger 'paths not initialized' errors."
)
default_logs = paths_module._PATHS_CONFIG.logs_dir
assert default_logs.name == "sessions", (
f"default logs_dir should end in 'sessions'; got {default_logs}"
)
def test_sloppy_py_parses_config_flag() -> None: