refactor(setup): simplify Z.AI picker — drop dead fallback, fix tests

- Remove dead `chosen_base or effective_base` fallback; _select_zai_endpoint
  always returns a non-empty base URL (returns current_base on cancel).
- Add .rstrip("/") to official-endpoint return for symmetry with custom-proxy
  path (both now return normalized URLs).
- Replace magic index 4 with len(ZAI_ENDPOINTS) in custom-proxy tests so they
  don't break if a 5th endpoint is added to ZAI_ENDPOINTS.
This commit is contained in:
kshitijk4poor 2026-06-25 11:57:47 +05:30 committed by kshitij
parent d0df264213
commit d6cf383d74
2 changed files with 8 additions and 5 deletions

View file

@ -2275,7 +2275,7 @@ def _select_zai_endpoint(current_base: str) -> str:
return current_base
return override.rstrip("/")
return options[selected][1]
return options[selected][1].rstrip("/")
def _model_flow_api_key_provider(config, provider_id, current_model=""):
@ -2400,7 +2400,7 @@ def _model_flow_api_key_provider(config, provider_id, current_model=""):
chosen_base = _select_zai_endpoint(effective_base)
if chosen_base and chosen_base != effective_base and base_url_env:
save_env_value(base_url_env, chosen_base)
effective_base = chosen_base or effective_base
effective_base = chosen_base
else:
try:
override = input(f"Base URL [{effective_base}]: ").strip()

View file

@ -462,8 +462,9 @@ class TestZaiEndpointPicker:
monkeypatch.setenv("GLM_API_KEY", "test-key")
# Last option index = custom proxy
with patch("hermes_cli.main._prompt_provider_choice", return_value=4), \
from hermes_cli.auth import ZAI_ENDPOINTS
custom_idx = len(ZAI_ENDPOINTS) # last option = custom proxy
with patch("hermes_cli.main._prompt_provider_choice", return_value=custom_idx), \
patch("hermes_cli.auth._prompt_model_selection", return_value="glm-5"), \
patch("hermes_cli.auth.deactivate_provider"), \
patch("builtins.input", return_value="https://proxy.example.com/glm/v4"):
@ -479,8 +480,10 @@ class TestZaiEndpointPicker:
monkeypatch.setenv("GLM_API_KEY", "test-key")
monkeypatch.delenv("GLM_BASE_URL", raising=False)
from hermes_cli.auth import ZAI_ENDPOINTS
custom_idx = len(ZAI_ENDPOINTS)
with patch("hermes_cli.main._prompt_provider_choice", return_value=4), \
with patch("hermes_cli.main._prompt_provider_choice", return_value=custom_idx), \
patch("hermes_cli.auth._prompt_model_selection", return_value="glm-5"), \
patch("hermes_cli.auth.deactivate_provider"), \
patch("builtins.input", return_value="not-a-url"):