Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

fix(alibaba): name qwen-coding and qwen-payg in every hand-written table

Jack Rudenko8691eedcdcf8
diff --git a/packages/cli/src/providers/qwen-coding-plan.test.ts b/packages/cli/src/providers/qwen-coding-plan.test.ts
new file mode 100644
index 00000000..8bb06ccb
--- /dev/null
+++ b/packages/cli/src/providers/qwen-coding-plan.test.ts
@@ -0,0 +1,91 @@
+/**
+ * Alibaba sells THREE products through three isolated key+host silos. This file
+ * pins the third one — the Coding Plan, `qcode@` / `qwen-coding` — against every
+ * hand-written table that repeats a fact its definition already holds.
+ *
+ * ── WHY A DRIFT TEST ──────────────────────────────────────────────────────────
+ *
+ * Each table below is a second spelling of something `ProviderDefinition` says.
+ * A provider missing from one of them is not an error and not visibly wrong: the
+ * routing hint prints only the OpenRouter line, and the config TUI's routing
+ * panel prints the bare uid as its own explanation. Both were missing for
+ * `qwen-coding` while seven other files tested it, so each table is checked
+ * here rather than by a look.
+ *
+ * Everything in this file is hermetic and offline.
+ */
+
+import { describe, expect, test } from "bun:test";
+import { buildProviderChoices } from "../model-selector.js";
+import { PROVIDER_REASONS } from "../tui/components/RoutingContent.js";
+import { API_KEY_MAP } from "./api-key-map.js";
+import { describeMissingCredential, getProviderByName } from "./provider-definitions.js";
+import { getProviderApiKeyEnv } from "./routing-hints.js";
+
+const CODING = "qwen-coding";
+const TOKEN = "qwen-token-plan";
+const PAYG = "qwen-payg";
+
+const CODING_KEY = "QWEN_CODING_PLAN_API_KEY";
+const TOKEN_KEY = "QWEN_TOKEN_PLAN_API_KEY";
+const PAYG_KEY = "DASHSCOPE_API_KEY";
+
+describe("qwen-coding — every hand-written table that shadows the definition", () => {
+ test("API_KEY_MAP (the --probe credential rows) agrees with the definition", () => {
+ const def = getProviderByName(CODING)!;
+ expect(API_KEY_MAP[CODING]).toEqual({ envVar: def.apiKeyEnvVar, aliases: def.apiKeyAliases });
+ });
+
+ test("the routing hint names the key, so qcode@ cannot vanish unexplained", () => {
+ expect(getProviderApiKeyEnv(CODING)).toBe(CODING_KEY);
+ });
+
+ test("the picker offers it, named as a product, next to its siblings", () => {
+ const choices = buildProviderChoices();
+ const row = choices.find((c) => c.value === CODING);
+ expect(row).toBeDefined();
+ expect(row!.name).toBe("Alibaba Coding Plan");
+ // The metering UNIT is the distinction a user picking a key needs: Credits,
+ // requests, tokens.
+ expect(row!.description).toContain("requests");
+
+ const order = choices.map((c) => c.value);
+ expect(order.indexOf(TOKEN)).toBeLessThan(order.indexOf(CODING));
+ expect(order.indexOf(CODING)).toBeLessThan(order.indexOf(PAYG));
+ });
+
+ test("the config TUI's routing panel names all three products", () => {
+ // Absent, a row renders its bare uid as its own explanation — not visibly
+ // broken, which is why it needs a test rather than a look.
+ expect(PROVIDER_REASONS[CODING]).toBe("Alibaba Coding Plan");
+ expect(PROVIDER_REASONS[TOKEN]).toBe("Alibaba Token Plan");
+ expect(PROVIDER_REASONS[PAYG]).toBe("Alibaba PAYG");
+ });
+
+ test("a 401 names the other two silos' keys as not-accepted-here", () => {
+ // `siblingKeyEnvVars` on all three, because at the routing layer a wrong-silo
+ // key and a bad key are the same 401. The clause is explanatory only — no
+ // resolution, no signing and no billing reads it.
+ const msg = describeMissingCredential(CODING);
+ expect(msg).toContain(`Set ${CODING_KEY}`);
+ expect(msg).toContain(`${TOKEN_KEY} (${TOKEN})`);
+ expect(msg).toContain(`${PAYG_KEY} (${PAYG})`);
+ expect(msg).toContain("is not accepted here");
+
+ expect(describeMissingCredential(TOKEN)).toContain(`${CODING_KEY} (${CODING})`);
+ expect(describeMissingCredential(PAYG)).toContain(`${TOKEN_KEY} (${TOKEN})`);
+ expect(describeMissingCredential(PAYG)).toContain(`${CODING_KEY} (${CODING})`);
+ });
+
+ test("nothing in the remedy infers a product from the key's bytes", () => {
+ // Alibaba documents `sk-sp-` as the CODING PLAN's format, and the one
+ // measured `sk-sp-` key authenticates the TOKEN PLAN. One counter-example is
+ // enough: a prefix cannot identify a product.
+ for (const name of [CODING, TOKEN, PAYG]) {
+ const msg = describeMissingCredential(name).toLowerCase();
+ expect(msg).not.toContain("sk-sp");
+ expect(msg).not.toContain("prefix");
+ expect(msg).not.toContain("starts with");
+ }
+ });
+});
diff --git a/packages/cli/src/providers/routing-hints.ts b/packages/cli/src/providers/routing-hints.ts
index d0bba77d..7bb2d8f5 100644
--- a/packages/cli/src/providers/routing-hints.ts
+++ b/packages/cli/src/providers/routing-hints.ts
@@ -44,7 +44,11 @@ const PROVIDER_HINT_MAP: Record<string, ProviderHintInfo> = {
mistralai: { apiKeyEnvVar: "MISTRAL_API_KEY" },
sakana: { apiKeyEnvVar: "SAKANA_API_KEY" },
"sakana-subscription": { apiKeyEnvVar: "SAKANA_SUBSCRIPTION_API_KEY" },
+ // One row per Alibaba silo. Each product has exactly one variable, and the
+ // name says which product it opens — a hint that names a vendor rather than a
+ // product is how a subscription key ends up filed against a metered silo.
"qwen-token-plan": { apiKeyEnvVar: "QWEN_TOKEN_PLAN_API_KEY" },
+ "qwen-coding": { apiKeyEnvVar: "QWEN_CODING_PLAN_API_KEY" },
"qwen-payg": { apiKeyEnvVar: "DASHSCOPE_API_KEY" },
ollamacloud: { apiKeyEnvVar: "OLLAMA_API_KEY" },
"native-anthropic": { apiKeyEnvVar: "ANTHROPIC_API_KEY" },
diff --git a/packages/cli/src/providers/transport/anthropic-compat.ts b/packages/cli/src/providers/transport/anthropic-compat.ts
index 175da325..6c5fed1c 100644
--- a/packages/cli/src/providers/transport/anthropic-compat.ts
+++ b/packages/cli/src/providers/transport/anthropic-compat.ts
@@ -9,6 +9,7 @@
import { credentials } from "../../auth/credentials/authority.js";
import type { RemoteProvider } from "../../handlers/shared/remote-provider-types.js";
import { log } from "../../logger.js";
+import { getProviderByName } from "../provider-definitions.js";
import { isTerminal429 } from "./openai.js";
import type { DiscoveryOutcome } from "./probe-discovery.js";
import { discoverProviderProbeModel } from "./provider-model-discovery.js";
@@ -175,18 +176,37 @@ export class AnthropicProviderTransport implements ProviderTransport {
return lastResponse!;
}
- private static formatDisplayName(name: string): string {
- const map: Record<string, string> = {
- minimax: "MiniMax",
- "minimax-coding": "MiniMax Coding",
- kimi: "Kimi",
- "kimi-coding": "Kimi Coding",
- "qwen-token-plan": "Alibaba Token Plan",
- "qwen-payg": "Qwen API",
- moonshot: "Kimi",
- "z-ai": "Z.AI",
- };
- return map[name.toLowerCase()] || name.charAt(0).toUpperCase() + name.slice(1);
+ /**
+ * DERIVED from the provider catalog — deliberately not a second table.
+ *
+ * This used to be a private map of eight names that SHADOWED
+ * `ProviderDefinition.displayName`, so renaming a provider in one place
+ * silently left this transport's log lines on the old label. That is the
+ * two-table coupling `provider-definitions.ts` exists to prevent: a provider
+ * whose label is stored twice keeps the stale one wherever nobody looked.
+ * `qwen-coding` was missing from the map and logged "Qwen-coding";
+ * `qwen-payg` logged "Qwen API" while its definition says "Alibaba PAYG".
+ *
+ * The other former entries are byte-identical to their definition's
+ * `displayName` (minimax, minimax-coding, kimi, kimi-coding, z-ai,
+ * qwen-token-plan). `moonshot → "Kimi"` is dropped on purpose: `moonshot` is
+ * one of `kimi`'s SHORTCUTS, never a provider `name`, so the entry was
+ * unreachable from `provider.name` — and `moonshot-cn` is a genuinely
+ * different service (CLAUDE.md), which the old entry would have collapsed
+ * into "Kimi" had it ever been reached.
+ *
+ * The title-case fallback is unchanged, so a runtime custom endpoint with no
+ * definition renders exactly as it did before.
+ *
+ * NOTE: `transport/openai.ts` keeps its own map on purpose — it carries no
+ * Alibaba entry, and deriving it would rename `Zen`/`Zen Go` in every log
+ * line for two providers this change has no business touching.
+ */
+ static formatDisplayName(name: string): string {
+ return (
+ getProviderByName(name.toLowerCase())?.displayName ||
+ name.charAt(0).toUpperCase() + name.slice(1)
+ );
}
}
diff --git a/packages/cli/src/tui/components/RoutingContent.tsx b/packages/cli/src/tui/components/RoutingContent.tsx
index 780ba4ce..78680c15 100644
--- a/packages/cli/src/tui/components/RoutingContent.tsx
+++ b/packages/cli/src/tui/components/RoutingContent.tsx
@@ -14,8 +14,18 @@ function chainStr(chain: string[]): string {
return chain.join(" → ");
}
-// Reasons shown beneath each probe entry
-const PROVIDER_REASONS: Record<string, string> = {
+/**
+ * Reasons shown beneath each probe entry.
+ *
+ * Exported for the drift test only. A provider missing from here renders its
+ * bare uid (`entry.provider`) as its own explanation — which is not an error and
+ * not visibly wrong, so the three Alibaba rows would silently read
+ * "qwen-token-plan / qwen-coding / qwen-payg" instead of naming the three
+ * products the user is choosing between. Nothing is DERIVED from this map; it
+ * only labels. The Alibaba labels equal each definition's `displayName`, and
+ * `qwen-coding-plan.test.ts` holds them to it.
+ */
+export const PROVIDER_REASONS: Record<string, string> = {
litellm: "LiteLLM proxy",
"opencode-zen": "Free tier (OpenCode Zen)",
"opencode-zen-go": "Zen Go plan",
@@ -26,6 +36,8 @@ const PROVIDER_REASONS: Record<string, string> = {
glm: "Native GLM API",
"glm-coding": "GLM Coding Plan",
"qwen-token-plan": "Alibaba Token Plan",
+ "qwen-coding": "Alibaba Coding Plan",
+ "qwen-payg": "Alibaba PAYG",
google: "Direct Gemini API",
openai: "Direct OpenAI API",
"openai-codex": "OpenAI Codex (Responses API)",