test(ui): hit GET /public/providers/fields for the Z.AI catalog row

Greptile flagged the JSON parse test as structure-only. The new test
calls the same public endpoint the Add Credential form uses.
This commit is contained in:
Chaitanya Laxman 2026-09-07 20:46:29 +04:00
parent 980ecf943c
commit ab0e3f7695
2 changed files with 31 additions and 27 deletions

View file

@ -2,7 +2,6 @@
Tests for Z.AI (Zhipu AI) provider - GLM models
"""
import json
import math
import pytest
@ -172,29 +171,3 @@ def test_zai_sync_completion(respx_mock, zai_response, monkeypatch):
assert response.choices[0].message.content == "Hello! How can I help you today?"
assert response.usage.total_tokens == 25
class TestZAIDashboardRegistration:
@staticmethod
def _provider_create_fields():
from pathlib import Path
path = Path(litellm.__file__).parent / "proxy" / "public_endpoints" / "provider_create_fields.json"
with open(path) as f:
return json.load(f)
def test_zai_is_selectable_in_the_add_model_form(self):
entries = [e for e in self._provider_create_fields() if e["litellm_provider"] == "zai"]
assert len(entries) == 1, "zai must appear exactly once in provider_create_fields.json"
entry = entries[0]
assert entry["provider"] == "ZAI"
assert entry["provider_display_name"] == "Z.AI (Zhipu AI)"
assert entry["default_model_placeholder"].startswith("zai/")
fields = {f["key"]: f for f in entry["credential_fields"]}
assert fields["api_key"]["required"] is True
assert fields["api_key"]["field_type"] == "password"
assert fields["api_base"]["required"] is False
assert fields["api_base"]["field_type"] == "text"
assert fields["api_base"]["placeholder"] == "https://api.z.ai/api/paas/v4"

View file

@ -327,6 +327,37 @@ def test_cognition_provider_fields():
assert fields_by_key["api_base"]["required"] is False
def test_zai_provider_fields():
"""Z.AI must be selectable in the Add Credential flow (#39310).
The form is driven by GET /public/providers/fields. Without a ZAI row the
UI shows only Credential Name and Provider, so the key cannot be saved.
"""
app_instance = FastAPI()
app_instance.include_router(router)
test_client = TestClient(app_instance)
response = test_client.get("/public/providers/fields")
assert response.status_code == 200
providers = response.json()
zai = next((p for p in providers if p["provider"] == "ZAI"), None)
assert zai is not None, "Z.AI provider entry not found"
assert zai["provider_display_name"] == "Z.AI (Zhipu AI)"
assert zai["litellm_provider"] == "zai"
assert zai["default_model_placeholder"].startswith("zai/")
fields_by_key = {f["key"]: f for f in zai["credential_fields"]}
assert fields_by_key["api_key"]["required"] is True
assert fields_by_key["api_key"]["field_type"] == "password"
assert fields_by_key["api_base"]["required"] is False
assert fields_by_key["api_base"]["field_type"] == "text"
assert fields_by_key["api_base"]["placeholder"] == "https://api.z.ai/api/paas/v4"
def test_google_ai_studio_provider_fields_expose_api_base():
"""The Google AI Studio (gemini) credential form must let admins set a custom
api_base so they can point at a Gemini-compatible gateway (e.g. a self-hosted