feat: surface plugin auth providers in the login picker (#13921)
Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
This commit is contained in:
120
packages/opencode/test/cli/plugin-auth-picker.test.ts
Normal file
120
packages/opencode/test/cli/plugin-auth-picker.test.ts
Normal file
@@ -0,0 +1,120 @@
|
||||
import { test, expect, describe } from "bun:test"
|
||||
import { resolvePluginProviders } from "../../src/cli/cmd/auth"
|
||||
import type { Hooks } from "@opencode-ai/plugin"
|
||||
|
||||
function hookWithAuth(provider: string): Hooks {
|
||||
return {
|
||||
auth: {
|
||||
provider,
|
||||
methods: [],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function hookWithoutAuth(): Hooks {
|
||||
return {}
|
||||
}
|
||||
|
||||
describe("resolvePluginProviders", () => {
|
||||
test("returns plugin providers not in models.dev", () => {
|
||||
const result = resolvePluginProviders({
|
||||
hooks: [hookWithAuth("portkey")],
|
||||
existingProviders: {},
|
||||
disabled: new Set(),
|
||||
providerNames: {},
|
||||
})
|
||||
expect(result).toEqual([{ id: "portkey", name: "portkey" }])
|
||||
})
|
||||
|
||||
test("skips providers already in models.dev", () => {
|
||||
const result = resolvePluginProviders({
|
||||
hooks: [hookWithAuth("anthropic")],
|
||||
existingProviders: { anthropic: {} },
|
||||
disabled: new Set(),
|
||||
providerNames: {},
|
||||
})
|
||||
expect(result).toEqual([])
|
||||
})
|
||||
|
||||
test("deduplicates across plugins", () => {
|
||||
const result = resolvePluginProviders({
|
||||
hooks: [hookWithAuth("portkey"), hookWithAuth("portkey")],
|
||||
existingProviders: {},
|
||||
disabled: new Set(),
|
||||
providerNames: {},
|
||||
})
|
||||
expect(result).toEqual([{ id: "portkey", name: "portkey" }])
|
||||
})
|
||||
|
||||
test("respects disabled_providers", () => {
|
||||
const result = resolvePluginProviders({
|
||||
hooks: [hookWithAuth("portkey")],
|
||||
existingProviders: {},
|
||||
disabled: new Set(["portkey"]),
|
||||
providerNames: {},
|
||||
})
|
||||
expect(result).toEqual([])
|
||||
})
|
||||
|
||||
test("respects enabled_providers when provider is absent", () => {
|
||||
const result = resolvePluginProviders({
|
||||
hooks: [hookWithAuth("portkey")],
|
||||
existingProviders: {},
|
||||
disabled: new Set(),
|
||||
enabled: new Set(["anthropic"]),
|
||||
providerNames: {},
|
||||
})
|
||||
expect(result).toEqual([])
|
||||
})
|
||||
|
||||
test("includes provider when in enabled set", () => {
|
||||
const result = resolvePluginProviders({
|
||||
hooks: [hookWithAuth("portkey")],
|
||||
existingProviders: {},
|
||||
disabled: new Set(),
|
||||
enabled: new Set(["portkey"]),
|
||||
providerNames: {},
|
||||
})
|
||||
expect(result).toEqual([{ id: "portkey", name: "portkey" }])
|
||||
})
|
||||
|
||||
test("resolves name from providerNames", () => {
|
||||
const result = resolvePluginProviders({
|
||||
hooks: [hookWithAuth("portkey")],
|
||||
existingProviders: {},
|
||||
disabled: new Set(),
|
||||
providerNames: { portkey: "Portkey AI" },
|
||||
})
|
||||
expect(result).toEqual([{ id: "portkey", name: "Portkey AI" }])
|
||||
})
|
||||
|
||||
test("falls back to id when no name configured", () => {
|
||||
const result = resolvePluginProviders({
|
||||
hooks: [hookWithAuth("portkey")],
|
||||
existingProviders: {},
|
||||
disabled: new Set(),
|
||||
providerNames: {},
|
||||
})
|
||||
expect(result).toEqual([{ id: "portkey", name: "portkey" }])
|
||||
})
|
||||
|
||||
test("skips hooks without auth", () => {
|
||||
const result = resolvePluginProviders({
|
||||
hooks: [hookWithoutAuth(), hookWithAuth("portkey"), hookWithoutAuth()],
|
||||
existingProviders: {},
|
||||
disabled: new Set(),
|
||||
providerNames: {},
|
||||
})
|
||||
expect(result).toEqual([{ id: "portkey", name: "portkey" }])
|
||||
})
|
||||
|
||||
test("returns empty for no hooks", () => {
|
||||
const result = resolvePluginProviders({
|
||||
hooks: [],
|
||||
existingProviders: {},
|
||||
disabled: new Set(),
|
||||
providerNames: {},
|
||||
})
|
||||
expect(result).toEqual([])
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user