Skip to content

The agent that grows with you

test: trim provider-id regression tests to two load_config invariants

teknium1fd9e7df0c4b1
diff --git a/tests/hermes_cli/test_config_provider_id_string.py b/tests/hermes_cli/test_config_provider_id_string.py
index 6bf440c28bd..71c8d530c3a 100644
--- a/tests/hermes_cli/test_config_provider_id_string.py
+++ b/tests/hermes_cli/test_config_provider_id_string.py
@@ -1,89 +1,33 @@
-"""Regression tests: ``model.provider`` must survive config load as a string.
+"""Regression for #117345: ``model.provider`` must survive config load as a string.
-An unquoted YAML scalar (``provider: 2``) loads as ``int``, and every downstream
-reader does ``(provider or "").strip()`` — a gateway turn dies before the agent
-runs (#117345). The load-path chokepoint (``_normalize_root_model_keys``) is where
-the value is canonicalized, so it must emit a string for every carrier: a plain
-``model.provider``, the legacy root-level ``provider`` alias, and the nested
-``{provider: <p>, model: <m>}`` flattening.
+An unquoted YAML scalar (``provider: 2``) loads as ``int``, and downstream readers
+do ``(provider or "").strip()`` — a gateway turn dies before the agent runs. The
+load-path chokepoint (``_normalize_root_model_keys``) canonicalizes the value, so
+``load_config()`` — the gateway's exact entry — is the surface under test.
"""
import os
from unittest.mock import patch
-import yaml
+from hermes_cli.config import load_config
-from hermes_cli.config import _normalize_root_model_keys, load_config
+def _load(tmp_path, model_section: str):
+ (tmp_path / "config.yaml").write_text(f"model:\n{model_section}", encoding="utf-8")
+ with patch.dict(os.environ, {"HERMES_HOME": str(tmp_path)}):
+ return load_config()
-class TestNormalizeProviderIdIsString:
- """model.provider reaches readers as ``str`` regardless of YAML scalar type."""
- def test_int_model_provider_is_stringified(self):
- config = {"model": {"default": "m", "provider": 2}}
- out = _normalize_root_model_keys(dict(config))
- assert out["model"]["provider"] == "2"
- assert isinstance(out["model"]["provider"], str)
+def test_unquoted_numeric_provider_loads_as_string(tmp_path):
+ # ``0`` is also falsy: a stringified "0" must not be dropped or blanked by the
+ # ``root_val and ...`` / ``(provider or "")`` guards on the way through.
+ for scalar in ("2", "0", "2.0"):
+ config = _load(tmp_path, f" default: deepseek-flash\n provider: {scalar}\n")
+ assert config["model"]["provider"] == scalar, scalar
- def test_str_model_provider_is_not_perturbed(self):
- config = {"model": {"default": "m", "provider": "glm-flash"}}
- out = _normalize_root_model_keys(dict(config))
- assert out["model"]["provider"] == "glm-flash"
- def test_legacy_root_provider_alias_is_stringified(self):
- config = {"provider": 2, "base_url": "https://api.example.com/v1",
- "model": {"default": "m"}}
- out = _normalize_root_model_keys(dict(config))
- assert out["model"]["provider"] == "2"
- assert isinstance(out["model"]["provider"], str)
-
- def test_nested_provider_flatten_is_stringified(self):
- config = {"model": {"default": {"provider": 2, "model": "m"}}}
- out = _normalize_root_model_keys(dict(config))
- provider = out["model"]["provider"]
- assert provider == "2"
- assert isinstance(provider, str)
-
-
-class TestLoadConfigIntProviderEndToEnd:
- """E2E through the real config.yaml path — the gateway's exact entry."""
-
- def test_unquoted_yaml_provider_loads_as_string(self, tmp_path):
- # Unquoted 2 is what `hermes config set model.provider 2` writes and
- # what PyYAML loads as int (the #117345 write-side bug shape).
- (tmp_path / "config.yaml").write_text(
- "model:\n default: deepseek-flash\n provider: 2\n", encoding="utf-8"
- )
- with patch.dict(os.environ, {"HERMES_HOME": str(tmp_path)}):
- config = load_config()
- provider = config["model"]["provider"]
- assert provider == "2"
- assert isinstance(provider, str)
-
- def test_provider_zero_and_negative_are_preserved_as_strings(self, tmp_path):
- # 0 is falsy: the normalize loop uses `root_val and ...`, and readers use
- # `(provider or "")` — a stringified "0" must not be dropped or blanked.
- (tmp_path / "config.yaml").write_text(
- "model:\n default: m\n provider: 0\n", encoding="utf-8"
- )
- with patch.dict(os.environ, {"HERMES_HOME": str(tmp_path)}):
- config = load_config()
- assert config["model"]["provider"] == "0"
-
- def test_absent_provider_key_is_not_injected(self, tmp_path):
- # A provider-less model section must not gain an empty provider key:
- # injecting one would rewrite config.yaml on the next save.
- (tmp_path / "config.yaml").write_text(
- "model:\n default: deepseek-flash\n", encoding="utf-8"
- )
- with patch.dict(os.environ, {"HERMES_HOME": str(tmp_path)}):
- config = load_config()
- assert "provider" not in config["model"]
-
- def test_float_provider_becomes_its_literal_string(self, tmp_path):
- (tmp_path / "config.yaml").write_text(
- "model:\n default: m\n provider: 2.0\n", encoding="utf-8"
- )
- with patch.dict(os.environ, {"HERMES_HOME": str(tmp_path)}):
- config = load_config()
- assert config["model"]["provider"] == "2.0"
+def test_absent_provider_key_is_not_injected(tmp_path):
+ # Coercing ``None`` would yield ""; an injected empty key rewrites config.yaml on
+ # the next save, so a provider-less model section must come back without one.
+ config = _load(tmp_path, " default: deepseek-flash\n")
+ assert "provider" not in config["model"]