(t *testing.T)
| 21 | ) |
| 22 | |
| 23 | func TestReadAIProvidersFromEnv(t *testing.T) { |
| 24 | t.Parallel() |
| 25 | |
| 26 | tests := []struct { |
| 27 | name string |
| 28 | env []string |
| 29 | expected []codersdk.AIProviderConfig |
| 30 | errContains string |
| 31 | }{ |
| 32 | { |
| 33 | name: "Empty", |
| 34 | env: []string{"HOME=/home/frodo"}, |
| 35 | }, |
| 36 | { |
| 37 | name: "SingleProvider", |
| 38 | env: []string{ |
| 39 | "CODER_AIBRIDGE_PROVIDER_0_TYPE=anthropic", |
| 40 | "CODER_AIBRIDGE_PROVIDER_0_NAME=anthropic-zdr", |
| 41 | "CODER_AIBRIDGE_PROVIDER_0_KEY=sk-ant-xxx", |
| 42 | "CODER_AIBRIDGE_PROVIDER_0_BASE_URL=https://api.anthropic.com/", |
| 43 | }, |
| 44 | expected: []codersdk.AIProviderConfig{ |
| 45 | { |
| 46 | Type: aibridge.ProviderAnthropic, |
| 47 | Name: "anthropic-zdr", |
| 48 | Keys: []string{"sk-ant-xxx"}, |
| 49 | BaseURL: "https://api.anthropic.com/", |
| 50 | }, |
| 51 | }, |
| 52 | }, |
| 53 | { |
| 54 | name: "SingleProviderAIGatewayPrefix", |
| 55 | env: []string{ |
| 56 | "CODER_AI_GATEWAY_PROVIDER_0_TYPE=anthropic", |
| 57 | "CODER_AI_GATEWAY_PROVIDER_0_NAME=anthropic-zdr", |
| 58 | "CODER_AI_GATEWAY_PROVIDER_0_KEY=sk-ant-xxx", |
| 59 | "CODER_AI_GATEWAY_PROVIDER_0_BASE_URL=https://api.anthropic.com/", |
| 60 | }, |
| 61 | expected: []codersdk.AIProviderConfig{ |
| 62 | { |
| 63 | Type: aibridge.ProviderAnthropic, |
| 64 | Name: "anthropic-zdr", |
| 65 | Keys: []string{"sk-ant-xxx"}, |
| 66 | BaseURL: "https://api.anthropic.com/", |
| 67 | }, |
| 68 | }, |
| 69 | }, |
| 70 | { |
| 71 | name: "MultipleProvidersSameType", |
| 72 | env: []string{ |
| 73 | "CODER_AIBRIDGE_PROVIDER_0_TYPE=anthropic", |
| 74 | "CODER_AIBRIDGE_PROVIDER_0_NAME=anthropic-us", |
| 75 | "CODER_AIBRIDGE_PROVIDER_1_TYPE=anthropic", |
| 76 | "CODER_AIBRIDGE_PROVIDER_1_NAME=anthropic-eu", |
| 77 | "CODER_AIBRIDGE_PROVIDER_1_BASE_URL=https://eu.api.anthropic.com/", |
| 78 | }, |
| 79 | expected: []codersdk.AIProviderConfig{ |
| 80 | {Type: aibridge.ProviderAnthropic, Name: "anthropic-us"}, |
nothing calls this directly
no test coverage detected