mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-03 15:43:45 +00:00
refactor: apply minimal tfcode branding
- Rename packages/opencode → packages/tfcode (directory only) - Rename bin/opencode → bin/tfcode (CLI binary) - Rename .opencode → .tfcode (config directory) - Update package.json name and bin field - Update config directory path references (.tfcode) - Keep internal code references as 'opencode' for easy upstream sync - Keep @opencode-ai/* workspace package names This minimal branding approach allows clean merges from upstream opencode repository while providing tfcode branding for users.
This commit is contained in:
120
packages/tfcode/test/cli/plugin-auth-picker.test.ts
Normal file
120
packages/tfcode/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/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([])
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user