Files
OmniRoute/tests/unit/flat-rate-cost-5552.test.ts
Diego Rodrigues de Sa e Souza 7d57d9f4a1 fix(providers): retire common ChatGPT Web provider (#11754)
Rebased onto the current release/v3.8.51 tip as part of a combined provider-retirement/provenance merge batch (Designer Web, Felo Web, Runtime, GPL-derived removal, Qwen Web already landed). Large conflict set (this is the biggest PR in the batch — the common ChatGPT Web provider touches chat, images, count-tokens, session leases, and combos). Conflicts resolved:

- `open-sse/config/providers/registry/chatgpt-web/*`, `open-sse/executors/chatgpt-web*`, `open-sse/handlers/imageGeneration/providers/chatgptWeb.ts`, and their tests: kept deleted, matching the PR's stated scope.
- `open-sse/config/providers/registry/minimax/web/index.ts`, `open-sse/handlers/imageGeneration/providers/geminiWeb.ts`, `open-sse/executors/gemini-web.ts`'s stale image-mode branch: base-drift collisions against already-merged sibling retirements (#11691, #11708) — kept deleted / dropped the dead code, since this PR's own branch forked before those merged.
- `src/shared/constants/reservedProviderPrefixes.ts`, `open-sse/executors/index.ts`, `executorProxy.ts`, `virtualFactory.ts`, `autoStrategy.ts`, `src/lib/db/providers.ts`, `src/sse/handlers/chat.ts`: combined the Designer + Runtime (Felo/Qwen) + common-ChatGPT-Web retirement guard calls at each shared chokepoint — compute-once-then-OR pattern, consistent with prior combinations in this batch.
- `src/sse/services/model.ts` / `src/sse/handlers/chatHelpers.ts`: adopted this PR's new `getModelInfoOrRetirementResponse()` central wrapper (a real improvement over ad-hoc try/catch), and extended it to also catch the Designer + Runtime retirement errors it didn't originally cover, so the consolidation doesn't regress the other two mechanisms.
- `src/app/api/v1/images/edits/route.ts`: this PR moved the retirement check earlier (before `enforceApiKeyPolicy`) but left the old later call+catch block in place from base drift — removed the now-redundant duplicate `resolveImageRouteModel()` call and merged the Designer catch into the earlier one.
- `open-sse/config/imageRegistry.ts`, `tests/snapshots/executors/executor-map.json` (`keyCount` recomputed to 133), `tests/snapshots/provider/translate-path.json`: same "both sides inserted a different retired provider at the same slot" pattern — resolved by dropping both.
- `tests/unit/chatcore-executor-proxy.test.ts`, `provider-node-reserved-prefix.test.ts`, `combo-auto-candidate-expansion.test.ts`, `messages-count-tokens-route.test.ts`, `virtual-auto-combo.test.ts`: split into independent per-mechanism test blocks (established pattern); `virtual-auto-combo.test.ts`'s old "includes cookie web-session providers" positive-inclusion test (which used chatgpt-web as its example) was retired along with the provider and replaced by this PR's negative-exclusion test for the same slot.
- `docs/architecture/ARCHITECTURE.md`, `CODEBASE_DOCUMENTATION.md` (+ 4 i18n mirrors), `README.md`, `FREE-TIERS-GUIDE.md`, `docs/diagrams/free-tier-budget.svg`, `docs/screenshots/free-tier-budget-card.svg`, `docs/reference/PROVIDER_REFERENCE.md`: recomputed every stale count from the real merged state — 104 executors (`countFiles` gate logic), 351 providers (regenerated via `gen:provider-reference`), 152/351 `hasFree` entries, 445/438/7 free-tier catalog rows, 13 ToS-avoid providers, budget-card regenerated via its real generator script. One doc conflict (`oauth/` module list) needed picking HEAD's side specifically — theirs still listed the already-removed `raycast` module instead of the real `openference`.
- `config/quality/test-masking-allowlist.json`: additive merge of the PR's 17 `_deletedWithReplacement` entries alongside the batch's existing ones (one real duplicate-key mistake in my first pass, caught and fixed via a `object_pairs_hook` duplicate-key check before finalizing).

Also fixed two real, unrelated-to-my-merge issues surfaced by the focused suite:
- `tests/unit/resolve-web-provider-host.test.ts`: the PR's own test had a typo — it asserted `perplexity-web`'s resolved host as `"perplexity.ai"`, but the provider's registered `website` is `"https://www.perplexity.ai"` and the resolver returns the URL's `host` verbatim (no www-stripping), so the correct value is `"www.perplexity.ai"` (consistent with the same test's own `url` assertion).
- `tests/unit/hard-session-lease-bypass-inventory.test.ts`: this golden call-site inventory was already stale on the pristine post-#11713 tip (confirmed via a throwaway probe worktree) — `src/lib/db/providers.ts`'s 3 connection-fallback sites and a third `src/app/api/providers/route.ts` site were never added to the golden list by the earlier-merged #11698/#11720 PRs. Updated it to the real current inventory (dated inline comments explain each delta and which PR introduced it), plus this PR's own legitimate deltas (image-edits duplicate-call removal, `ChatGptWebExecutor.execute()` site removed).

Focused suite green (433/433 across executor-proxy, reserved-prefix, hard-session-lease-bypass-inventory, resolve-web-provider-host, retirement/runtime-block/source-retirement/management-retirement/image-handler-retirement, migration-168, combo-auto-candidate-expansion, virtual-auto-combo, executor-map-golden and siblings), plus `typecheck:core`, `check-file-size`, and `check-changelog-integrity` clean. Thanks for the thorough provenance-hold retirement work — appreciated.
2026-08-28 06:52:46 -03:00

129 lines
4.9 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 ["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(" GROK-WEB "), true);
assert.equal(isFlatRateProvider("MINIMAX"), true);
});
test("isFlatRateProvider: retired common ChatGPT Web ids are no longer active billing lanes", () => {
assert.equal(isFlatRateProvider("chatgpt-web"), false);
assert.equal(isFlatRateProvider("cgpt-web"), false);
});
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: "grok-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: "grok-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
);
});