mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-24 06:45:22 +00:00
The auth command has been renamed to providers to better reflect its purpose of managing AI provider credentials. This makes it easier for users to discover and use the credential management features when configuring different AI providers.
121 lines
3.3 KiB
TypeScript
121 lines
3.3 KiB
TypeScript
import { test, expect, describe } from "bun:test"
|
|
import { resolvePluginProviders } from "../../src/cli/cmd/providers"
|
|
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([])
|
|
})
|
|
})
|