(t *testing.T)
| 52 | } |
| 53 | |
| 54 | func TestResolveUserProviderKeys(t *testing.T) { |
| 55 | t.Parallel() |
| 56 | |
| 57 | configuredProvider := func(id uuid.UUID, provider string, centralEnabled bool, centralKey string, allowUser bool, allowCentralFallback bool) chatprovider.ConfiguredProvider { |
| 58 | return chatprovider.ConfiguredProvider{ |
| 59 | ProviderID: id, |
| 60 | Provider: provider, |
| 61 | APIKey: centralKey, |
| 62 | CentralAPIKeyEnabled: centralEnabled, |
| 63 | AllowUserAPIKey: allowUser, |
| 64 | AllowCentralAPIKeyFallback: allowCentralFallback, |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | userProviderKey := func(id uuid.UUID, apiKey string) chatprovider.UserProviderKey { |
| 69 | return chatprovider.UserProviderKey{ |
| 70 | ChatProviderID: id, |
| 71 | APIKey: apiKey, |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | openAIProviderID := uuid.MustParse("00000000-0000-0000-0000-000000000001") |
| 76 | anthropicProviderID := uuid.MustParse("00000000-0000-0000-0000-000000000002") |
| 77 | bedrockProviderID := uuid.MustParse("00000000-0000-0000-0000-000000000003") |
| 78 | |
| 79 | tests := []struct { |
| 80 | name string |
| 81 | fallback chatprovider.ProviderAPIKeys |
| 82 | providers []chatprovider.ConfiguredProvider |
| 83 | userKeys []chatprovider.UserProviderKey |
| 84 | wantAvailability map[string]chatprovider.ProviderAvailability |
| 85 | wantKeys map[string]string |
| 86 | wantKeyPresence map[string]bool |
| 87 | }{ |
| 88 | { |
| 89 | name: "CentralOnlyKeyPresent", |
| 90 | providers: []chatprovider.ConfiguredProvider{configuredProvider(openAIProviderID, fantasyopenai.Name, true, "sk-central", false, false)}, |
| 91 | wantAvailability: map[string]chatprovider.ProviderAvailability{ |
| 92 | fantasyopenai.Name: {Available: true}, |
| 93 | }, |
| 94 | wantKeys: map[string]string{ |
| 95 | fantasyopenai.Name: "sk-central", |
| 96 | }, |
| 97 | }, |
| 98 | { |
| 99 | name: "CentralOnlyKeyMissing", |
| 100 | providers: []chatprovider.ConfiguredProvider{configuredProvider(openAIProviderID, fantasyopenai.Name, true, "", false, false)}, |
| 101 | wantAvailability: map[string]chatprovider.ProviderAvailability{ |
| 102 | fantasyopenai.Name: {Available: false, UnavailableReason: codersdk.ChatModelProviderUnavailableMissingAPIKey}, |
| 103 | }, |
| 104 | wantKeys: map[string]string{ |
| 105 | fantasyopenai.Name: "", |
| 106 | }, |
| 107 | wantKeyPresence: map[string]bool{ |
| 108 | fantasyopenai.Name: false, |
| 109 | }, |
| 110 | }, |
| 111 | { |
nothing calls this directly
no test coverage detected