fix(config): preserve custom-provider models maps and metadata through v11->v12 migration (#40573)

Salvaged from #40410; cleaned up, re-verified against main, tests added.

Co-authored-by: rodboev <rodboev@users.noreply.github.com>
This commit is contained in:
Teknium
2026-06-06 18:43:20 -07:00
committed by GitHub
co-authored by rodboev
parent 89929553b4
commit 887295ba54
3 changed files with 133 additions and 16 deletions
+65
View File
@@ -706,6 +706,71 @@ class TestCustomProviderCompatibility:
# custom_providers removed by migration — runtime reads via compat layer
assert "custom_providers" not in raw
def test_v11_upgrade_preserves_custom_provider_model_metadata(self, tmp_path):
config_path = tmp_path / "config.yaml"
model_map = {
"kimi-k2.6": {"context_length": 262144},
"moonshotai/Kimi-K2.6-ACED": {"context_length": 131072},
}
config_path.write_text(
yaml.safe_dump(
{
"_config_version": 11,
"custom_providers": [
{
"name": "Kimi Coding Plan",
"base_url": "https://api.kimi.example.com/coding",
"api_key_env": "KIMI_CODING_API_KEY",
"api_mode": "anthropic_messages",
"model": "kimi-k2.6",
"models": model_map,
"context_length": 262144,
"rate_limit_delay": 0.25,
"discover_models": False,
"extra_body": {
"chat_template_kwargs": {"enable_thinking": False}
},
},
{
"name": "List Models",
"base_url": "https://list.example.com/v1",
"models": ["alpha", "beta"],
},
],
}
),
encoding="utf-8",
)
with patch.dict(os.environ, {"HERMES_HOME": str(tmp_path)}):
migrate_config(interactive=False, quiet=True)
raw = yaml.safe_load(config_path.read_text(encoding="utf-8"))
compatible = get_compatible_custom_providers(raw)
assert "custom_providers" not in raw
provider = raw["providers"]["kimi-coding-plan"]
assert provider["api"] == "https://api.kimi.example.com/coding"
assert provider["key_env"] == "KIMI_CODING_API_KEY"
assert provider["transport"] == "anthropic_messages"
assert provider["default_model"] == "kimi-k2.6"
assert provider["models"] == model_map
assert provider["context_length"] == 262144
assert provider["rate_limit_delay"] == 0.25
assert provider["discover_models"] is False
assert provider["extra_body"] == {
"chat_template_kwargs": {"enable_thinking": False}
}
assert raw["providers"]["list-models"]["models"] == {
"alpha": {},
"beta": {},
}
compatible_provider = next(
entry for entry in compatible if entry["provider_key"] == "kimi-coding-plan"
)
assert compatible_provider["models"] == model_map
assert compatible_provider["key_env"] == "KIMI_CODING_API_KEY"
def test_providers_dict_resolves_at_runtime(self, tmp_path):
"""After migration deleted custom_providers, get_compatible_custom_providers
still finds entries from the providers dict."""
+16 -1
View File
@@ -35,6 +35,10 @@ def _run_migration(hermes_home: Path, **env_overrides: str) -> subprocess.Comple
def test_docker_config_migrate_backs_up_and_migrates_legacy_config(tmp_path: Path) -> None:
config_path = tmp_path / "config.yaml"
env_path = tmp_path / ".env"
model_map = {
"local-small": {"context_length": 8192},
"local-large": {"context_length": 32768},
}
config_path.write_text(
yaml.safe_dump(
{
@@ -44,6 +48,11 @@ def test_docker_config_migrate_backs_up_and_migrates_legacy_config(tmp_path: Pat
"name": "Local API",
"base_url": "http://localhost:8080/v1",
"api_key": "test-key",
"api_mode": "chat_completions",
"model": "local-small",
"models": model_map,
"context_length": 32768,
"discover_models": False,
}
],
}
@@ -59,7 +68,13 @@ def test_docker_config_migrate_backs_up_and_migrates_legacy_config(tmp_path: Pat
raw = yaml.safe_load(config_path.read_text(encoding="utf-8"))
assert raw["_config_version"] == DEFAULT_CONFIG["_config_version"]
assert "custom_providers" not in raw
assert raw["providers"]["local-api"]["api"] == "http://localhost:8080/v1"
provider = raw["providers"]["local-api"]
assert provider["api"] == "http://localhost:8080/v1"
assert provider["transport"] == "chat_completions"
assert provider["default_model"] == "local-small"
assert provider["models"] == model_map
assert provider["context_length"] == 32768
assert provider["discover_models"] is False
assert list(tmp_path.glob("config.yaml.bak-*"))
assert list(tmp_path.glob(".env.bak-*"))