From d6cf383d745f91462d46df96e71f57a72e7300ee Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Thu, 25 Jun 2026 11:57:47 +0530 Subject: [PATCH] =?UTF-8?q?refactor(setup):=20simplify=20Z.AI=20picker=20?= =?UTF-8?q?=E2=80=94=20drop=20dead=20fallback,=20fix=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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. --- hermes_cli/model_setup_flows.py | 4 ++-- tests/hermes_cli/test_model_provider_persistence.py | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/hermes_cli/model_setup_flows.py b/hermes_cli/model_setup_flows.py index be9ecd612ff..458b442c362 100644 --- a/hermes_cli/model_setup_flows.py +++ b/hermes_cli/model_setup_flows.py @@ -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() diff --git a/tests/hermes_cli/test_model_provider_persistence.py b/tests/hermes_cli/test_model_provider_persistence.py index bc4c1dfa32e..76d5ee7414d 100644 --- a/tests/hermes_cli/test_model_provider_persistence.py +++ b/tests/hermes_cli/test_model_provider_persistence.py @@ -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"):