fix: validate named custom provider endpoints

This commit is contained in:
chengyongru
2026-06-13 00:04:13 +08:00
committed by Xubin Ren
parent a9308eb8e2
commit 09d24e6c25
6 changed files with 164 additions and 12 deletions
+35
View File
@@ -688,6 +688,41 @@ def test_make_provider_treats_dynamic_custom_provider_as_direct():
assert kwargs["base_url"] == "https://example.com/v1"
def test_make_provider_rejects_dynamic_custom_provider_without_api_base():
config = Config.model_validate(
{
"agents": {"defaults": {"provider": "my-company-api", "model": "gpt-4o-mini"}},
"providers": {
"my-company-api": {
"apiKey": "sk-test",
}
},
}
)
with pytest.raises(ValueError, match="Provider 'my-company-api' requires api_base"):
make_provider(config)
def test_make_provider_rejects_auto_dynamic_custom_prefix_without_api_base():
config = Config.model_validate(
{
"agents": {"defaults": {"provider": "auto", "model": "companyProxy/gpt-4o"}},
"providers": {
"otherProxy": {
"apiBase": "https://other.example.test/v1",
},
"companyProxy": {
"apiKey": "sk-company",
},
},
}
)
with pytest.raises(ValueError, match="Provider 'companyProxy' requires api_base"):
make_provider(config)
@pytest.fixture
def mock_agent_runtime(tmp_path):
"""Mock agent command dependencies for focused CLI tests."""