| 1 | package config |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestDeepSeekV4FlashEffortCapabilityIncludesLow(t *testing.T) { |
| 9 | flash := &ProviderEntry{Kind: "openai", BaseURL: "https://api.deepseek.com", Model: "deepseek-v4-flash"} |
| 10 | cap := EffortCapabilityForEntry(flash) |
| 11 | want := []string{"auto", "disabled", "low", "high", "max"} |
| 12 | if !cap.Supported || len(cap.Levels) != len(want) { |
| 13 | t.Fatalf("Flash capability = %+v, want %v", cap, want) |
| 14 | } |
| 15 | for i := range want { |
| 16 | if cap.Levels[i] != want[i] { |
| 17 | t.Fatalf("Flash levels[%d] = %q, want %q", i, cap.Levels[i], want[i]) |
| 18 | } |
| 19 | } |
| 20 | if cap.Default != "high" { |
| 21 | t.Fatalf("Flash default = %q, want high", cap.Default) |
| 22 | } |
| 23 | if got, err := NormalizeEffort(flash, "low"); err != nil || got != "low" { |
| 24 | t.Fatalf("Flash low = %q/%v, want low/nil", got, err) |
| 25 | } |
| 26 | if _, err := NormalizeEffort(flash, "xhigh"); err == nil { |
| 27 | t.Fatal("undeclared xhigh must be rejected") |
| 28 | } |
| 29 | flash.ReasoningProtocol = ReasoningProtocolDeepSeek |
| 30 | if got := EffortCapabilityForEntry(flash); len(got.Levels) != len(want) || got.Levels[2] != "low" { |
| 31 | t.Fatalf("explicit DeepSeek Flash capability = %+v, want model-specific low", got) |
| 32 | } |
| 33 | if got, err := NormalizeEffort(flash, "low"); err != nil || got != "low" { |
| 34 | t.Fatalf("explicit DeepSeek Flash low = %q/%v, want low/nil", got, err) |
| 35 | } |
| 36 | if _, err := NormalizeEffort(flash, "xhigh"); err == nil { |
| 37 | t.Fatal("undeclared xhigh must be rejected") |
| 38 | } |
| 39 | |
| 40 | pro := &ProviderEntry{Kind: "openai", BaseURL: "https://api.deepseek.com", Model: "deepseek-v4-pro"} |
| 41 | if got, err := NormalizeEffort(pro, "low"); err != nil || got != "low" { |
| 42 | t.Fatalf("Pro low = %q/%v, want low/nil", got, err) |
| 43 | } |
| 44 | if _, err := NormalizeEffort(pro, "xhigh"); err == nil { |
| 45 | t.Fatal("undeclared xhigh must be rejected") |
| 46 | } |
| 47 | if cap := EffortCapabilityForEntry(pro); !containsString(cap.Levels, "low") { |
| 48 | t.Fatalf("Pro capability = %+v, want low", cap) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | func TestDefaultDeepSeekV4EntriesRejectCompatibilityAliases(t *testing.T) { |
| 53 | cfg := Default() |
| 54 | for _, ref := range []string{"deepseek-flash", "deepseek-pro"} { |
| 55 | entry, ok := cfg.ResolveModel(ref) |
| 56 | if !ok { |
| 57 | t.Fatalf("default model %q did not resolve", ref) |
| 58 | } |
| 59 | for _, alias := range []string{"medium", "xhigh"} { |
| 60 | got, err := NormalizeEffort(entry, alias) |
| 61 | if err == nil { |
| 62 | t.Errorf("%s %s = %q: undeclared alias accepted", ref, alias, got) |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | func TestDeepSeekV4CustomEffortVocabularyRemainsAuthoritative(t *testing.T) { |
| 69 | entry := &ProviderEntry{ |
| 70 | Kind: "anthropic", |
| 71 | Model: "deepseek-v4-pro", |
| 72 | SupportedEfforts: []string{"disabled", "high", "max"}, |
| 73 | } |
| 74 | if _, err := NormalizeEffort(entry, "medium"); err == nil { |
| 75 | t.Fatal("custom supported_efforts should reject an undeclared compatibility alias") |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | func TestIsMiniMaxEntry(t *testing.T) { |
| 80 | for _, tc := range []struct { |
| 81 | baseURL string |
| 82 | want bool |
| 83 | }{ |
| 84 | {"https://api.minimaxi.com/v1", true}, |
| 85 | {"https://api.minimaxi.com", true}, |
| 86 | {"https://api.minimaxi.com/anthropic", true}, |
| 87 | // Subdomain variants of the canonical host. |
| 88 | {"https://eu.minimaxi.com/v1", true}, |
| 89 | {"https://us.minimaxi.com/v1", true}, |
| 90 | // Bare apex (no api. prefix) is rejected: it would only match if |
| 91 | // the user pointed their base_url at the apex domain, which is a |
| 92 | // misconfiguration — not a path we want to silently accept. |
| 93 | {"https://minimaxi.com/v1", false}, |
| 94 | {"https://minimaxi.com", false}, |
| 95 | // Other vendors must not match. |
| 96 | {"https://api.deepseek.com", false}, |
| 97 | {"https://api.xiaomimimo.com/v1", false}, |
| 98 | {"https://api.minimax.example.com", false}, // wrong spelling — must not match |
| 99 | {"", false}, |
| 100 | } { |
| 101 | e := &ProviderEntry{Kind: "openai", BaseURL: tc.baseURL} |
| 102 | if got := isMiniMaxEntry(e); got != tc.want { |
| 103 | t.Errorf("baseURL=%q: isMiniMaxEntry=%v, want %v", tc.baseURL, got, tc.want) |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | func TestIsZhipuEntry(t *testing.T) { |
| 109 | for _, tc := range []struct { |
| 110 | baseURL string |
| 111 | want bool |
| 112 | }{ |
| 113 | {"https://open.bigmodel.cn/api/paas/v4", true}, |
| 114 | {"https://open.bigmodel.cn", true}, |
| 115 | {"https://api.bigmodel.cn/v1", true}, |
| 116 | {"https://api.z.ai/api/paas/v4", true}, |
| 117 | {"https://open.z.ai/v1", true}, |
| 118 | // Bare apexes rejected. |
| 119 | {"https://bigmodel.cn/v1", false}, |
| 120 | {"https://z.ai", false}, |
| 121 | // Other vendors must not match. |
| 122 | {"https://api.deepseek.com", false}, |
| 123 | {"https://api.minimaxi.com/v1", false}, |
| 124 | {"", false}, |
| 125 | } { |
| 126 | e := &ProviderEntry{Kind: "openai", BaseURL: tc.baseURL} |
| 127 | if got := isZhipuEntry(e); got != tc.want { |
| 128 | t.Errorf("baseURL=%q: isZhipuEntry=%v, want %v", tc.baseURL, got, tc.want) |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | func TestIsLongCatEntry(t *testing.T) { |
| 134 | for _, tc := range []struct { |
| 135 | baseURL string |
| 136 | want bool |
| 137 | }{ |
| 138 | {"https://api.longcat.chat/openai/v1", true}, |
| 139 | {"https://api.longcat.chat/anthropic", true}, |
| 140 | {"https://longcat.chat/openai/v1", false}, |
| 141 | {"https://api.deepseek.com", false}, |
| 142 | {"", false}, |
| 143 | } { |
| 144 | e := &ProviderEntry{Kind: "openai", BaseURL: tc.baseURL} |
| 145 | if got := isLongCatEntry(e); got != tc.want { |
| 146 | t.Errorf("baseURL=%q: isLongCatEntry=%v, want %v", tc.baseURL, got, tc.want) |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | func TestIsOllamaCloudEntry(t *testing.T) { |
| 152 | for _, tc := range []struct { |
| 153 | baseURL string |
| 154 | want bool |
| 155 | }{ |
| 156 | {"https://ollama.com/v1", true}, |
| 157 | {"https://api.ollama.com/v1", true}, |
| 158 | {"https://localhost:11434/v1", false}, |
| 159 | {"http://127.0.0.1:11434/v1", false}, |
| 160 | {"https://api.openai.com/v1", false}, |
| 161 | {"", false}, |
| 162 | } { |
| 163 | e := &ProviderEntry{Kind: "openai", BaseURL: tc.baseURL} |
| 164 | if got := isOllamaCloudEntry(e); got != tc.want { |
| 165 | t.Errorf("baseURL=%q: isOllamaCloudEntry=%v, want %v", tc.baseURL, got, tc.want) |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | func TestIsMimoEntry(t *testing.T) { |
| 171 | for _, tc := range []struct { |
| 172 | baseURL string |
| 173 | want bool |
| 174 | }{ |
| 175 | {"https://api.xiaomimimo.com/v1", true}, |
| 176 | {"https://api.xiaomimimo.com/v1/responses", true}, |
| 177 | {"https://api.deepseek.com", false}, |
| 178 | {"https://dashscope.aliyuncs.com/compatible-mode/v1", false}, |
| 179 | {"https://api.xiaomimimo.com.attacker.example/v1", false}, |
| 180 | {"https://example.com/?u=api.xiaomimimo.com", false}, |
| 181 | {"", false}, |
| 182 | } { |
| 183 | if got := isMimoEntry(&ProviderEntry{BaseURL: tc.baseURL}); got != tc.want { |
| 184 | t.Errorf("baseURL=%q: isMimoEntry=%v, want %v", tc.baseURL, got, tc.want) |
| 185 | } |
| 186 | } |
| 187 | if isMimoEntry(nil) { |
| 188 | t.Fatal("isMimoEntry(nil) must be false") |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | func TestMimoEffortSupportsNone(t *testing.T) { |
| 193 | e := &ProviderEntry{ |
| 194 | Kind: "responses", |
| 195 | BaseURL: "https://api.xiaomimimo.com/v1", |
| 196 | ReasoningProtocol: ReasoningProtocolOpenAI, |
| 197 | } |
| 198 | cap := EffortCapabilityForEntry(e) |
| 199 | if !cap.Supported { |
| 200 | t.Fatal("MiMo effort must be supported") |
| 201 | } |
| 202 | for _, level := range []string{"auto", "none", "low", "medium", "high"} { |
| 203 | if !containsString(cap.Levels, level) { |
| 204 | t.Errorf("MiMo capability missing %q: %v", level, cap.Levels) |
| 205 | } |
| 206 | } |
| 207 | got, err := NormalizeEffort(e, "none") |
| 208 | if err != nil || got != "none" { |
| 209 | t.Fatalf("MiMo none = %q/%v, want none/nil", got, err) |
| 210 | } |
| 211 | for _, level := range []string{"low", "medium", "high"} { |
| 212 | if got, err := NormalizeEffort(e, level); err != nil || got != level { |
| 213 | t.Fatalf("MiMo %s = %q/%v, want %s/nil", level, got, err, level) |
| 214 | } |
| 215 | } |
| 216 | if _, err := NormalizeEffort(e, "xhigh"); err == nil { |
| 217 | t.Fatal("MiMo xhigh must be rejected") |
| 218 | } |
| 219 | // A plain OpenAI endpoint keeps rejecting none. |
| 220 | plain := &ProviderEntry{Kind: "openai", BaseURL: "https://example.com/v1", ReasoningProtocol: ReasoningProtocolOpenAI} |
| 221 | if got, err := NormalizeEffort(plain, "none"); err == nil || got != "" { |
| 222 | t.Fatalf("plain OpenAI none = %q/%v, want error", got, err) |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | func TestEffortCapabilityZhipu(t *testing.T) { |
| 227 | e := &ProviderEntry{Kind: "openai", BaseURL: "https://open.bigmodel.cn/api/paas/v4", Model: "glm-4.5-air"} |
| 228 | cap := EffortCapabilityForEntry(e) |
| 229 | if !cap.Supported { |
| 230 | t.Fatalf("GLM entry should expose /effort, got %+v", cap) |
| 231 | } |
| 232 | wantLevels := []string{"auto", "enabled", "disabled"} |
| 233 | if len(cap.Levels) != len(wantLevels) { |
| 234 | t.Fatalf("levels = %v, want %v", cap.Levels, wantLevels) |
| 235 | } |
| 236 | for i, l := range wantLevels { |
| 237 | if cap.Levels[i] != l { |
| 238 | t.Errorf("levels[%d] = %q, want %q", i, cap.Levels[i], l) |
| 239 | } |
| 240 | } |
| 241 | if cap.Default != "enabled" { |
| 242 | t.Errorf("default = %q, want enabled (GLM ships with thinking on)", cap.Default) |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | func TestEffortCapabilityExplicitGLMProtocolOnGateway(t *testing.T) { |
| 247 | e := &ProviderEntry{ |
| 248 | Name: "glm-gateway", |
| 249 | Kind: "openai", |
| 250 | BaseURL: "https://gateway.example.com/v1", |
| 251 | Model: "glm-5.2", |
| 252 | ReasoningProtocol: ReasoningProtocolGLM, |
| 253 | } |
| 254 | cap := EffortCapabilityForEntry(e) |
| 255 | want := []string{"auto", "enabled", "disabled"} |
| 256 | if !cap.Supported || cap.Default != "enabled" || len(cap.Levels) != len(want) { |
| 257 | t.Fatalf("explicit GLM capability = %+v, want levels %v default enabled", cap, want) |
| 258 | } |
| 259 | for i := range want { |
| 260 | if cap.Levels[i] != want[i] { |
| 261 | t.Fatalf("explicit GLM levels[%d] = %q, want %q", i, cap.Levels[i], want[i]) |
| 262 | } |
| 263 | } |
| 264 | if got, err := NormalizeEffort(e, "disabled"); err != nil || got != "disabled" { |
| 265 | t.Fatalf("explicit GLM disabled = %q/%v, want disabled/nil", got, err) |
| 266 | } |
| 267 | if _, err := NormalizeEffort(e, "high"); err == nil { |
| 268 | t.Fatal("GLM must reject undeclared depth") |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | func TestGLMModelRegistryUpgradesLegacyGatewayConfig(t *testing.T) { |
| 273 | for _, model := range []string{"glm-5", "glm-5.1", "glm-5.2"} { |
| 274 | t.Run(model, func(t *testing.T) { |
| 275 | // This is the shape persisted by an older Token Rhythm installation: |
| 276 | // no reasoning_protocol and no model_overrides metadata. |
| 277 | e := &ProviderEntry{ |
| 278 | Name: "token-rhythm", |
| 279 | Kind: "openai", |
| 280 | BaseURL: "https://tokenrhythm.studio/v1", |
| 281 | Model: model, |
| 282 | } |
| 283 | if got := ReasoningProtocolForEntry(e); got != ReasoningProtocolGLM { |
| 284 | t.Fatalf("ReasoningProtocolForEntry() = %q, want %q", got, ReasoningProtocolGLM) |
| 285 | } |
| 286 | cap := EffortCapabilityForEntry(e) |
| 287 | want := []string{"auto", "enabled", "disabled"} |
| 288 | if !cap.Supported || cap.Default != "enabled" || !stringSlicesEqual(cap.Levels, want) { |
| 289 | t.Fatalf("legacy gateway GLM capability = %+v, want levels %v default enabled", cap, want) |
| 290 | } |
| 291 | }) |
| 292 | } |
| 293 | |
| 294 | nonGLM := &ProviderEntry{Kind: "openai", BaseURL: "https://tokenrhythm.studio/v1", Model: "my-glm-5.2-alias"} |
| 295 | if got := ReasoningProtocolForEntry(nonGLM); got != "" { |
| 296 | t.Fatalf("non-exact GLM alias protocol = %q, want empty without explicit override", got) |
| 297 | } |
| 298 | otherGateway := &ProviderEntry{Kind: "openai", BaseURL: "https://unrelated-gateway.example/v1", Model: "glm-5.2"} |
| 299 | if got := ReasoningProtocolForEntry(otherGateway); got != "" { |
| 300 | t.Fatalf("unrelated gateway GLM protocol = %q, want empty without explicit override", got) |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | func TestEffortCapabilityLongCat(t *testing.T) { |
| 305 | e := &ProviderEntry{Kind: "openai", BaseURL: "https://api.longcat.chat/openai/v1", Model: "LongCat-2.0"} |
| 306 | cap := EffortCapabilityForEntry(e) |
| 307 | if !cap.Supported { |
| 308 | t.Fatalf("LongCat entry should expose /effort, got %+v", cap) |
| 309 | } |
| 310 | wantLevels := []string{"auto", "enabled", "disabled"} |
| 311 | if len(cap.Levels) != len(wantLevels) { |
| 312 | t.Fatalf("levels = %v, want %v", cap.Levels, wantLevels) |
| 313 | } |
| 314 | for i, l := range wantLevels { |
| 315 | if cap.Levels[i] != l { |
| 316 | t.Errorf("levels[%d] = %q, want %q", i, cap.Levels[i], l) |
| 317 | } |
| 318 | } |
| 319 | if cap.Default != "enabled" { |
| 320 | t.Errorf("default = %q, want enabled", cap.Default) |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | func TestEffortCapabilityOllamaCloud(t *testing.T) { |
| 325 | e := &ProviderEntry{Kind: "openai", BaseURL: "https://ollama.com/v1", Model: "nemotron-3-nano:30b"} |
| 326 | cap := EffortCapabilityForEntry(e) |
| 327 | if !cap.Supported { |
| 328 | t.Fatalf("Ollama Cloud entry should expose /effort, got %+v", cap) |
| 329 | } |
| 330 | wantLevels := []string{"auto", "none", "low", "medium", "high", "max"} |
| 331 | if len(cap.Levels) != len(wantLevels) { |
| 332 | t.Fatalf("levels = %v, want %v", cap.Levels, wantLevels) |
| 333 | } |
| 334 | for i, l := range wantLevels { |
| 335 | if cap.Levels[i] != l { |
| 336 | t.Errorf("levels[%d] = %q, want %q", i, cap.Levels[i], l) |
| 337 | } |
| 338 | } |
| 339 | if cap.Default != "auto" { |
| 340 | t.Errorf("default = %q, want auto", cap.Default) |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | func TestNormalizeEffortOllamaCloud(t *testing.T) { |
| 345 | e := &ProviderEntry{Kind: "openai", BaseURL: "https://ollama.com/v1", Model: "nemotron-3-nano:30b"} |
| 346 | cases := []struct { |
| 347 | in, want string |
| 348 | }{ |
| 349 | {"auto", ""}, |
| 350 | {"none", "none"}, |
| 351 | {"disabled", "none"}, |
| 352 | {"off", "none"}, |
| 353 | {"low", "low"}, |
| 354 | {"medium", "medium"}, |
| 355 | {"high", "high"}, |
| 356 | {"xhigh", "max"}, |
| 357 | {"max", "max"}, |
| 358 | } |
| 359 | for _, tc := range cases { |
| 360 | got, err := NormalizeEffort(e, tc.in) |
| 361 | if tc.in != tc.want && tc.in != "auto" { |
| 362 | if err == nil { |
| 363 | t.Errorf("undeclared %q was silently mapped to %q", tc.in, got) |
| 364 | } |
| 365 | continue |
| 366 | } |
| 367 | if err != nil { |
| 368 | t.Errorf("NormalizeEffort(%q) returned error: %v", tc.in, err) |
| 369 | continue |
| 370 | } |
| 371 | if got != tc.want { |
| 372 | t.Errorf("NormalizeEffort(%q) = %q, want %q", tc.in, got, tc.want) |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | func TestNormalizeEffortZhipu(t *testing.T) { |
| 378 | e := &ProviderEntry{Kind: "openai", BaseURL: "https://open.bigmodel.cn/api/paas/v4", Model: "glm-4.5-air"} |
| 379 | cases := []struct { |
| 380 | in, want string |
| 381 | }{ |
| 382 | {"auto", ""}, // auto == leave to provider default == empty |
| 383 | {"enabled", "enabled"}, |
| 384 | {"disabled", "disabled"}, |
| 385 | {"ENABLED", "enabled"}, // case-insensitive |
| 386 | // Stale values from other vendors resolve to a valid GLM level rather |
| 387 | // than failing the /effort command. |
| 388 | {"off", "disabled"}, // retired DeepSeek "no thinking" |
| 389 | {"low", "enabled"}, |
| 390 | {"medium", "enabled"}, |
| 391 | {"high", "enabled"}, |
| 392 | {"xhigh", "enabled"}, |
| 393 | {"max", "enabled"}, |
| 394 | } |
| 395 | for _, tc := range cases { |
| 396 | got, err := NormalizeEffort(e, tc.in) |
| 397 | if tc.in != tc.want && tc.in != "auto" { |
| 398 | if err == nil { |
| 399 | t.Errorf("undeclared %q was silently mapped to %q", tc.in, got) |
| 400 | } |
| 401 | continue |
| 402 | } |
| 403 | if err != nil { |
| 404 | t.Errorf("NormalizeEffort(%q) returned error: %v", tc.in, err) |
| 405 | continue |
| 406 | } |
| 407 | if got != tc.want { |
| 408 | t.Errorf("NormalizeEffort(%q) = %q, want %q", tc.in, got, tc.want) |
| 409 | } |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | func TestNormalizeEffortLongCat(t *testing.T) { |
| 414 | e := &ProviderEntry{Kind: "openai", BaseURL: "https://api.longcat.chat/openai/v1", Model: "LongCat-2.0"} |
| 415 | cases := []struct { |
| 416 | in, want string |
| 417 | }{ |
| 418 | {"auto", ""}, |
| 419 | {"enabled", "enabled"}, |
| 420 | {"disabled", "disabled"}, |
| 421 | {"ENABLED", "enabled"}, |
| 422 | {"off", "disabled"}, |
| 423 | {"low", "enabled"}, |
| 424 | {"medium", "enabled"}, |
| 425 | {"high", "enabled"}, |
| 426 | {"xhigh", "enabled"}, |
| 427 | {"max", "enabled"}, |
| 428 | } |
| 429 | for _, tc := range cases { |
| 430 | got, err := NormalizeEffort(e, tc.in) |
| 431 | if tc.in != tc.want && tc.in != "auto" { |
| 432 | if err == nil { |
| 433 | t.Errorf("undeclared %q was silently mapped to %q", tc.in, got) |
| 434 | } |
| 435 | continue |
| 436 | } |
| 437 | if err != nil { |
| 438 | t.Errorf("NormalizeEffort(%q) returned error: %v", tc.in, err) |
| 439 | continue |
| 440 | } |
| 441 | if got != tc.want { |
| 442 | t.Errorf("NormalizeEffort(%q) = %q, want %q", tc.in, got, tc.want) |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | func TestEffortCapabilityMiniMax(t *testing.T) { |
| 448 | e := &ProviderEntry{Kind: "openai", BaseURL: "https://api.minimaxi.com/v1", Model: "MiniMax-M3"} |
| 449 | cap := EffortCapabilityForEntry(e) |
| 450 | if !cap.Supported { |
| 451 | t.Fatalf("M3 entry should expose /effort, got %+v", cap) |
| 452 | } |
| 453 | wantLevels := []string{"auto", "adaptive", "disabled"} |
| 454 | if len(cap.Levels) != len(wantLevels) { |
| 455 | t.Fatalf("levels = %v, want %v", cap.Levels, wantLevels) |
| 456 | } |
| 457 | for i, l := range wantLevels { |
| 458 | if cap.Levels[i] != l { |
| 459 | t.Errorf("levels[%d] = %q, want %q", i, cap.Levels[i], l) |
| 460 | } |
| 461 | } |
| 462 | if cap.Default != "adaptive" { |
| 463 | t.Errorf("default = %q, want adaptive (M3 ships with thinking on)", cap.Default) |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | func TestNormalizeEffortMiniMax(t *testing.T) { |
| 468 | e := &ProviderEntry{Kind: "openai", BaseURL: "https://api.minimaxi.com/v1", Model: "MiniMax-M3"} |
| 469 | cases := []struct { |
| 470 | in, want string |
| 471 | }{ |
| 472 | {"auto", ""}, // auto == "leave to provider default" == empty |
| 473 | {"adaptive", "adaptive"}, |
| 474 | {"disabled", "disabled"}, |
| 475 | {"ADAPTIVE", "adaptive"}, // case-insensitive |
| 476 | // Stale values from other vendors still resolve to a valid M3 level |
| 477 | // rather than failing the /effort command. |
| 478 | {"off", "disabled"}, // retired DeepSeek "no thinking" → M3 actually supports "disabled" |
| 479 | {"low", "adaptive"}, |
| 480 | {"medium", "adaptive"}, |
| 481 | {"high", "adaptive"}, |
| 482 | {"xhigh", "disabled"}, |
| 483 | {"max", "disabled"}, |
| 484 | } |
| 485 | for _, tc := range cases { |
| 486 | got, err := NormalizeEffort(e, tc.in) |
| 487 | if tc.in != tc.want && tc.in != "auto" { |
| 488 | if err == nil { |
| 489 | t.Errorf("undeclared %q was silently mapped to %q", tc.in, got) |
| 490 | } |
| 491 | continue |
| 492 | } |
| 493 | if err != nil { |
| 494 | t.Errorf("NormalizeEffort(%q) returned error: %v", tc.in, err) |
| 495 | continue |
| 496 | } |
| 497 | if got != tc.want { |
| 498 | t.Errorf("NormalizeEffort(%q) = %q, want %q", tc.in, got, tc.want) |
| 499 | } |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | func TestNormalizeEffortMiniMaxRejectsGarbage(t *testing.T) { |
| 504 | e := &ProviderEntry{Kind: "openai", BaseURL: "https://api.minimaxi.com/v1", Model: "MiniMax-M3"} |
| 505 | // "turbo" and similar unrecognised inputs reach the MiniMax switch and |
| 506 | // are rejected with the MiniMax-specific usage hint. Empty input is |
| 507 | // rejected earlier with the generic hint; both are valid user-facing |
| 508 | // errors. "off" is *not* in this list — it's a retired level we now |
| 509 | // migrate to "adaptive" (tested in TestNormalizeEffortMiniMax above). |
| 510 | cases := map[string]string{ |
| 511 | "turbo": "UNSUPPORTED_REASONING_EFFORT", |
| 512 | "": "auto|<level>", |
| 513 | } |
| 514 | for in, wantHint := range cases { |
| 515 | _, err := NormalizeEffort(e, in) |
| 516 | if err == nil { |
| 517 | t.Errorf("NormalizeEffort(%q) should be rejected", in) |
| 518 | continue |
| 519 | } |
| 520 | if !strings.Contains(err.Error(), wantHint) { |
| 521 | t.Errorf("NormalizeEffort(%q) error = %q, want it to mention %q", in, err.Error(), wantHint) |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | func TestEffectiveEffortMiniMax(t *testing.T) { |
| 527 | e := &ProviderEntry{Kind: "openai", BaseURL: "https://api.minimaxi.com/v1", Model: "MiniMax-M3"} |
| 528 | // unset → EffectiveEffort stays empty so the wire layer defaults to adaptive |
| 529 | if got := EffectiveEffort(e); got != "" { |
| 530 | t.Errorf("unset EffectiveEffort = %q, want \"\"", got) |
| 531 | } |
| 532 | // explicit value is preserved verbatim |
| 533 | e.Effort = "disabled" |
| 534 | if got := EffectiveEffort(e); got != "disabled" { |
| 535 | t.Errorf("explicit EffectiveEffort = %q, want disabled", got) |
| 536 | } |
| 537 | } |
| 538 |