fix(honcho): respect HOME-anchored default profile fallback

This commit is contained in:
Billard 2026-04-08 16:03:15 +02:00 committed by Teknium
parent 4ca5e72444
commit d18618f48f
2 changed files with 35 additions and 8 deletions

View file

@ -21,6 +21,7 @@ from dataclasses import dataclass, field
from pathlib import Path
from hermes_constants import get_hermes_home
from hermes_cli.profiles import _get_default_hermes_home
from typing import Any, TYPE_CHECKING
if TYPE_CHECKING:
@ -73,7 +74,7 @@ def resolve_config_path() -> Path:
return local_path
# Default profile's config — host blocks accumulate here via setup/clone
default_path = Path.home() / ".hermes" / "honcho.json"
default_path = _get_default_hermes_home() / "honcho.json"
if default_path != local_path and default_path.exists():
return default_path

View file

@ -6,6 +6,8 @@ import os
from pathlib import Path
from unittest.mock import patch, MagicMock
from hermes_cli.profiles import _get_default_hermes_home
import pytest
from plugins.memory.honcho.client import (
@ -349,18 +351,22 @@ class TestResolveConfigPath:
result = resolve_config_path()
assert result == local_cfg
def test_falls_back_to_global_when_no_local(self, tmp_path):
def test_falls_back_to_default_profile_when_no_local(self, tmp_path, monkeypatch):
hermes_home = tmp_path / "hermes"
hermes_home.mkdir()
# No honcho.json in HERMES_HOME — also isolate ~/.hermes so
# the default-profile fallback doesn't hit the real filesystem.
fake_home = tmp_path / "fakehome"
fake_home.mkdir()
default_cfg = fake_home / ".hermes" / "honcho.json"
default_cfg.parent.mkdir(parents=True)
default_cfg.write_text('{"apiKey": "default-key"}')
with patch.dict(os.environ, {"HERMES_HOME": str(hermes_home)}), \
patch.object(Path, "home", return_value=fake_home):
result = resolve_config_path()
assert result == fake_home / ".honcho" / "config.json"
monkeypatch.setattr(Path, "home", lambda: fake_home)
monkeypatch.setenv("HERMES_HOME", str(hermes_home))
result = resolve_config_path()
assert _get_default_hermes_home() == fake_home / ".hermes"
assert result == default_cfg
def test_falls_back_to_global_without_hermes_home_env(self, tmp_path):
fake_home = tmp_path / "fakehome"
@ -383,6 +389,26 @@ class TestResolveConfigPath:
assert resolve_global_config_path() == fake_home / ".honcho" / "config.json"
assert resolve_config_path() == fake_home / ".honcho" / "config.json"
def test_from_global_config_uses_default_profile_fallback(self, tmp_path, monkeypatch):
hermes_home = tmp_path / "hermes"
hermes_home.mkdir()
fake_home = tmp_path / "fakehome"
fake_home.mkdir()
default_cfg = fake_home / ".hermes" / "honcho.json"
default_cfg.parent.mkdir(parents=True)
default_cfg.write_text(json.dumps({
"apiKey": "default-key",
"workspace": "default-ws",
}))
monkeypatch.setattr(Path, "home", lambda: fake_home)
monkeypatch.setenv("HERMES_HOME", str(hermes_home))
config = HonchoClientConfig.from_global_config()
assert config.api_key == "default-key"
assert config.workspace_id == "default-ws"
def test_from_global_config_uses_local_path(self, tmp_path):
hermes_home = tmp_path / "hermes"
hermes_home.mkdir()