mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
In Docker, HERMES_HOME=/opt/data (set in Dockerfile) and users mount their .hermes directory to /opt/data. However, profile operations used Path.home() / '.hermes' which resolves to /root/.hermes in Docker — an ephemeral container path, not the mounted volume. This caused: - Profiles created at /root/.hermes/profiles/ (lost on container recreate) - active_profile sticky file written to wrong location - profile list looking at wrong directory Fix: Add get_default_hermes_root() to hermes_constants.py that detects Docker/custom deployments (HERMES_HOME outside ~/.hermes) and returns HERMES_HOME as the root. Also handles Docker profiles correctly (<root>/profiles/<name> → root is grandparent). Files changed: - hermes_constants.py: new get_default_hermes_root() - hermes_cli/profiles.py: _get_default_hermes_home() delegates to shared fn - hermes_cli/main.py: _apply_profile_override() + _invalidate_update_cache() - hermes_cli/gateway.py: _profile_suffix() + _profile_arg() - Tests: 12 new tests covering Docker scenarios
62 lines
2.7 KiB
Python
62 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
|