This commit is contained in:
Daniel Lindsley 2025-12-23 15:42:44 +08:00 committed by GitHub
commit 685bc1c838
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 0 deletions

View file

@ -660,6 +660,14 @@ export namespace Provider {
const providerID = plugin.auth.provider
if (disabled.has(providerID)) continue
// Skip OAuth/plugin auth if config explicitly sets an apiKey for this provider
const configProvider = config.provider?.[providerID]
const hasExplicitApiKey = configProvider?.options?.apiKey !== undefined
if (hasExplicitApiKey) {
log.debug("skipping plugin auth loader - config has explicit apiKey", { providerID })
continue
}
// For github-copilot plugin, check if auth exists for either github-copilot or github-copilot-enterprise
let hasAuth = false
const auth = await Auth.get(providerID)

View file

@ -1807,3 +1807,35 @@ test("custom model inherits api.url from models.dev provider", async () => {
},
})
})
test("config apiKey takes precedence over OAuth plugin auth loaders", async () => {
await using tmp = await tmpdir({
init: async (dir) => {
await Bun.write(
path.join(dir, "opencode.json"),
JSON.stringify({
$schema: "https://opencode.ai/config.json",
provider: {
anthropic: {
options: {
apiKey: "explicit-config-api-key",
},
},
},
}),
)
},
})
await Instance.provide({
directory: tmp.path,
fn: async () => {
const providers = await Provider.list()
expect(providers["anthropic"]).toBeDefined()
// When config has explicit apiKey, it should be used
// and plugin auth loaders should be skipped (no OAuth processing)
expect(providers["anthropic"].options.apiKey).toBe("explicit-config-api-key")
// Source should be "config" since config is merged last
expect(providers["anthropic"].source).toBe("config")
},
})
})