Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.
Python agentaianthropicclaude-codecompressioncontext-engineeringcontext-windowcursorfastapilangchainllmmcpopenaiprompt-engineeringproxypythonragtoken-optimizationtokenstypescript
feat(paths): add canonical HEADROOM_CONFIG_DIR / HEADROOM_WORKSPACE_DIR module
JerrettDavis4fb193540503
diff --git a/headroom/paths.py b/headroom/paths.pynew file mode 100644index 000000000..7a3083325--- /dev/null+++ b/headroom/paths.py@@ -0,0 +1,349 @@+"""Canonical filesystem contract for Headroom.++This module defines the single source of truth for where Headroom reads and+writes files. It introduces two canonical roots:++* ``HEADROOM_CONFIG_DIR`` -- read-mostly configuration (defaults to+ ``~/.headroom/config``). Holds model catalogs, plugin settings, and other+ configuration that users or admins edit.+* ``HEADROOM_WORKSPACE_DIR`` -- read-write state (defaults to ``~/.headroom``).+ Holds runtime caches, telemetry outputs, logs, savings history, memory+ databases, and anything else that the running proxy/CLI writes to.++Precedence for every per-resource helper is::++ explicit argument > per-resource env var > derived from canonical root >+ default++Adding the canonical root env vars is strictly additive: every existing+per-resource override (``HEADROOM_SAVINGS_PATH``, ``HEADROOM_TOIN_PATH``,+``HEADROOM_SUBSCRIPTION_STATE_PATH``, ``HEADROOM_MODEL_LIMITS``, ...)+continues to take precedence with identical semantics.++Implementation notes:++* Helpers return ``Path`` (never ``str``). Callers that need a string cast+ at the callsite.+* Helpers are pure -- they never call ``mkdir``. Use the ``ensure_*``+ variants when the caller needs the directory to exist.+* No caching. Every call re-reads the environment so that ``monkeypatch``+ in tests works without extra hoops.+"""++from __future__ import annotations++import os+from pathlib import Path++# ---------------------------------------------------------------------------+# Canonical env var names+# ---------------------------------------------------------------------------++HEADROOM_CONFIG_DIR_ENV = "HEADROOM_CONFIG_DIR"+HEADROOM_WORKSPACE_DIR_ENV = "HEADROOM_WORKSPACE_DIR"++# ---------------------------------------------------------------------------+# Legacy per-resource env vars (kept for backward compatibility)+# ---------------------------------------------------------------------------++HEADROOM_SAVINGS_PATH_ENV = "HEADROOM_SAVINGS_PATH"+HEADROOM_TOIN_PATH_ENV = "HEADROOM_TOIN_PATH"+HEADROOM_SUBSCRIPTION_STATE_PATH_ENV = "HEADROOM_SUBSCRIPTION_STATE_PATH"++# ---------------------------------------------------------------------------+# Default sub-path fragments+# ---------------------------------------------------------------------------++_WORKSPACE_DIR_DEFAULT = ".headroom"+_CONFIG_DIR_DEFAULT_SUFFIX = "config"++# Resource file/sub-dir names (kept here so nothing else has to hardcode them)+_SAVINGS_FILE = "proxy_savings.json"+_TOIN_FILE = "toin.json"+_MODELS_FILE = "models.json"+_SUBSCRIPTION_FILE = "subscription_state.json"+_MEMORY_DB_FILE = "memory.db"+_MEMORIES_DIR = "memories"+_LICENSE_CACHE_FILE = "license_cache.json"+_SESSION_STATS_FILE = "session_stats.jsonl"+_SYNC_STATE_FILE = "sync_state.json"+_BRIDGE_STATE_FILE = "bridge_state.json"+_LOGS_DIR = "logs"+_PROXY_LOG_FILE = "proxy.log"+_DEBUG_400_DIR = "debug_400"+_BIN_DIR = "bin"+_RTK_UNIX = "rtk"+_RTK_WIN = "rtk.exe"+_DEPLOY_DIR = "deploy"+_PLUGINS_DIR = "plugins"+++# ---------------------------------------------------------------------------+# Internal helpers+# ---------------------------------------------------------------------------+++def _env(name: str) -> str:+ """Return a trimmed environment value, or ``""`` when unset/blank."""++ return os.environ.get(name, "").strip()+++def _resolve(explicit: str | os.PathLike[str] | None, env_var: str, derived: Path) -> Path:+ """Apply the standard precedence: explicit > env > derived.++ ``explicit`` and the env-var value are both passed through ``expanduser()``+ so that callers can pass ``"~/foo/bar"`` and have it resolve naturally.+ """++ if explicit is not None and str(explicit) != "":+ return Path(explicit).expanduser()+ env_value = _env(env_var)+ if env_value:+ return Path(env_value).expanduser()+ return derived+++# ---------------------------------------------------------------------------+# Canonical roots+# ---------------------------------------------------------------------------+++def workspace_dir() -> Path:+ """Return the workspace (read-write state) root directory.++ Resolution order:++ 1. ``$HEADROOM_WORKSPACE_DIR`` (trimmed, tilde-expanded) if set.+ 2. ``~/.headroom`` otherwise.+ """++ env_value = _env(HEADROOM_WORKSPACE_DIR_ENV)+ if env_value:+ return Path(env_value).expanduser()+ return Path.home() / _WORKSPACE_DIR_DEFAULT+++def config_dir() -> Path:+ """Return the config (read-mostly) root directory.++ Resolution order:++ 1. ``$HEADROOM_CONFIG_DIR`` (trimmed, tilde-expanded) if set.+ 2. ``$HEADROOM_WORKSPACE_DIR/config`` when the workspace env var is set+ so that a single override relocates both roots coherently.+ 3. ``~/.headroom/config`` otherwise.+ """++ env_value = _env(HEADROOM_CONFIG_DIR_ENV)+ if env_value:+ return Path(env_value).expanduser()+ workspace_env = _env(HEADROOM_WORKSPACE_DIR_ENV)+ if workspace_env:+ return Path(workspace_env).expanduser() / _CONFIG_DIR_DEFAULT_SUFFIX+ return Path.home() / _WORKSPACE_DIR_DEFAULT / _CONFIG_DIR_DEFAULT_SUFFIX+++def ensure_workspace_dir() -> Path:+ """Return :func:`workspace_dir`, creating it if it does not yet exist."""++ path = workspace_dir()+ path.mkdir(parents=True, exist_ok=True)+ return path+++def ensure_config_dir() -> Path:+ """Return :func:`config_dir`, creating it if it does not yet exist."""++ path = config_dir()+ path.mkdir(parents=True, exist_ok=True)+ return path+++# ---------------------------------------------------------------------------+# Per-resource helpers -- workspace bucket+# ---------------------------------------------------------------------------+++def savings_path(explicit: str | os.PathLike[str] | None = None) -> Path:+ """Return the path for the proxy savings JSON ledger."""++ return _resolve(+ explicit,+ HEADROOM_SAVINGS_PATH_ENV,+ workspace_dir() / _SAVINGS_FILE,+ )+++def toin_path(explicit: str | os.PathLike[str] | None = None) -> Path:+ """Return the path for the TOIN telemetry JSON file.++ TOIN is classified as workspace state because it is actively written by+ the running proxy (it's a compression feedback loop). The default stays+ ``~/.headroom/toin.json`` to preserve byte-for-byte backward compat.+ """++ return _resolve(+ explicit,+ HEADROOM_TOIN_PATH_ENV,+ workspace_dir() / _TOIN_FILE,+ )+++def subscription_state_path(explicit: str | os.PathLike[str] | None = None) -> Path:+ """Return the path for the subscription tracker state JSON."""++ return _resolve(+ explicit,+ HEADROOM_SUBSCRIPTION_STATE_PATH_ENV,+ workspace_dir() / _SUBSCRIPTION_FILE,+ )+++def memory_db_path() -> Path:+ """Return the default memory SQLite path."""++ return workspace_dir() / _MEMORY_DB_FILE+++def native_memory_dir() -> Path:+ """Return the default native-memory directory."""++ return workspace_dir() / _MEMORIES_DIR+++def license_cache_path() -> Path:+ """Return the path for the cached license envelope."""++ return workspace_dir() / _LICENSE_CACHE_FILE+++def session_stats_path() -> Path:+ """Return the path for the per-session stats JSONL file."""++ return workspace_dir() / _SESSION_STATS_FILE+++def sync_state_path() -> Path:+ """Return the path for memory sync state."""++ return workspace_dir() / _SYNC_STATE_FILE+++def bridge_state_path() -> Path:+ """Return the path for the memory bridge state."""++ return workspace_dir() / _BRIDGE_STATE_FILE+++def log_dir() -> Path:+ """Return the directory for Headroom log files."""++ return workspace_dir() / _LOGS_DIR+++def proxy_log_path() -> Path:+ """Return the path for the proxy log file."""++ return log_dir() / _PROXY_LOG_FILE+++def debug_400_dir() -> Path:+ """Return the directory used to stash HTTP 400 debug payloads."""++ return log_dir() / _DEBUG_400_DIR+++def bin_dir() -> Path:+ """Return the directory where Headroom ships vendored binaries."""++ return workspace_dir() / _BIN_DIR+++def rtk_path() -> Path:+ """Return the path to the vendored ``rtk`` binary."""++ name = _RTK_WIN if os.name == "nt" else _RTK_UNIX+ return bin_dir() / name+++def deploy_root() -> Path:+ """Return the root directory for persistent deployment profiles."""++ return workspace_dir() / _DEPLOY_DIR+++def beacon_lock_path(port: int) -> Path:+ """Return the per-port proxy beacon lock file path."""++ return workspace_dir() / f".beacon_lock_{int(port)}"+++# ---------------------------------------------------------------------------+# Per-resource helpers -- config bucket+# ---------------------------------------------------------------------------+++def models_config_path() -> Path:+ """Return the default path for the models catalog JSON.++ Note: the ``HEADROOM_MODEL_LIMITS`` env var is a *content* override+ (it can hold either a JSON string or a filesystem path) and is handled+ by the provider layer. This helper only returns the default file+ location and deliberately ignores ``HEADROOM_MODEL_LIMITS``.+ """++ return config_dir() / _MODELS_FILE+++# ---------------------------------------------------------------------------+# Plugin-author entry points+# ---------------------------------------------------------------------------+++def plugin_config_dir(plugin_name: str) -> Path:+ """Return the config directory for a named plugin."""++ if not plugin_name or "/" in plugin_name or "\\" in plugin_name:+ raise ValueError(f"invalid plugin name: {plugin_name!r}")+ return config_dir() / _PLUGINS_DIR / plugin_name+++def plugin_workspace_dir(plugin_name: str) -> Path:+ """Return the workspace directory for a named plugin."""++ if not plugin_name or "/" in plugin_name or "\\" in plugin_name:+ raise ValueError(f"invalid plugin name: {plugin_name!r}")+ return workspace_dir() / _PLUGINS_DIR / plugin_name+++__all__ = [+ "HEADROOM_CONFIG_DIR_ENV",+ "HEADROOM_WORKSPACE_DIR_ENV",+ "HEADROOM_SAVINGS_PATH_ENV",+ "HEADROOM_TOIN_PATH_ENV",+ "HEADROOM_SUBSCRIPTION_STATE_PATH_ENV",+ "config_dir",+ "workspace_dir",+ "ensure_config_dir",+ "ensure_workspace_dir",+ "savings_path",+ "toin_path",+ "subscription_state_path",+ "memory_db_path",+ "native_memory_dir",+ "license_cache_path",+ "session_stats_path",+ "sync_state_path",+ "bridge_state_path",+ "log_dir",+ "proxy_log_path",+ "debug_400_dir",+ "bin_dir",+ "rtk_path",+ "deploy_root",+ "beacon_lock_path",+ "models_config_path",+ "plugin_config_dir",+ "plugin_workspace_dir",+]diff --git a/tests/test_paths.py b/tests/test_paths.pynew file mode 100644index 000000000..c70a728a3--- /dev/null+++ b/tests/test_paths.py@@ -0,0 +1,391 @@+"""Tests for ``headroom.paths`` -- canonical filesystem contract."""++from __future__ import annotations++import os+from pathlib import Path++import pytest++from headroom import paths++# ---------------------------------------------------------------------------+# Helpers+# ---------------------------------------------------------------------------+++def clean_env(monkeypatch: pytest.MonkeyPatch) -> pytest.MonkeyPatch:+ """Ensure every HEADROOM_* env var this module touches is unset."""++ for name in (+ paths.HEADROOM_CONFIG_DIR_ENV,+ paths.HEADROOM_WORKSPACE_DIR_ENV,+ paths.HEADROOM_SAVINGS_PATH_ENV,+ paths.HEADROOM_TOIN_PATH_ENV,+ paths.HEADROOM_SUBSCRIPTION_STATE_PATH_ENV,+ ):+ monkeypatch.delenv(name, raising=False)+ return monkeypatch+++def fake_home(clean_env: pytest.MonkeyPatch, tmp_path: Path) -> Path:+ """Redirect ``Path.home()`` to ``tmp_path`` for isolation."""++ clean_env.setenv("HOME", str(tmp_path))+ # On Windows ``Path.home()`` reads ``USERPROFILE`` first, then ``HOME``.+ clean_env.setenv("USERPROFILE", str(tmp_path))+ return tmp_path+++# ---------------------------------------------------------------------------+# Canonical roots+# ---------------------------------------------------------------------------+++def test_workspace_dir_default(fake_home: Path) -> None:+ assert paths.workspace_dir() == fake_home / ".headroom"+++def test_workspace_dir_env_override(+ fake_home: Path, clean_env: pytest.MonkeyPatch, tmp_path: Path+) -> None:+ override = tmp_path / "alt_ws"+ clean_env.setenv(paths.HEADROOM_WORKSPACE_DIR_ENV, str(override))+ assert paths.workspace_dir() == override+++def test_workspace_dir_tilde_expansion(fake_home: Path, clean_env: pytest.MonkeyPatch) -> None:+ clean_env.setenv(paths.HEADROOM_WORKSPACE_DIR_ENV, "~/custom")+ assert paths.workspace_dir() == fake_home / "custom"+++def test_workspace_dir_blank_env_is_ignored(fake_home: Path, clean_env: pytest.MonkeyPatch) -> None:+ clean_env.setenv(paths.HEADROOM_WORKSPACE_DIR_ENV, " ")+ assert paths.workspace_dir() == fake_home / ".headroom"+++def test_config_dir_default(fake_home: Path) -> None:+ assert paths.config_dir() == fake_home / ".headroom" / "config"+++def test_config_dir_follows_workspace_when_only_workspace_set(+ fake_home: Path, clean_env: pytest.MonkeyPatch, tmp_path: Path+) -> None:+ override = tmp_path / "alt_ws"+ clean_env.setenv(paths.HEADROOM_WORKSPACE_DIR_ENV, str(override))+ assert paths.config_dir() == override / "config"+++def test_config_dir_explicit_env_overrides_workspace(+ fake_home: Path, clean_env: pytest.MonkeyPatch, tmp_path: Path+) -> None:+ clean_env.setenv(paths.HEADROOM_WORKSPACE_DIR_ENV, str(tmp_path / "ws"))+ config_override = tmp_path / "cfg"+ clean_env.setenv(paths.HEADROOM_CONFIG_DIR_ENV, str(config_override))+ assert paths.config_dir() == config_override+++def test_config_dir_tilde_expansion(fake_home: Path, clean_env: pytest.MonkeyPatch) -> None:+ clean_env.setenv(paths.HEADROOM_CONFIG_DIR_ENV, "~/cfg")+ assert paths.config_dir() == fake_home / "cfg"+++# ---------------------------------------------------------------------------+# Ensure-* side effects+# ---------------------------------------------------------------------------+++def test_workspace_dir_getter_no_mkdir(fake_home: Path) -> None:+ target = paths.workspace_dir()+ assert not target.exists()+ # Calling again must still not create it.+ assert not paths.workspace_dir().exists()+++def test_config_dir_getter_no_mkdir(fake_home: Path) -> None:+ target = paths.config_dir()+ assert not target.exists()+++def test_ensure_workspace_dir_creates(fake_home: Path) -> None:+ result = paths.ensure_workspace_dir()+ assert result.is_dir()+ assert result == fake_home / ".headroom"+++def test_ensure_config_dir_creates(fake_home: Path) -> None:+ result = paths.ensure_config_dir()+ assert result.is_dir()+ assert result == fake_home / ".headroom" / "config"+++def test_per_resource_getters_no_mkdir(fake_home: Path) -> None:+ # None of these should trigger directory creation.+ paths.savings_path()+ paths.toin_path()+ paths.subscription_state_path()+ paths.memory_db_path()+ paths.native_memory_dir()+ paths.license_cache_path()+ paths.session_stats_path()+ paths.sync_state_path()+ paths.bridge_state_path()+ paths.log_dir()+ paths.proxy_log_path()+ paths.debug_400_dir()+ paths.bin_dir()+ paths.rtk_path()+ paths.deploy_root()+ paths.beacon_lock_path(8787)+ paths.models_config_path()+ paths.plugin_config_dir("example")+ paths.plugin_workspace_dir("example")+ assert not (fake_home / ".headroom").exists()+++# ---------------------------------------------------------------------------+# Per-resource precedence matrix+# ---------------------------------------------------------------------------+++RESOURCES_WITH_LEGACY_ENV = [+ pytest.param(+ "savings_path",+ paths.HEADROOM_SAVINGS_PATH_ENV,+ "proxy_savings.json",+ id="savings",+ ),+ pytest.param(+ "toin_path",+ paths.HEADROOM_TOIN_PATH_ENV,+ "toin.json",+ id="toin",+ ),+ pytest.param(+ "subscription_state_path",+ paths.HEADROOM_SUBSCRIPTION_STATE_PATH_ENV,+ "subscription_state.json",+ id="subscription",+ ),+]++[email protected]("fn_name,env_var,filename", RESOURCES_WITH_LEGACY_ENV)+def test_resource_default_under_home(+ fake_home: Path, fn_name: str, env_var: str, filename: str+) -> None:+ fn = getattr(paths, fn_name)+ assert fn() == fake_home / ".headroom" / filename++[email protected]("fn_name,env_var,filename", RESOURCES_WITH_LEGACY_ENV)+def test_resource_derived_from_workspace_env(+ fake_home: Path,+ clean_env: pytest.MonkeyPatch,+ tmp_path: Path,+ fn_name: str,+ env_var: str,+ filename: str,+) -> None:+ ws = tmp_path / "state"+ clean_env.setenv(paths.HEADROOM_WORKSPACE_DIR_ENV, str(ws))+ fn = getattr(paths, fn_name)+ assert fn() == ws / filename++[email protected]("fn_name,env_var,filename", RESOURCES_WITH_LEGACY_ENV)+def test_resource_legacy_env_wins_over_workspace(+ fake_home: Path,+ clean_env: pytest.MonkeyPatch,+ tmp_path: Path,+ fn_name: str,+ env_var: str,+ filename: str,+) -> None:+ ws = tmp_path / "state"+ clean_env.setenv(paths.HEADROOM_WORKSPACE_DIR_ENV, str(ws))+ legacy = tmp_path / "legacy_custom.json"+ clean_env.setenv(env_var, str(legacy))+ fn = getattr(paths, fn_name)+ # Legacy per-resource env var wins. Backward compatibility is preserved.+ assert fn() == legacy++[email protected]("fn_name,env_var,filename", RESOURCES_WITH_LEGACY_ENV)+def test_resource_explicit_arg_wins(+ fake_home: Path,+ clean_env: pytest.MonkeyPatch,+ tmp_path: Path,+ fn_name: str,+ env_var: str,+ filename: str,+) -> None:+ ws = tmp_path / "state"+ clean_env.setenv(paths.HEADROOM_WORKSPACE_DIR_ENV, str(ws))+ legacy = tmp_path / "legacy_custom.json"+ clean_env.setenv(env_var, str(legacy))+ explicit = tmp_path / "explicit.json"+ fn = getattr(paths, fn_name)+ assert fn(str(explicit)) == explicit++[email protected]("fn_name,env_var,filename", RESOURCES_WITH_LEGACY_ENV)+def test_resource_legacy_env_tilde_expansion(+ fake_home: Path,+ clean_env: pytest.MonkeyPatch,+ fn_name: str,+ env_var: str,+ filename: str,+) -> None:+ clean_env.setenv(env_var, "~/foo.json")+ fn = getattr(paths, fn_name)+ assert fn() == fake_home / "foo.json"++[email protected]("fn_name,env_var,filename", RESOURCES_WITH_LEGACY_ENV)+def test_resource_explicit_none_falls_through(+ fake_home: Path,+ clean_env: pytest.MonkeyPatch,+ fn_name: str,+ env_var: str,+ filename: str,+) -> None:+ fn = getattr(paths, fn_name)+ assert fn(None) == fake_home / ".headroom" / filename++[email protected]("fn_name,env_var,filename", RESOURCES_WITH_LEGACY_ENV)+def test_resource_explicit_empty_string_falls_through(+ fake_home: Path,+ clean_env: pytest.MonkeyPatch,+ fn_name: str,+ env_var: str,+ filename: str,+) -> None:+ fn = getattr(paths, fn_name)+ assert fn("") == fake_home / ".headroom" / filename+++# ---------------------------------------------------------------------------+# Resources without a legacy env var (derived-only from canonical roots)+# ---------------------------------------------------------------------------+++def test_memory_db_path_default(fake_home: Path) -> None:+ assert paths.memory_db_path() == fake_home / ".headroom" / "memory.db"+++def test_memory_db_path_follows_workspace_env(+ fake_home: Path, clean_env: pytest.MonkeyPatch, tmp_path: Path+) -> None:+ clean_env.setenv(paths.HEADROOM_WORKSPACE_DIR_ENV, str(tmp_path / "ws"))+ assert paths.memory_db_path() == tmp_path / "ws" / "memory.db"+++def test_native_memory_dir_default(fake_home: Path) -> None:+ assert paths.native_memory_dir() == fake_home / ".headroom" / "memories"+++def test_license_cache_path_default(fake_home: Path) -> None:+ assert paths.license_cache_path() == fake_home / ".headroom" / "license_cache.json"+++def test_session_stats_path_default(fake_home: Path) -> None:+ assert paths.session_stats_path() == fake_home / ".headroom" / "session_stats.jsonl"+++def test_log_dir_default(fake_home: Path) -> None:+ assert paths.log_dir() == fake_home / ".headroom" / "logs"+++def test_debug_400_dir_default(fake_home: Path) -> None:+ assert paths.debug_400_dir() == fake_home / ".headroom" / "logs" / "debug_400"+++def test_bin_dir_default(fake_home: Path) -> None:+ assert paths.bin_dir() == fake_home / ".headroom" / "bin"+++def test_rtk_path_suffix(fake_home: Path) -> None:+ expected_name = "rtk.exe" if os.name == "nt" else "rtk"+ assert paths.rtk_path().name == expected_name+ assert paths.rtk_path().parent == paths.bin_dir()+++def test_deploy_root_default(fake_home: Path) -> None:+ assert paths.deploy_root() == fake_home / ".headroom" / "deploy"+++def test_beacon_lock_path_includes_port(fake_home: Path) -> None:+ assert paths.beacon_lock_path(8787) == fake_home / ".headroom" / ".beacon_lock_8787"+++# ---------------------------------------------------------------------------+# Config bucket+# ---------------------------------------------------------------------------+++def test_models_config_path_default(fake_home: Path) -> None:+ assert paths.models_config_path() == fake_home / ".headroom" / "config" / "models.json"+++def test_models_config_path_follows_config_env(+ fake_home: Path, clean_env: pytest.MonkeyPatch, tmp_path: Path+) -> None:+ clean_env.setenv(paths.HEADROOM_CONFIG_DIR_ENV, str(tmp_path / "cfg"))+ assert paths.models_config_path() == tmp_path / "cfg" / "models.json"+++def test_models_config_path_follows_workspace_env(+ fake_home: Path, clean_env: pytest.MonkeyPatch, tmp_path: Path+) -> None:+ clean_env.setenv(paths.HEADROOM_WORKSPACE_DIR_ENV, str(tmp_path / "ws"))+ assert paths.models_config_path() == tmp_path / "ws" / "config" / "models.json"+++# ---------------------------------------------------------------------------+# Plugin namespace isolation+# ---------------------------------------------------------------------------+++def test_plugin_config_dir_namespaced(fake_home: Path) -> None:+ a = paths.plugin_config_dir("alpha")+ b = paths.plugin_config_dir("beta")+ assert a != b+ assert a == fake_home / ".headroom" / "config" / "plugins" / "alpha"+ assert b == fake_home / ".headroom" / "config" / "plugins" / "beta"+++def test_plugin_workspace_dir_namespaced(fake_home: Path) -> None:+ a = paths.plugin_workspace_dir("alpha")+ b = paths.plugin_workspace_dir("beta")+ assert a != b+ assert a == fake_home / ".headroom" / "plugins" / "alpha"+ assert b == fake_home / ".headroom" / "plugins" / "beta"++[email protected]("bad_name", ["", "foo/bar", "foo\\bar"])+def test_plugin_dirs_reject_bad_names(fake_home: Path, bad_name: str) -> None:+ with pytest.raises(ValueError):+ paths.plugin_config_dir(bad_name)+ with pytest.raises(ValueError):+ paths.plugin_workspace_dir(bad_name)+++# ---------------------------------------------------------------------------+# Returns Path, not str+# ---------------------------------------------------------------------------+++def test_all_helpers_return_path(fake_home: Path) -> None:+ assert isinstance(paths.workspace_dir(), Path)+ assert isinstance(paths.config_dir(), Path)+ assert isinstance(paths.savings_path(), Path)+ assert isinstance(paths.toin_path(), Path)+ assert isinstance(paths.subscription_state_path(), Path)+ assert isinstance(paths.memory_db_path(), Path)+ assert isinstance(paths.models_config_path(), Path)+ assert isinstance(paths.plugin_config_dir("x"), Path)+ assert isinstance(paths.plugin_workspace_dir("x"), Path)