Skip to content

Commit 46638fe

Browse files
byapparovclaude
andcommitted
fix(provider): skip plugin auth loaders for providers missing from the catalog (#187)
The plugin auth contract passes a non-optional Provider to loader(). With github-copilot dropped from the catalog, a leftover auth plugin for it would receive undefined and could abort provider init for everyone. Skip the loader when the provider has no catalog entry; mergeProvider would discard its options anyway. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 043ffd6 commit 46638fe

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎packages/cli/src/provider/provider.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,9 +1006,11 @@ export namespace Provider {
10061006
const providerID = plugin.auth.provider
10071007
if (disabled.has(providerID)) continue
10081008
if (!plugin.auth.loader) continue
1009+
const provider = database[providerID]
1010+
if (!provider) continue
10091011
if (!(await Auth.get(providerID))) continue
10101012

1011-
const options = await plugin.auth.loader(() => Auth.get(providerID) as any, database[providerID])
1013+
const options = await plugin.auth.loader(() => Auth.get(providerID) as any, provider)
10121014
const opts = options ?? {}
10131015
const patch: Partial<Info> = providers[providerID] ? { options: opts } : { source: "custom", options: opts }
10141016
mergeProvider(providerID, patch)

‎packages/cli/test/provider/provider.test.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ test("getModel throws ModelNotFoundError for invalid provider", async () => {
350350
})
351351
})
352352

353-
test("removed github-copilot provider is unavailable despite GITHUB_TOKEN and stored auth", async () => {
353+
test("removed github-copilot provider is unavailable despite GITHUB_TOKEN, stored auth and an auth plugin", async () => {
354354
await using tmp = await tmpdir({
355355
init: async (dir) => {
356356
await Bun.write(
@@ -359,6 +359,20 @@ test("removed github-copilot provider is unavailable despite GITHUB_TOKEN and st
359359
$schema: "https://aictrl.ai/config.json",
360360
}),
361361
)
362+
// A leftover Copilot auth plugin whose loader expects a catalog entry.
363+
await Bun.write(
364+
path.join(dir, ".aictrl", "plugin", "copilot-auth.ts"),
365+
[
366+
"export default async () => ({",
367+
" auth: {",
368+
' provider: "github-copilot",',
369+
' methods: [{ type: "api", label: "Copilot" }],',
370+
" loader: async (_auth, provider) => ({ models: Object.keys(provider.models) }),",
371+
" },",
372+
"})",
373+
"",
374+
].join("\n"),
375+
)
362376
},
363377
})
364378
await Auth.set("github-copilot", { type: "oauth", refresh: "stale", access: "stale", expires: 0 })

0 commit comments

Comments
 (0)