MCPcopy Index your code
hub / github.com/coder/coder / TestListChatProviders

Function TestListChatProviders

coderd/exp_chats_test.go:2261–2329  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2259}
2260
2261func TestListChatProviders(t *testing.T) {
2262 t.Parallel()
2263 t.Skip("legacy chat provider API removed in favor of AI provider API")
2264
2265 t.Run("Success", func(t *testing.T) {
2266 t.Parallel()
2267
2268 ctx := testutil.Context(t, testutil.WaitLong)
2269 client := newChatClient(t)
2270 _ = coderdtest.CreateFirstUser(t, client.Client)
2271 modelConfig := createChatModelConfig(t, client)
2272
2273 providers, err := client.ListChatProviders(ctx)
2274 require.NoError(t, err)
2275
2276 var openAIProvider *codersdk.ChatProviderConfig
2277 for i := range providers {
2278 if providers[i].Provider == modelConfig.Provider {
2279 openAIProvider = &providers[i]
2280 break
2281 }
2282 }
2283 require.NotNil(t, openAIProvider)
2284 require.Equal(t, codersdk.ChatProviderConfigSourceDatabase, openAIProvider.Source)
2285 require.True(t, openAIProvider.Enabled)
2286 require.True(t, openAIProvider.HasAPIKey)
2287 })
2288
2289 t.Run("IgnoresDeploymentKeyWhenCentralKeyDisabled", func(t *testing.T) {
2290 t.Parallel()
2291
2292 ctx := testutil.Context(t, testutil.WaitLong)
2293 values := chatDeploymentValues(t)
2294 values.AI.BridgeConfig.LegacyOpenAI.Key = serpent.String("deployment-openai-key")
2295 client := newChatClientWithDeploymentValues(t, values)
2296 _ = coderdtest.CreateFirstUser(t, client.Client)
2297
2298 provider, err := client.CreateChatProvider(ctx, codersdk.CreateChatProviderConfigRequest{
2299 Provider: "openai",
2300 CentralAPIKeyEnabled: ptr.Ref(false),
2301 AllowUserAPIKey: ptr.Ref(true),
2302 })
2303 require.NoError(t, err)
2304 require.False(t, provider.HasAPIKey)
2305
2306 providers, err := client.ListChatProviders(ctx)
2307 require.NoError(t, err)
2308 for _, listed := range providers {
2309 if listed.Provider == "openai" {
2310 require.False(t, listed.HasAPIKey)
2311 return
2312 }
2313 }
2314 t.Fatal("openai provider not found")
2315 })
2316
2317 t.Run("ForbiddenForOrganizationMember", func(t *testing.T) {
2318 t.Parallel()

Callers

nothing calls this directly

Calls 15

ListChatProvidersMethod · 0.95
ContextFunction · 0.92
CreateFirstUserFunction · 0.92
RefFunction · 0.92
CreateAnotherUserFunction · 0.92
NewExperimentalClientFunction · 0.92
chatDeploymentValuesFunction · 0.85
requireSDKErrorFunction · 0.85
SkipMethod · 0.80
CreateChatProviderMethod · 0.80
FatalMethod · 0.80

Tested by

no test coverage detected