Skip to content

The agent that grows with you

fix(config): good-config backup only for the active home; fixture-based effective-config contract

teknium15aa1a50c575c
diff --git a/hermes_cli/config_effective.py b/hermes_cli/config_effective.py
index 518dc47fb72..d37d82d0a0f 100644
--- a/hermes_cli/config_effective.py
+++ b/hermes_cli/config_effective.py
@@ -88,8 +88,11 @@ def load_user_config_effective(config_path: Optional[Path] = None, *, fail_close
_config._RAW_CONFIG_CACHE[path_key] = (*user_sig, copy.deepcopy(raw))
_LAST_GOOD_USER_RAW[path_key] = copy.deepcopy(raw)
# Same copy load_config keeps: a fresh process recovers from it (see _recover_user_raw).
- from hermes_cli.config_backups import backup_config
- backup_config(config_path, "good")
+ # Only for the ACTIVE home — a read of another profile's file (doctor, TUI cwd lookup)
+ # must not create backups/ inside that profile.
+ if config_path == _config.get_config_path():
+ from hermes_cli.config_backups import backup_config
+ backup_config(config_path, "good")
env_snapshot = _config._env_ref_snapshot(raw)
managed = managed_scope.load_managed_config()
diff --git a/tests/gateway/test_custom_provider_request_overrides.py b/tests/gateway/test_custom_provider_request_overrides.py
index 4089095647d..f052cdc8ffe 100644
--- a/tests/gateway/test_custom_provider_request_overrides.py
+++ b/tests/gateway/test_custom_provider_request_overrides.py
@@ -171,7 +171,6 @@ def test_turn_route_merges_fast_mode_with_provider_request_overrides():
@pytest.mark.asyncio
async def test_run_agent_preserves_provider_request_overrides_on_gateway_path(monkeypatch):
- monkeypatch.setattr(gateway_run, "_load_gateway_config", lambda: {})
monkeypatch.setattr(gateway_run, "_load_gateway_config", lambda: {})
monkeypatch.setattr(gateway_run, "_resolve_gateway_model", lambda config=None: "gpt-5.4")
monkeypatch.setattr(
@@ -228,7 +227,6 @@ async def test_reused_agent_turn_merges_request_overrides_not_overwrite(monkeypa
fast-mode key while the provider extra_body survives.
"""
monkeypatch.setattr(gateway_run, "_load_gateway_config", lambda: {})
- monkeypatch.setattr(gateway_run, "_load_gateway_config", lambda: {})
monkeypatch.setattr(gateway_run, "_resolve_gateway_model", lambda config=None: "gpt-5.4")
monkeypatch.setattr(
gateway_run,
diff --git a/tests/gateway/test_fast_command.py b/tests/gateway/test_fast_command.py
index e573df9d879..e72c1189eba 100644
--- a/tests/gateway/test_fast_command.py
+++ b/tests/gateway/test_fast_command.py
@@ -154,7 +154,6 @@ async def test_session_fast_override_beats_config_default(monkeypatch, tmp_path)
runner = _make_runner()
monkeypatch.setattr(gateway_run, "_hermes_home", tmp_path)
- monkeypatch.setattr(gateway_run, "_load_gateway_config", lambda: {})
monkeypatch.setattr(
gateway_run,
"_load_gateway_config",
diff --git a/tests/gateway/test_multiplex_busy_input_mode.py b/tests/gateway/test_multiplex_busy_input_mode.py
index da77663d845..e5ca3cbb17c 100644
--- a/tests/gateway/test_multiplex_busy_input_mode.py
+++ b/tests/gateway/test_multiplex_busy_input_mode.py
@@ -445,7 +445,6 @@ async def test_effective_mode_uses_startup_snapshot_without_rereading_config(
raise AssertionError("busy-mode lookup reread config after startup")
monkeypatch.setattr(gateway_run, "_load_gateway_config", fail_config_read)
- monkeypatch.setattr(gateway_run, "_load_gateway_config", fail_config_read)
assert runner._effective_busy_input_mode(source) == "steer"
assert runner._effective_busy_input_mode(source) == "steer"
diff --git a/tests/gateway/test_streaming_tts_gateway_regression.py b/tests/gateway/test_streaming_tts_gateway_regression.py
index 8a1241dbff6..fa6fb5e2c49 100644
--- a/tests/gateway/test_streaming_tts_gateway_regression.py
+++ b/tests/gateway/test_streaming_tts_gateway_regression.py
@@ -97,7 +97,6 @@ def _setup_monkeypatches(monkeypatch, tmp_path):
(tmp_path / "config.yaml").write_text("agent:\n model: test-model\n", encoding="utf-8")
monkeypatch.setattr(gateway_run, "_hermes_home", tmp_path)
monkeypatch.setattr(gateway_run, "_env_path", tmp_path / ".env")
- monkeypatch.setattr(gateway_run, "_load_gateway_config", lambda: {})
monkeypatch.setattr(
gateway_run,
"_load_gateway_config",
diff --git a/tests/hermes_cli/test_config_effective.py b/tests/hermes_cli/test_config_effective.py
index 92a6260da45..6ddb4fc0b52 100644
--- a/tests/hermes_cli/test_config_effective.py
+++ b/tests/hermes_cli/test_config_effective.py
@@ -4,6 +4,7 @@ bootstrap modules) goes through."""
import textwrap
import pytest
+import yaml
@pytest.fixture
@@ -52,20 +53,12 @@ MANAGED_YAML = """
"""
-def _legacy_gateway_pipeline(config_path):
- """The pre-unification gateway sequence (raw read → overlay → model-key canon → ${VAR} expansion)."""
- from hermes_cli import managed_scope
- from hermes_cli.config import _expand_env_vars, _normalize_root_model_keys, read_user_config_raw
-
- raw = managed_scope.apply_managed_overlay(read_user_config_raw(config_path))
- return _expand_env_vars(_normalize_root_model_keys(raw))
-
-
-def test_effective_equals_legacy_gateway_pipeline_and_carries_no_defaults(homes):
- """Contract: the shared loader returns byte-for-byte what the gateway's hand-rolled pipeline did
- for a user file with a managed overlay and ``${VAR}`` refs on both layers — so per-message
- gateway config reads (and the system prompt built from them) do not change — while never
- merging DEFAULT_CONFIG (a missing key stays missing)."""
+def test_effective_is_user_plus_managed_plus_env_with_no_defaults(homes):
+ """Contract as a fixture: given user config.yaml X, managed overlay Y and env Z, the effective
+ dict is exactly this literal — ``${VAR}`` expanded on both layers, managed keys winning,
+ root ``provider`` migrated under ``model``, and no DEFAULT_CONFIG key introduced (a missing
+ key stays missing). Per-message gateway reads (and the system prompt built from them) are
+ pinned by this shape, not by re-running the implementation's primitives."""
from hermes_cli.config import DEFAULT_CONFIG
from hermes_cli.config_effective import load_user_config_effective
@@ -75,13 +68,16 @@ def test_effective_equals_legacy_gateway_pipeline_and_carries_no_defaults(homes)
effective = load_user_config_effective(home / "config.yaml")
- assert effective == _legacy_gateway_pipeline(home / "config.yaml")
- assert effective["model"] == {
- "default": "user/model", "provider": "custom", "api_key": "user-secret",
- "base_url": "https://managed.example"}
- assert effective["display"]["skin"] == "managed-skin"
- assert "provider" not in effective # root key migrated under ``model`` (canonicalization applied)
- assert "agent" not in effective and "agent" in DEFAULT_CONFIG # no DEFAULT_CONFIG merge
+ assert effective == {
+ "model": {
+ "default": "user/model",
+ "provider": "custom",
+ "api_key": "user-secret",
+ "base_url": "https://managed.example",
+ },
+ "display": {"skin": "managed-skin"},
+ }
+ assert "agent" in DEFAULT_CONFIG # would be present if defaults had been merged
def test_broken_yaml_serves_last_good_and_fail_closed_raises(homes):
@@ -98,10 +94,28 @@ def test_broken_yaml_serves_last_good_and_fail_closed_raises(homes):
_reset_caches_keep_last_good()
assert load_user_config_effective(home / "config.yaml") == good
- with pytest.raises(Exception):
+ with pytest.raises(yaml.YAMLError): # the type _refresh_fallback_model's own last-good path keys on
load_user_config_effective(home / "config.yaml", fail_closed=True)
+def test_good_backup_is_written_only_for_the_active_home(homes, tmp_path):
+ """Reading ANOTHER profile's config (doctor, TUI cwd lookup) is a read: it must not create
+ ``backups/config/`` inside that profile. The active home keeps the last-good copy."""
+ from hermes_cli.config_effective import load_user_config_effective
+
+ home, _ = homes
+ other = tmp_path / "other-profile"
+ other.mkdir()
+ _write(home / "config.yaml", USER_YAML)
+ _write(other / "config.yaml", USER_YAML)
+
+ load_user_config_effective(other / "config.yaml")
+ load_user_config_effective(home / "config.yaml")
+
+ assert not (other / "backups").exists()
+ assert list((home / "backups" / "config").glob("config.yaml.good.*"))
+
+
def _reset_caches_keep_last_good():
import hermes_cli.config as cfg
from hermes_cli import config_effective