Files
OmniRoute/tests/unit/modelsdevsync-transform-split.test.ts
Diego Rodrigues de Sa e Souza 852f18502d fix(providers): remove OpenCode Free while preserving Zen and Go (#16310)
Merged via /merge-batch (2026-10-17 wave, owner-approved rework incl. count-only edits to protected surfaces).

Reconciled on release/v3.8.52 @ 5413a24d (after #16531, #16960, #16965, #16924):
- Migration renumbered 208 -> 207 (`207_remove_opencode_free_provider.sql`; tip ships 206_codex_wakeup_tasks, no gap); test, REMOVED_PROVIDERS (+66 mirrors) and changelog fragment follow.
- #16531: the keyless `opencode` registry stays deleted; its tool-name-length test now covers the keyed Zen/Go entries only (10/10).
- Counts re-measured on the merged tree: 374 providers (375 - OpenCode Free), 204 migrations, 34 recurring pools, 52 free-forever. AGENTS.md, llm.txt (+66 mirrors), skills omni-auth/omni-providers differ from the tip only in digits (verified).
- FREE_TIERS mirrors: tip's #16924 refresh kept, OpenCode Free rows/section removed and pool count 35->34 applied mechanically (66/66); QUICK-START, TROUBLESHOOTING, FREE-TIERS-GUIDE, PROVIDERS-GUIDE, REMOVED_PROVIDERS mirrors retranslated with targeted `i18n:run --files` (330/330, table row counts equal to the source). i18n drift gate reports exactly the tip's inherited 21 drifted sources, 0 drifted targets.
- CodeQL: chat-noauth-model-cooldown test compares the exact upstream hostname instead of a URL substring.

Validation: focused node tests 1737/1737 (PR tests, migrations, blocklist, opencode*, tool-name-length, noauth cooldown) + 1052/1053 across every other test referencing opencode (1 env-only: opencode-ai postinstall binary absent locally); vitest 61/61 + 18/18; typecheck:core, api-typecheck, open-sse typecheck OK; complexity/cognitive/file-size/dead-code within baseline; boundary 774/774; changelog-integrity, docs-sync, docs-counts (strict) OK; provider-consistency OK (374); agent-skills Generated 0; eslint + prettier on changed files clean. CI runs for this head were queued (account runner backlog) and never started; remaining tip reds are the inherited base-red #15306.
2026-10-17 13:05:52 -03:00

110 lines
3.9 KiB
TypeScript

/**
* Split-guard — modelsDevSync ↔ modelsDevSync/transform
*
* Guards the extraction of the pure transform layer (provider-id mapping +
* raw→OmniRoute pricing/capability transforms) into the leaf
* src/lib/modelsDevSync/transform.ts. Characterizes the provider map and the
* two transform functions, and proves the host still re-exports them so its
* public API is unchanged. DB-free by design — the transform layer is pure.
*/
import { describe, it } from "node:test";
import assert from "node:assert/strict";
import {
mapProviderId,
transformModelsDevToPricing,
transformModelsDevToCapabilities,
MODELS_DEV_PROVIDER_MAP,
} from "../../src/lib/modelsDevSync/transform.ts";
describe("modelsDevSync/transform split-guard", () => {
it("maps known models.dev provider ids to OmniRoute aliases", () => {
assert.deepEqual(mapProviderId("openai"), ["openai", "cx"]);
assert.deepEqual(mapProviderId("anthropic"), ["anthropic", "cc"]);
assert.deepEqual(mapProviderId("zai"), ["zai", "glm"]);
assert.deepEqual(mapProviderId("bedrock"), ["kiro", "kr"]);
assert.deepEqual(mapProviderId("opencode"), ["opencode-zen"]);
});
it("falls back to the raw id for unmapped providers", () => {
assert.deepEqual(mapProviderId("some-unknown-provider"), ["some-unknown-provider"]);
});
it("exports a non-trivial provider map table", () => {
assert.ok(MODELS_DEV_PROVIDER_MAP.openai);
assert.ok(Object.keys(MODELS_DEV_PROVIDER_MAP).length > 30);
});
it("transforms cost → pricing and writes to every mapped provider", () => {
const raw = {
openai: {
id: "openai",
models: {
"gpt-x": {
id: "gpt-x",
name: "GPT-X",
cost: { input: 1, output: 2, cache_read: 0.5, cache_write: 3, reasoning: 4 },
},
},
},
};
const pricing = transformModelsDevToPricing(raw as never);
assert.deepEqual(pricing.openai["gpt-x"], {
input: 1,
output: 2,
cached: 0.5,
cache_creation: 3,
reasoning: 4,
});
// openai maps to ["openai", "cx"] — both must receive the entry.
assert.deepEqual(pricing.cx["gpt-x"], pricing.openai["gpt-x"]);
});
it("skips models with no cost or missing input pricing", () => {
const raw = {
openai: {
id: "openai",
models: {
"no-cost": { id: "no-cost", name: "x" },
"no-input": { id: "no-input", name: "y", cost: { output: 5 } },
},
},
};
const pricing = transformModelsDevToPricing(raw as never);
assert.equal(pricing.openai, undefined);
});
it("transforms capabilities incl. interleaved=true → reasoning_content", () => {
const raw = {
anthropic: {
id: "anthropic",
models: {
"claude-x": {
id: "claude-x",
name: "Claude X",
tool_call: true,
reasoning: true,
interleaved: true,
modalities: { input: ["text", "image"], output: ["text"] },
},
},
},
};
const caps = transformModelsDevToCapabilities(raw as never);
assert.equal(caps.anthropic["claude-x"].tool_call, true);
assert.equal(caps.anthropic["claude-x"].interleaved_field, "reasoning_content");
assert.equal(caps.anthropic["claude-x"].modalities_input, JSON.stringify(["text", "image"]));
// anthropic maps to ["anthropic", "cc"].
assert.deepEqual(caps.cc["claude-x"], caps.anthropic["claude-x"]);
});
it("host re-exports the pure transform functions (public API preserved)", async () => {
const host = await import("../../src/lib/modelsDevSync.ts");
assert.equal(typeof host.mapProviderId, "function");
assert.equal(typeof host.transformModelsDevToPricing, "function");
assert.equal(typeof host.transformModelsDevToCapabilities, "function");
assert.deepEqual(host.mapProviderId("anthropic"), mapProviderId("anthropic"));
});
});