(t *testing.T)
| 41 | } |
| 42 | |
| 43 | func TestBuildProviders(t *testing.T) { |
| 44 | t.Parallel() |
| 45 | |
| 46 | t.Run("EmptyConfig", func(t *testing.T) { |
| 47 | t.Parallel() |
| 48 | providers, err := buildFromEnv(t, codersdk.AIBridgeConfig{}) |
| 49 | require.NoError(t, err) |
| 50 | assert.Empty(t, providers) |
| 51 | }) |
| 52 | |
| 53 | t.Run("LegacyOnly", func(t *testing.T) { |
| 54 | t.Parallel() |
| 55 | cfg := codersdk.AIBridgeConfig{} |
| 56 | cfg.LegacyOpenAI.Key = serpent.String("sk-openai") |
| 57 | cfg.LegacyAnthropic.Key = serpent.String("sk-anthropic") |
| 58 | |
| 59 | providers, err := buildFromEnv(t, cfg) |
| 60 | require.NoError(t, err) |
| 61 | |
| 62 | names := providerNames(providers) |
| 63 | assert.Contains(t, names, aibridge.ProviderOpenAI) |
| 64 | assert.Contains(t, names, aibridge.ProviderAnthropic) |
| 65 | assert.Len(t, names, 2) |
| 66 | }) |
| 67 | |
| 68 | t.Run("IndexedOnly", func(t *testing.T) { |
| 69 | t.Parallel() |
| 70 | cfg := codersdk.AIBridgeConfig{ |
| 71 | Providers: []codersdk.AIProviderConfig{ |
| 72 | { |
| 73 | Type: aibridge.ProviderAnthropic, |
| 74 | Name: "anthropic-zdr", |
| 75 | Keys: []string{"sk-zdr"}, |
| 76 | }, |
| 77 | { |
| 78 | Type: aibridge.ProviderOpenAI, |
| 79 | Name: "openai-azure", |
| 80 | Keys: []string{"sk-azure"}, |
| 81 | BaseURL: "https://azure.openai.com", |
| 82 | }, |
| 83 | }, |
| 84 | } |
| 85 | |
| 86 | providers, err := buildFromEnv(t, cfg) |
| 87 | require.NoError(t, err) |
| 88 | require.Len(t, providers, 2) |
| 89 | |
| 90 | byName := make(map[string]aibridge.Provider, len(providers)) |
| 91 | for _, p := range providers { |
| 92 | byName[p.Name()] = p |
| 93 | } |
| 94 | require.Contains(t, byName, "anthropic-zdr") |
| 95 | require.Contains(t, byName, "openai-azure") |
| 96 | }) |
| 97 | |
| 98 | t.Run("LegacyOpenAIConflictsWithIndexed", func(t *testing.T) { |
| 99 | t.Parallel() |
| 100 | cfg := codersdk.AIBridgeConfig{ |
nothing calls this directly
no test coverage detected