63 lines
2.7 KiB
Python
63 lines
2.7 KiB
Python
|
|
"""Tests for hermes_constants module."""
|
||
|
|
|
||
|
|
import os
|
||
|
|
from pathlib import Path
|
||
|
|
from unittest.mock import patch
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
from hermes_constants import get_default_hermes_root
|
||
|
|
|
||
|
|
|
||
|
|
class TestGetDefaultHermesRoot:
|
||
|
|
"""Tests for get_default_hermes_root() — Docker/custom deployment awareness."""
|
||
|
|
|
||
|
|
def test_no_hermes_home_returns_native(self, tmp_path, monkeypatch):
|
||
|
|
"""When HERMES_HOME is not set, returns ~/.hermes."""
|
||
|
|
monkeypatch.delenv("HERMES_HOME", raising=False)
|
||
|
|
monkeypatch.setattr(Path, "home", lambda: tmp_path)
|
||
|
|
assert get_default_hermes_root() == tmp_path / ".hermes"
|
||
|
|
|
||
|
|
def test_hermes_home_is_native(self, tmp_path, monkeypatch):
|
||
|
|
"""When HERMES_HOME = ~/.hermes, returns ~/.hermes."""
|
||
|
|
native = tmp_path / ".hermes"
|
||
|
|
native.mkdir()
|
||
|
|
monkeypatch.setattr(Path, "home", lambda: tmp_path)
|
||
|
|
monkeypatch.setenv("HERMES_HOME", str(native))
|
||
|
|
assert get_default_hermes_root() == native
|
||
|
|
|
||
|
|
def test_hermes_home_is_profile(self, tmp_path, monkeypatch):
|
||
|
|
"""When HERMES_HOME is a profile under ~/.hermes, returns ~/.hermes."""
|
||
|
|
native = tmp_path / ".hermes"
|
||
|
|
profile = native / "profiles" / "coder"
|
||
|
|
profile.mkdir(parents=True)
|
||
|
|
monkeypatch.setattr(Path, "home", lambda: tmp_path)
|
||
|
|
monkeypatch.setenv("HERMES_HOME", str(profile))
|
||
|
|
assert get_default_hermes_root() == native
|
||
|
|
|
||
|
|
def test_hermes_home_is_docker(self, tmp_path, monkeypatch):
|
||
|
|
"""When HERMES_HOME points outside ~/.hermes (Docker), returns HERMES_HOME."""
|
||
|
|
docker_home = tmp_path / "opt" / "data"
|
||
|
|
docker_home.mkdir(parents=True)
|
||
|
|
monkeypatch.setattr(Path, "home", lambda: tmp_path)
|
||
|
|
monkeypatch.setenv("HERMES_HOME", str(docker_home))
|
||
|
|
assert get_default_hermes_root() == docker_home
|
||
|
|
|
||
|
|
def test_hermes_home_is_custom_path(self, tmp_path, monkeypatch):
|
||
|
|
"""Any HERMES_HOME outside ~/.hermes is treated as the root."""
|
||
|
|
custom = tmp_path / "my-hermes-data"
|
||
|
|
custom.mkdir()
|
||
|
|
monkeypatch.setattr(Path, "home", lambda: tmp_path)
|
||
|
|
monkeypatch.setenv("HERMES_HOME", str(custom))
|
||
|
|
assert get_default_hermes_root() == custom
|
||
|
|
|
||
|
|
def test_docker_profile_active(self, tmp_path, monkeypatch):
|
||
|
|
"""When a Docker profile is active (HERMES_HOME=<root>/profiles/<name>),
|
||
|
|
returns the Docker root, not the profile dir."""
|
||
|
|
docker_root = tmp_path / "opt" / "data"
|
||
|
|
profile = docker_root / "profiles" / "coder"
|
||
|
|
profile.mkdir(parents=True)
|
||
|
|
monkeypatch.setattr(Path, "home", lambda: tmp_path)
|
||
|
|
monkeypatch.setenv("HERMES_HOME", str(profile))
|
||
|
|
assert get_default_hermes_root() == docker_root
|