Files
cc-switch/tests/config/commandCodeUsage.test.ts
Jason c859026d48 feat(usage): enable coding-plan usage by default for every app
Adding a provider whose base URL matches a coding plan (Kimi, Zhipu,
MiniMax, Volcengine, OpenCode Go, Command Code) now turns on the
token_plan usage query in every app, not only Claude Code. Before, other
apps got it only for OpenCode Go and Codex + Command Code, so a Kimi plan
added to Codex, OpenCode, Pi, Hermes etc. had usage off until enabled by
hand.

The quota endpoints only depend on the API key (Zhipu also on the host),
not on the client protocol or base URL path, and the backend already
resolves usage credentials for all apps. The frontend base URL lookup now
also covers Gemini CLI, Grok Build, Hermes, OpenClaw and MiniMax Code.

ZenMux stays Claude-only: its query GETs the configured base URL itself,
which is untested for other apps' inference URLs. Existing providers are
not changed.
2026-10-13 22:13:16 +08:00

67 lines
2.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
detectCodingPlanProvider,
injectCodingPlanUsageScript,
} from "@/config/codingPlanProviders";
const CODEX_BASE_URL = "https://api.commandcode.ai/provider/v1";
const CLAUDE_BASE_URL = "https://api.commandcode.ai/provider";
describe("Command Code usage detection", () => {
it("recognizes both provider base variants but not unrelated URLs", () => {
expect(detectCodingPlanProvider(CLAUDE_BASE_URL)).toBe("command_code");
expect(detectCodingPlanProvider(CODEX_BASE_URL)).toBe("command_code");
expect(
detectCodingPlanProvider("https://commandcode.ai/provider"),
).toBeNull();
});
it("injects the quota script for Claude Code and Codex", () => {
const claude = injectCodingPlanUsageScript("claude", {
settingsConfig: {
env: { ANTHROPIC_BASE_URL: CLAUDE_BASE_URL },
},
}) as { meta?: { usage_script?: { codingPlanProvider?: string } } };
const codex = injectCodingPlanUsageScript("codex", {
settingsConfig: {
config: `model_provider = "command_code"
[model_providers.command_code]
base_url = "${CODEX_BASE_URL}"`,
},
}) as { meta?: { usage_script?: { codingPlanProvider?: string } } };
expect(claude.meta?.usage_script?.codingPlanProvider).toBe("command_code");
expect(codex.meta?.usage_script?.codingPlanProvider).toBe("command_code");
});
it("injects Command Code into other apps too", () => {
const provider = injectCodingPlanUsageScript("opencode", {
settingsConfig: {
options: { baseURL: CODEX_BASE_URL },
},
}) as { meta?: { usage_script?: { codingPlanProvider?: string } } };
expect(provider.meta?.usage_script?.codingPlanProvider).toBe(
"command_code",
);
});
it("does not overwrite an existing usage script", () => {
const provider = injectCodingPlanUsageScript("codex", {
settingsConfig: {
config: `model_provider = "command_code"
[model_providers.command_code]
base_url = "${CODEX_BASE_URL}"`,
},
meta: {
usage_script: { enabled: false, templateType: "custom" },
},
}) as { meta?: { usage_script?: unknown } };
expect(provider.meta?.usage_script).toEqual({
enabled: false,
templateType: "custom",
});
});
});