Skip to content

The agent that grows with you

test(config): save survives a raw read that returns empty

kshitijk4poor39846149cf16
diff --git a/tests/hermes_cli/test_config.py b/tests/hermes_cli/test_config.py
index 9474dbbcb14..3c0e6941327 100644
--- a/tests/hermes_cli/test_config.py
+++ b/tests/hermes_cli/test_config.py
@@ -1978,3 +1978,26 @@ class TestSaveConfigExplicitPathAuthority:
saved = yaml.safe_load(config_path.read_text(encoding="utf-8"))
assert saved["model"] == "test/other"
assert saved["skills"]["write_approval"] is True
+
+ def test_save_survives_cached_raw_read_returning_empty(self, tmp_path):
+ # Real schema sections, each pinned to its (scalar) default value, so the file survives
+ # only if save_config still sees them as explicitly set. ``agent`` is skipped because
+ # canonicalisation rewrites its max_turns shape and would mask the collapse signal.
+ # Only sections whose first value is a scalar: a nested dict/list default would be
+ # stripped element-wise and blur the per-section survival check.
+ sections = {k: v for k, v in DEFAULT_CONFIG.items() if isinstance(v, dict) and v and k != "agent"}
+ chosen = {}
+ for k, v in sections.items():
+ ik, iv = next(iter(v.items()))
+ if not isinstance(iv, (dict, list)):
+ chosen[k] = {ik: iv}
+ assert len(chosen) >= 10, sorted(chosen) # modest floor: a schema reorder must not fail this
+ config_path = tmp_path / "config.yaml"
+ config_path.write_text(yaml.safe_dump(chosen), encoding="utf-8")
+
+ with (patch.dict(os.environ, {"HERMES_HOME": str(tmp_path)}),
+ patch("hermes_cli.config.read_raw_config", return_value={})):
+ save_config(load_config())
+
+ saved = yaml.safe_load(config_path.read_text(encoding="utf-8"))
+ assert set(chosen) <= set(saved), sorted(set(chosen) - set(saved))