1package provider
2
3import (
4 "slices"
5 "testing"
6)
7
8func TestAvailableReasoningLevels(t *testing.T) {
9 tests := []struct {
10 name string
11 model Model
12 want []string
13 }{
14 {name: "unsupported", model: Model{}, want: []string{""}},
15 {name: "generic openai", model: Model{Reasoning: true}, want: []string{"", "low", "medium", "high"}},
16 {name: "responses", model: Model{Reasoning: true, API: APIResponses, ID: "gpt-5.5"}, want: []string{"", "low", "medium", "high", "xhigh"}},
17 {name: "responses native max", model: Model{Reasoning: true, API: APIResponses, ID: "gpt-5.6-sol"}, want: []string{"", "low", "medium", "high", "xhigh", "max"}},
18 {name: "astra native max", model: Model{Reasoning: true, API: APIResponses, ID: "gpt-6-astra"}, want: []string{"", "low", "medium", "high", "xhigh", "max"}},
19 {name: "adaptive", model: Model{Reasoning: true, AdaptiveThinking: true}, want: []string{"", "low", "medium", "high", "xhigh", "max"}},
20 {name: "adaptive compatible", model: Model{Reasoning: true, AdaptiveThinkingCompat: true}, want: []string{"", "high"}},
21 {name: "gemini pro", model: Model{Provider: "google", ID: "gemini-3-pro-preview", Reasoning: true}, want: []string{"", "low", "high"}},
22 {name: "gemini flash", model: Model{Provider: "google", ID: "gemini-3-flash-preview", Reasoning: true}, want: []string{"", "minimum", "low", "medium", "high"}},
23 {name: "gemini 2.5 budget", model: Model{Provider: "google", ID: "gemini-2.5-flash", Reasoning: true}, want: []string{"", "minimum", "low", "medium", "high", "xhigh"}},
24 {name: "gemini alias without control", model: Model{Provider: "google", ID: "gemini-flash-latest", Reasoning: true}, want: []string{""}},
25 {name: "anthropic budget", model: Model{Provider: "anthropic", Reasoning: true}, want: []string{"", "minimum", "low", "medium", "high", "xhigh"}},
26 {name: "bedrock without effort control", model: Model{Provider: "amazon-bedrock", Reasoning: true}, want: []string{""}},
27 {
28 name: "per-model overrides",
29 model: Model{
30 Provider: "anthropic", Reasoning: true,
31 ReasoningLevelMap: map[string]string{"minimum": "low", "high": "", "max": "max"},
32 },
33 want: []string{"", "low", "medium", "xhigh", "max"},
34 },
35 {
36 name: "explicit levels extend generic defaults",
37 model: Model{
38 Provider: "custom", Reasoning: true,
39 ReasoningLevelMap: map[string]string{
40 "minimum": "", "low": "", "medium": "", "high": "high", "xhigh": "xhigh", "max": "max",
41 },
42 },
43 want: []string{"", "high", "xhigh", "max"},
44 },
45 }
46 for _, tt := range tests {
47 t.Run(tt.name, func(t *testing.T) {
48 if got := AvailableReasoningLevels(tt.model); !slices.Equal(got, tt.want) {
49 t.Fatalf("levels = %q, want %q", got, tt.want)
50 }
51 })
52 }
53}
54
55func TestClampReasoningForModel(t *testing.T) {
56 tests := []struct {
57 name string
58 model Model
59 level string
60 want string
61 }{
62 {name: "unsupported", model: Model{}, level: "high", want: ""},
63 {name: "generic max", model: Model{Reasoning: true}, level: "max", want: "high"},
64 {name: "adaptive minimum", model: Model{Reasoning: true, AdaptiveThinking: true}, level: "minimum", want: "low"},
65 {name: "gemini pro medium", model: Model{Provider: "google", ID: "gemini-3-pro", Reasoning: true}, level: "medium", want: "high"},
66 {name: "native max", model: Model{Reasoning: true, API: APIResponses, ID: "gpt-5.6-sol"}, level: "max", want: "max"},
67 {name: "astra native max", model: Model{Reasoning: true, API: APIResponses, ID: "gpt-6-astra"}, level: "max", want: "max"},
68 {
69 name: "explicit equivalent",
70 model: Model{Reasoning: true, ReasoningLevelMap: map[string]string{"minimum": "high"}},
71 level: "minimum",
72 want: "high",
73 },
74 {
75 name: "explicit max extends generic defaults",
76 model: Model{Reasoning: true, ReasoningLevelMap: map[string]string{"max": "max"}},
77 level: "max",
78 want: "max",
79 },
80 }
81 for _, tt := range tests {
82 t.Run(tt.name, func(t *testing.T) {
83 if got := ClampReasoningForModel(tt.model, tt.level); got != tt.want {
84 t.Fatalf("level = %q, want %q", got, tt.want)
85 }
86 })
87 }
88}
89
90func TestOpenAIRequestUsesReasoningLevelMap(t *testing.T) {
91 SetLiveModels([]Model{{
92 Provider: "custom",
93 ID: "mapped-reasoning-model",
94 Reasoning: true,
95 ReasoningLevelMap: map[string]string{"high": "low", "max": "max"},
96 }})
97 t.Cleanup(func() { SetLiveModels(nil) })
98
99 client := NewOpenAICompat("custom", "test", "", "").(*openaiClient)
100 for _, tt := range []struct {
101 requested string
102 want string
103 }{
104 {requested: "high", want: "low"},
105 {requested: "max", want: "max"},
106 } {
107 request, err := client.buildRequest(Request{Model: "mapped-reasoning-model", Reasoning: tt.requested})
108 if err != nil {
109 t.Fatal(err)
110 }
111 if request.ReasoningEffort != tt.want {
112 t.Errorf("reasoning effort for %q = %q, want %q", tt.requested, request.ReasoningEffort, tt.want)
113 }
114 }
115}
116
117func TestReasoningEffortMappings(t *testing.T) {
118 cases := []struct {
119 level string
120 model string
121 openai string
122 anthCompat string
123 codex string
124 budget int
125 normalized string
126 }{
127 {"off", "gpt-5.6-sol", "", "", "", 0, ""},
128 {"minimum", "gpt-5.6-sol", "low", "low", "low", 1024, "minimum"},
129 {"minimal", "gpt-5.6-sol", "low", "low", "low", 1024, "minimum"},
130 {"low", "gpt-5.6-sol", "low", "low", "low", 2048, "low"},
131 {"medium", "gpt-5.6-sol", "medium", "medium", "medium", 8192, "medium"},
132 {"high", "gpt-5.6-sol", "high", "high", "high", 16384, "high"},
133 {"maximum", "gpt-5.6-sol", "high", "xhigh", "xhigh", 32768, "xhigh"},
134 {"xhigh", "gpt-5.6-sol", "high", "xhigh", "xhigh", 32768, "xhigh"},
135 {"max", "gpt-5.6-sol", "high", "max", "max", 32768, "max"},
136 {"max", "gpt-5.5", "high", "max", "xhigh", 32768, "max"},
137 {"max", "gpt-6-astra", "high", "max", "max", 32768, "max"},
138 {"max", "GPT-6-ASTRA", "high", "max", "max", 32768, "max"},
139 {"max", "gpt-6-unknown", "high", "max", "xhigh", 32768, "max"},
140 }
141 for _, tc := range cases {
142 if got := NormalizeReasoning(tc.level); got != tc.normalized {
143 t.Errorf("NormalizeReasoning(%q)=%q want %q", tc.level, got, tc.normalized)
144 }
145 if got := OpenAIReasoningEffort(tc.level); got != tc.openai {
146 t.Errorf("OpenAIReasoningEffort(%q)=%q want %q", tc.level, got, tc.openai)
147 }
148 if got := OpenAICompatAnthropicEffort(tc.level); got != tc.anthCompat {
149 t.Errorf("OpenAICompatAnthropicEffort(%q)=%q want %q", tc.level, got, tc.anthCompat)
150 }
151 if got := OpenAICodexReasoningEffort(tc.level, tc.model); got != tc.codex {
152 t.Errorf("OpenAICodexReasoningEffort(%q, %q)=%q want %q", tc.level, tc.model, got, tc.codex)
153 }
154 if got := ReasoningBudget(tc.level); got != tc.budget {
155 t.Errorf("ReasoningBudget(%q)=%d want %d", tc.level, got, tc.budget)
156 }
157 }
158}