(t *testing.T)
| 3347 | } |
| 3348 | |
| 3349 | func TestUpsertUserChatProviderKey(t *testing.T) { |
| 3350 | t.Parallel() |
| 3351 | t.Skip("legacy chat provider API removed in favor of AI provider API") |
| 3352 | |
| 3353 | t.Run("RejectsTooLargeAPIKey", func(t *testing.T) { |
| 3354 | t.Parallel() |
| 3355 | |
| 3356 | ctx := testutil.Context(t, testutil.WaitLong) |
| 3357 | client := newChatClient(t) |
| 3358 | _ = coderdtest.CreateFirstUser(t, client.Client) |
| 3359 | |
| 3360 | provider, err := client.CreateChatProvider(ctx, codersdk.CreateChatProviderConfigRequest{ |
| 3361 | Provider: "anthropic", |
| 3362 | CentralAPIKeyEnabled: ptr.Ref(false), |
| 3363 | AllowUserAPIKey: ptr.Ref(true), |
| 3364 | }) |
| 3365 | require.NoError(t, err) |
| 3366 | |
| 3367 | _, err = client.UpsertUserChatProviderKey(ctx, provider.ID, codersdk.CreateUserChatProviderKeyRequest{ |
| 3368 | APIKey: strings.Repeat("a", chatProviderAPIKeySizeLimit+1), |
| 3369 | }) |
| 3370 | sdkErr := requireSDKError(t, err, http.StatusBadRequest) |
| 3371 | require.Equal(t, "API key too large.", sdkErr.Message) |
| 3372 | require.Equal(t, fmt.Sprintf("API key exceeds maximum size of 10 KB (%d bytes)", chatProviderAPIKeySizeLimit), sdkErr.Detail) |
| 3373 | }) |
| 3374 | |
| 3375 | t.Run("AllowsMaxSizedAPIKey", func(t *testing.T) { |
| 3376 | t.Parallel() |
| 3377 | |
| 3378 | ctx := testutil.Context(t, testutil.WaitLong) |
| 3379 | client := newChatClient(t) |
| 3380 | _ = coderdtest.CreateFirstUser(t, client.Client) |
| 3381 | |
| 3382 | provider, err := client.CreateChatProvider(ctx, codersdk.CreateChatProviderConfigRequest{ |
| 3383 | Provider: "anthropic", |
| 3384 | CentralAPIKeyEnabled: ptr.Ref(false), |
| 3385 | AllowUserAPIKey: ptr.Ref(true), |
| 3386 | }) |
| 3387 | require.NoError(t, err) |
| 3388 | |
| 3389 | config, err := client.UpsertUserChatProviderKey(ctx, provider.ID, codersdk.CreateUserChatProviderKeyRequest{ |
| 3390 | APIKey: strings.Repeat("a", chatProviderAPIKeySizeLimit), |
| 3391 | }) |
| 3392 | require.NoError(t, err) |
| 3393 | require.True(t, config.HasUserAPIKey) |
| 3394 | }) |
| 3395 | } |
| 3396 | |
| 3397 | func TestListChatModelConfigs(t *testing.T) { |
| 3398 | t.Parallel() |
nothing calls this directly
no test coverage detected