From 805498e6dfed8a95679397feeb34a3e60bb09db2 Mon Sep 17 00:00:00 2001 From: Edizzier Date: Wed, 2 Sep 2026 04:35:11 -0700 Subject: [PATCH] fix(providers): give alibaba-coding-plan-cn its own API key env var ALIBABA_CODING_PLAN_CN_API_KEY is checked first for the China Coding Plan endpoint (mirroring kimi-coding-cn), so the intl and CN rows no longer light off the same key. Fixes #101122. --- .../alibaba-coding-plan/__init__.py | 6 +++- ...alibaba_coding_plan_cn_provider_listing.py | 30 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/hermes_cli/test_alibaba_coding_plan_cn_provider_listing.py diff --git a/plugins/model-providers/alibaba-coding-plan/__init__.py b/plugins/model-providers/alibaba-coding-plan/__init__.py index b420fbbbd9..4723606d0e 100644 --- a/plugins/model-providers/alibaba-coding-plan/__init__.py +++ b/plugins/model-providers/alibaba-coding-plan/__init__.py @@ -9,6 +9,10 @@ Region split, mirroring the base DashScope pair (#73265): Profile names match the models.dev catalog keys exactly so model metadata lines up and ``model.provider: alibaba-coding-plan-cn`` resolves at runtime. + +The CN profile checks its own ``ALIBABA_CODING_PLAN_CN_API_KEY`` first (#101122, +mirroring kimi-coding-cn) and keeps the shared vars as ordered fallbacks so +existing CN users configured with the shared key keep working. """ from providers import register_provider @@ -31,7 +35,7 @@ alibaba_coding_plan_cn = ProviderProfile( display_name="Alibaba Cloud (Coding Plan, China)", description="Alibaba Cloud Coding Plan, mainland-China endpoint", signup_url="https://help.aliyun.com/zh/model-studio/", - env_vars=("ALIBABA_CODING_PLAN_API_KEY", "DASHSCOPE_API_KEY", "ALIBABA_CODING_PLAN_CN_BASE_URL"), + env_vars=("ALIBABA_CODING_PLAN_CN_API_KEY", "ALIBABA_CODING_PLAN_API_KEY", "DASHSCOPE_API_KEY", "ALIBABA_CODING_PLAN_CN_BASE_URL"), base_url="https://coding.dashscope.aliyuncs.com/v1", auth_type="api_key", ) diff --git a/tests/hermes_cli/test_alibaba_coding_plan_cn_provider_listing.py b/tests/hermes_cli/test_alibaba_coding_plan_cn_provider_listing.py new file mode 100644 index 0000000000..6dc59e3338 --- /dev/null +++ b/tests/hermes_cli/test_alibaba_coding_plan_cn_provider_listing.py @@ -0,0 +1,30 @@ +"""alibaba-coding-plan and alibaba-coding-plan-cn must not both appear in the +/model picker off a single shared key (#101122). + +The CN profile now has its own ALIBABA_CODING_PLAN_CN_API_KEY (checked first), +keeping the shared ALIBABA_CODING_PLAN_API_KEY / DASHSCOPE_API_KEY as ordered +fallbacks so existing CN users are not broken. The picker hides a ``-cn`` row +whose only lit vars are shared with a lit non-CN sibling row. +""" + +import os +from unittest.mock import patch + +from hermes_cli.model_switch import list_authenticated_providers + +_CLEAR = {k: "" for k in ("ALIBABA_CODING_PLAN_API_KEY", "ALIBABA_CODING_PLAN_CN_API_KEY", "DASHSCOPE_API_KEY")} + + +def _alibaba_slugs(current_provider=""): + return [p["slug"] for p in list_authenticated_providers(current_provider=current_provider) if "coding-plan" in p["slug"]] + + +@patch.dict(os.environ, {**_CLEAR, "ALIBABA_CODING_PLAN_CN_API_KEY": "sk-cn-fake"}, clear=False) +def test_alibaba_cn_appears_when_only_cn_key_set(): + assert _alibaba_slugs() == ["alibaba-coding-plan-cn"] + + +@patch.dict(os.environ, {**_CLEAR, "ALIBABA_CODING_PLAN_API_KEY": "sk-intl-fake"}, clear=False) +def test_alibaba_cn_does_not_appear_when_only_intl_key_set(): + """#101122: the shared intl key alone must light only the intl row.""" + assert _alibaba_slugs() == ["alibaba-coding-plan"]