test(provider): migrate more config-backed cases (#27067)

This commit is contained in:
Kit Langton
2026-05-12 14:19:49 +00:00
committed by GitHub
parent 0fd0facc44
commit 04aafe2bfc
@@ -582,15 +582,20 @@ it.instance(
}, },
) )
test("model options are merged from existing model", async () => { it.instance(
await using tmp = await tmpdir({ "model options are merged from existing model",
init: async (dir) => { Effect.gen(function* () {
await Bun.write( const providers = yield* Provider.Service.use((provider) => provider.list())
path.join(dir, "opencode.json"), const model = providers[ProviderID.anthropic].models["claude-sonnet-4-20250514"]
JSON.stringify({ expect(model.options.customOption).toBe("custom-value")
$schema: "https://opencode.ai/config.json", }),
{
config: {
provider: { provider: {
anthropic: { anthropic: {
options: {
apiKey: "test-api-key",
},
models: { models: {
"claude-sonnet-4-20250514": { "claude-sonnet-4-20250514": {
options: { options: {
@@ -600,46 +605,29 @@ test("model options are merged from existing model", async () => {
}, },
}, },
}, },
}), },
},
) )
},
})
await WithInstance.provide({
directory: tmp.path,
fn: async () => {
set("ANTHROPIC_API_KEY", "test-api-key")
const providers = await list()
const model = providers[ProviderID.anthropic].models["claude-sonnet-4-20250514"]
expect(model.options.customOption).toBe("custom-value")
},
})
})
test("provider removed when all models filtered out", async () => { it.instance(
await using tmp = await tmpdir({ "provider removed when all models filtered out",
init: async (dir) => { Effect.gen(function* () {
await Bun.write( const providers = yield* Provider.Service.use((provider) => provider.list())
path.join(dir, "opencode.json"), expect(providers[ProviderID.anthropic]).toBeUndefined()
JSON.stringify({ }),
$schema: "https://opencode.ai/config.json", {
config: {
provider: { provider: {
anthropic: { anthropic: {
options: {
apiKey: "test-api-key",
},
whitelist: ["nonexistent-model"], whitelist: ["nonexistent-model"],
}, },
}, },
}), },
},
) )
},
})
await WithInstance.provide({
directory: tmp.path,
fn: async () => {
set("ANTHROPIC_API_KEY", "test-api-key")
const providers = await list()
expect(providers[ProviderID.anthropic]).toBeUndefined()
},
})
})
test("closest finds model by partial match", async () => { test("closest finds model by partial match", async () => {
await using tmp = await tmpdir({ await using tmp = await tmpdir({