-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils_test.go
More file actions
65 lines (57 loc) · 2.1 KB
/
utils_test.go
File metadata and controls
65 lines (57 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package agentd
import (
"context"
"strings"
"testing"
)
func TestCreateModel_MissingAnthropicKey(t *testing.T) {
_, err := createModel(context.Background(), "claude-sonnet-4-6", staticModelKeyDiscoverer{})
if err == nil {
t.Fatal("expected error for missing Anthropic key")
}
if !strings.Contains(err.Error(), "Anthropic API key is required") {
t.Errorf("error should mention Anthropic key requirement, got: %v", err)
}
if !strings.Contains(err.Error(), HeaderAnthropicAPIKey) {
t.Errorf("error should mention BYOK header name, got: %v", err)
}
}
func TestCreateModel_MissingOpenAIKey(t *testing.T) {
_, err := createModel(context.Background(), "gpt-4o", staticModelKeyDiscoverer{})
if err == nil {
t.Fatal("expected error for missing OpenAI key")
}
if !strings.Contains(err.Error(), "OpenAI API key is required") {
t.Errorf("error should mention OpenAI key requirement, got: %v", err)
}
if !strings.Contains(err.Error(), HeaderOpenAIAPIKey) {
t.Errorf("error should mention BYOK header name, got: %v", err)
}
}
func TestCreateModel_MissingGeminiKey(t *testing.T) {
_, err := createModel(context.Background(), "gemini-2.5-flash", staticModelKeyDiscoverer{})
if err == nil {
t.Fatal("expected error for missing Gemini key")
}
if !strings.Contains(err.Error(), "Gemini API key is required") {
t.Errorf("error should mention Gemini key requirement, got: %v", err)
}
if !strings.Contains(err.Error(), HeaderGeminiAPIKey) {
t.Errorf("error should mention BYOK header name, got: %v", err)
}
}
func TestCreateModel_KeysNotInErrorDetail(t *testing.T) {
secretKey := "sk-super-secret-12345"
_, err := createModel(context.Background(), "claude-sonnet-4-6", staticModelKeyDiscoverer{key: secretKey})
// When a key IS provided but for the wrong provider, the error for the
// correct provider should never leak the other provider's key value.
if err != nil && strings.Contains(err.Error(), secretKey) {
t.Errorf("error message must not contain raw API key material")
}
}
type staticModelKeyDiscoverer struct {
key string
}
func (d staticModelKeyDiscoverer) APIKeyForModel(string) string {
return d.key
}