Files
oh-my-opencode/packages/model-core/src/model-capabilities-snapshot.test.ts
T
YeonGyu-Kim edaa95fec0 refactor(model-core): host snapshot fetcher, suggestion parser, and context-limit resolver
Move three pure helpers from src/shared/ into @oh-my-opencode/model-core so the package can stand alone without depending on plugin internals:

- buildModelCapabilitiesSnapshotFromModelsDev + fetchModelCapabilitiesSnapshot (models.dev normalization)
- parseModelSuggestion (cross-provider ProviderModelNotFoundError suggestion extraction)
- resolveActualContextLimit (Anthropic GA 1M context override)

Split provider-model-id-transform into two variants exposed by model-core:

- transformModelForProvider keeps the runtime dash to dot Anthropic rewrite used by the SDK
- transformModelForProviderDisplay preserves hyphenated Anthropic IDs so the installer writes registry-compatible model strings, fixing the ProviderModelNotFoundError fresh installs hit when the dotted form leaks into the config

src/shared/* and src/cli/provider-model-id-transform.ts collapse to re-export shims that point at the new core modules. Stale src/shared/{known-variants,model-capability-aliases,model-capability-guardrails,model-capability-heuristics}.ts re-export files plus the duplicated context-limit-resolver test are removed in favor of the canonical model-core copies.

Tests: bun test packages/model-core src/shared/model-capabilities-cache.test.ts src/cli/provider-model-id-transform.test.ts
2026-05-21 16:19:38 +09:00

118 lines
2.8 KiB
TypeScript

import { describe, expect, test } from "bun:test"
import {
buildModelCapabilitiesSnapshotFromModelsDev,
fetchModelCapabilitiesSnapshot,
} from "./model-capabilities-snapshot"
describe("model-capabilities-snapshot", () => {
test("builds a normalized snapshot from models.dev provider data", () => {
const raw = {
openai: {
models: {
"gpt-5.4": {
id: "gpt-5.4",
family: "gpt",
reasoning: true,
temperature: false,
tool_call: true,
modalities: {
input: ["text", "image"],
output: ["text"],
},
limit: {
context: 1_050_000,
output: 128_000,
},
},
},
},
}
const snapshot = buildModelCapabilitiesSnapshotFromModelsDev(raw)
expect(snapshot.sourceUrl).toBe("https://models.dev/api.json")
expect(snapshot.models["gpt-5.4"]).toEqual({
id: "gpt-5.4",
family: "gpt",
reasoning: true,
temperature: false,
toolCall: true,
modalities: {
input: ["text", "image"],
output: ["text"],
},
limit: {
context: 1_050_000,
output: 128_000,
},
})
})
test("ignores malformed provider entries and missing fields", () => {
const raw = {
invalidProvider: null,
anthropic: {
models: {
"claude-sonnet-4-6": {
reasoning: true,
},
"bad-model": "invalid",
},
},
openai: {
models: {
"gpt-5.4": {
id: "GPT-5.4",
modalities: {
input: ["text", 1],
},
},
},
},
}
const snapshot = buildModelCapabilitiesSnapshotFromModelsDev(raw)
expect(snapshot.models["claude-sonnet-4-6"]).toEqual({
id: "claude-sonnet-4-6",
reasoning: true,
})
expect(snapshot.models["gpt-5.4"]).toEqual({
id: "GPT-5.4",
modalities: {
input: ["text"],
},
})
expect(snapshot.models["bad-model"]).toBeUndefined()
})
test("fetches snapshot using injected fetch implementation", async () => {
const sourceUrl = "https://fixture.local/models.json"
const fetchImpl = async () =>
new Response(
JSON.stringify({
openai: {
models: {
"gpt-5.4": {
id: "gpt-5.4",
limit: {
output: 128_000,
},
},
},
},
}),
{
status: 200,
headers: { "content-type": "application/json" },
},
)
const snapshot = await fetchModelCapabilitiesSnapshot({ sourceUrl, fetchImpl })
expect(snapshot.sourceUrl).toBe(sourceUrl)
expect(snapshot.models["gpt-5.4"]?.limit?.output).toBe(128_000)
})
})