Files
OmniRoute/tests/unit/flat-rate-cost-5552.test.ts
Paco Cartones 8d6870f96e fix(analytics): classify opencode-go as a flat-rate subscription (#11199)
Validated on the combined batch board over tip c92bd40b: static gates clean (changelog, file-size 158 frozen, complexity 2626<=2774, cognitive 1183<=1223, dead-code 409<=416), typecheck:core clean, 70 focused tests green (PR suites 49/49 + auth/combo neighbors 21/21).

opencode-go joins FLAT_RATE_SUBSCRIPTION_PROVIDER_IDS — cost analytics stop pricing a flat 0 subscription at metered aggregator rates (3.35 reported vs 0 actual). Same pattern as #10774. Fixes #11149. Thank you @pacocartones!
2026-08-23 01:24:28 -03:00

124 lines
4.7 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { isFlatRateProvider } from "../../src/lib/usage/flatRateProviders.ts";
import { computeCostFromPricing } from "../../src/lib/usage/costCalculator.ts";
// $1/1M input, $2/1M output → 1M+1M tokens = $1 + $2 = $3 at the metered rate.
const PRICING = { input: 1, output: 2 };
const TOKENS = { input: 1_000_000, output: 1_000_000 };
test("isFlatRateProvider: cookie-web providers are flat-rate", () => {
for (const id of ["chatgpt-web", "grok-web", "gemini-web", "claude-web", "kimi-web"]) {
assert.equal(isFlatRateProvider(id), true, `${id} should be flat-rate`);
}
});
test("isFlatRateProvider: dedicated subscription / coding-plan providers are flat-rate", () => {
for (const id of [
"minimax",
"kimi-coding",
"kimi-coding-apikey",
"xiaomi-mimo",
"bailian-coding-plan",
"qwen-cloud-token-plan",
"glm",
"glm-cn",
"claude",
"cc",
"opencode-go",
]) {
assert.equal(isFlatRateProvider(id), true, `${id} should be flat-rate`);
}
});
test("isFlatRateProvider: case-insensitive + trimmed", () => {
assert.equal(isFlatRateProvider(" CHATGPT-WEB "), true);
assert.equal(isFlatRateProvider("MINIMAX"), true);
});
test("isFlatRateProvider: metered / cost-tracked providers are NOT flat-rate (no hidden cost)", () => {
// codex/cx = OmniRoute actively tracks Codex token cost (Fast-tier multipliers,
// GPT-5.x pricing) and Codex can be a metered account; byteplus = metered ModelArk;
// minimax-cn = metered China API; glm-thinking = metered tier; anthropic = the
// metered Anthropic API, distinct from the `claude`/`cc` Claude Code plan.
for (const id of [
"openai",
"anthropic",
"gemini",
"codex",
"cx",
"byteplus",
"minimax-cn",
"glm-thinking",
"qwen-cloud",
]) {
assert.equal(isFlatRateProvider(id), false, `${id} should NOT be flat-rate`);
}
});
test("isFlatRateProvider: empty / nullish is not flat-rate", () => {
assert.equal(isFlatRateProvider(""), false);
assert.equal(isFlatRateProvider(" "), false);
assert.equal(isFlatRateProvider(null), false);
assert.equal(isFlatRateProvider(undefined), false);
});
test("computeCostFromPricing: flat-rate provider with flatRateAsZero → $0", () => {
assert.equal(
computeCostFromPricing(PRICING, TOKENS, { provider: "chatgpt-web", flatRateAsZero: true }),
0
);
assert.equal(
computeCostFromPricing(PRICING, TOKENS, { provider: "minimax", flatRateAsZero: true }),
0
);
// Claude Code is billed by the Pro/Max subscription, never per token.
assert.equal(
computeCostFromPricing(PRICING, TOKENS, { provider: "claude", flatRateAsZero: true }),
0
);
});
test("computeCostFromPricing: opt-in only — flat-rate provider WITHOUT the flag still estimates", () => {
// Proves the guard never silently changes budget/routing/per-request paths.
assert.equal(computeCostFromPricing(PRICING, TOKENS, { provider: "chatgpt-web" }), 3);
});
test("#11149: opencode-go is a flat-rate subscription, not metered", () => {
// opencode-go (https://opencode.ai/go) is a $10/month flat subscription that
// resells GLM, Kimi, Grok, DeepSeek, MiniMax, Qwen and GPT-5.x. Because it is
// an aggregator, every call was priced at the UNDERLYING model's metered rate,
// so the overstatement is large rather than marginal (a reported ~$13.35 for a
// month actually billed at $10 flat). It is api-key auth, so it is not covered
// by the dynamic WEB_COOKIE_PROVIDERS branch and needs the explicit id.
assert.equal(isFlatRateProvider("opencode-go"), true);
assert.equal(
computeCostFromPricing(PRICING, TOKENS, { provider: "opencode-go", flatRateAsZero: true }),
0
);
// Still opt-in: without the flag the per-request estimate is unchanged.
assert.equal(computeCostFromPricing(PRICING, TOKENS, { provider: "opencode-go" }), 3);
});
test("#11149: sibling opencode ids keep their own billing semantics", () => {
// Only the Go subscription is flat-rate. The keyless `opencode` provider is a
// different id and must not be swept in by a prefix-style match.
assert.equal(isFlatRateProvider("opencode"), false);
});
test("computeCostFromPricing: metered provider with the flag still estimates", () => {
assert.equal(
computeCostFromPricing(PRICING, TOKENS, { provider: "openai", flatRateAsZero: true }),
3
);
// byteplus is metered despite being a subscription-ish gateway — must NOT be zeroed.
assert.equal(
computeCostFromPricing(PRICING, TOKENS, { provider: "byteplus", flatRateAsZero: true }),
3
);
// The metered Anthropic API keeps its real cost — only the Claude Code plan is flat-rate.
assert.equal(
computeCostFromPricing(PRICING, TOKENS, { provider: "anthropic", flatRateAsZero: true }),
3
);
});