test: avoid global env-coupled defaults regression

This commit is contained in:
Harlan Zhou
2026-05-25 01:00:13 +00:00
committed by nesquena-hermes
parent f8a7726e09
commit e8b426d825
2 changed files with 10 additions and 24 deletions

View File

@@ -54,10 +54,9 @@ TLS_ENABLED = TLS_CERT is not None and TLS_KEY is not None
# ── State directory (env-overridable, never inside repo) ──────────────────────
_DEFAULT_HERMES_HOME = _platform_default_hermes_home()
_EFFECTIVE_HERMES_HOME = Path(os.getenv("HERMES_HOME", str(_DEFAULT_HERMES_HOME))).expanduser()
STATE_DIR = (
Path(os.getenv("HERMES_WEBUI_STATE_DIR", str(_EFFECTIVE_HERMES_HOME / "webui")))
Path(os.getenv("HERMES_WEBUI_STATE_DIR", str(_DEFAULT_HERMES_HOME / "webui")))
.expanduser()
.resolve()
)

View File

@@ -1,28 +1,15 @@
import importlib
import sys
from pathlib import Path
def _reload(module_name: str):
sys.modules.pop(module_name, None)
return importlib.import_module(module_name)
import api.config as config
import api.profiles as profiles
def test_config_state_dir_defaults_to_hermes_home_webui(monkeypatch, tmp_path):
hermes_home = tmp_path / "hermes-home"
monkeypatch.setenv("HERMES_HOME", str(hermes_home))
monkeypatch.delenv("HERMES_WEBUI_STATE_DIR", raising=False)
cfg = _reload("api.config")
assert cfg.STATE_DIR == hermes_home / "webui"
def test_profiles_unwrap_profile_home_to_base():
base = Path('/tmp/hermes-base')
profile_home = base / 'profiles' / 'webui'
assert profiles._unwrap_profile_home_to_base(profile_home) == base
def test_profiles_resolve_base_home_unwraps_profiles_subdir(monkeypatch, tmp_path):
profile_home = tmp_path / "hermes" / "profiles" / "webui"
monkeypatch.delenv("HERMES_BASE_HOME", raising=False)
monkeypatch.setenv("HERMES_HOME", str(profile_home))
profiles = _reload("api.profiles")
assert profiles._resolve_base_hermes_home() == tmp_path / "hermes"
def test_default_hermes_home_returns_path_object():
home = config._platform_default_hermes_home()
assert isinstance(home, Path)