test(provider): migrate more config-backed cases (#27067)
This commit is contained in:
@@ -582,64 +582,52 @@ 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",
|
}),
|
||||||
provider: {
|
{
|
||||||
anthropic: {
|
config: {
|
||||||
models: {
|
provider: {
|
||||||
"claude-sonnet-4-20250514": {
|
anthropic: {
|
||||||
options: {
|
options: {
|
||||||
customOption: "custom-value",
|
apiKey: "test-api-key",
|
||||||
},
|
},
|
||||||
},
|
models: {
|
||||||
|
"claude-sonnet-4-20250514": {
|
||||||
|
options: {
|
||||||
|
customOption: "custom-value",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
)
|
},
|
||||||
},
|
},
|
||||||
})
|
},
|
||||||
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",
|
{
|
||||||
provider: {
|
config: {
|
||||||
anthropic: {
|
provider: {
|
||||||
whitelist: ["nonexistent-model"],
|
anthropic: {
|
||||||
},
|
options: {
|
||||||
|
apiKey: "test-api-key",
|
||||||
},
|
},
|
||||||
}),
|
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({
|
||||||
|
|||||||
Reference in New Issue
Block a user