|
| 1 | +package cliproxy |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/router-for-me/CLIProxyAPI/v6/internal/registry" |
| 7 | + coreauth "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/auth" |
| 8 | + "github.com/router-for-me/CLIProxyAPI/v6/sdk/config" |
| 9 | +) |
| 10 | + |
| 11 | +func TestRegisterModelsForAuth_OpenAICompatibility_DefaultThinkingPreservesLegacyPassthrough(t *testing.T) { |
| 12 | + modelID := "compat-default-" + t.Name() |
| 13 | + authID := "auth-" + t.Name() |
| 14 | + service := &Service{ |
| 15 | + cfg: &config.Config{ |
| 16 | + OpenAICompatibility: []config.OpenAICompatibility{{ |
| 17 | + Name: "compat-default", |
| 18 | + Models: []config.OpenAICompatibilityModel{{ |
| 19 | + Name: "upstream-default", |
| 20 | + Alias: modelID, |
| 21 | + }}, |
| 22 | + }}, |
| 23 | + }, |
| 24 | + } |
| 25 | + auth := &coreauth.Auth{ |
| 26 | + ID: authID, |
| 27 | + Provider: "openai-compatibility", |
| 28 | + Status: coreauth.StatusActive, |
| 29 | + Attributes: map[string]string{ |
| 30 | + "compat_name": "compat-default", |
| 31 | + }, |
| 32 | + } |
| 33 | + |
| 34 | + reg := GlobalModelRegistry() |
| 35 | + reg.UnregisterClient(auth.ID) |
| 36 | + t.Cleanup(func() { |
| 37 | + reg.UnregisterClient(auth.ID) |
| 38 | + }) |
| 39 | + |
| 40 | + service.registerModelsForAuth(auth) |
| 41 | + |
| 42 | + got := registry.LookupModelInfo(modelID, "compat-default") |
| 43 | + if got == nil { |
| 44 | + t.Fatalf("expected model %q to be registered", modelID) |
| 45 | + } |
| 46 | + if !got.UserDefined { |
| 47 | + t.Fatalf("expected model %q to remain user-defined when thinking is omitted", modelID) |
| 48 | + } |
| 49 | + if got.Thinking != nil { |
| 50 | + t.Fatalf("expected model %q to keep nil thinking support when omitted, got %+v", modelID, got.Thinking) |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +func TestRegisterModelsForAuth_OpenAICompatibility_ExplicitThinkingEnablesManagedSupport(t *testing.T) { |
| 55 | + modelID := "compat-thinking-" + t.Name() |
| 56 | + authID := "auth-" + t.Name() |
| 57 | + service := &Service{ |
| 58 | + cfg: &config.Config{ |
| 59 | + OpenAICompatibility: []config.OpenAICompatibility{{ |
| 60 | + Name: "compat-thinking", |
| 61 | + Models: []config.OpenAICompatibilityModel{{ |
| 62 | + Name: "upstream-thinking", |
| 63 | + Alias: modelID, |
| 64 | + Thinking: ®istry.ThinkingSupport{Levels: []string{"low", "medium", "high"}}, |
| 65 | + }}, |
| 66 | + }}, |
| 67 | + }, |
| 68 | + } |
| 69 | + auth := &coreauth.Auth{ |
| 70 | + ID: authID, |
| 71 | + Provider: "openai-compatibility", |
| 72 | + Status: coreauth.StatusActive, |
| 73 | + Attributes: map[string]string{ |
| 74 | + "compat_name": "compat-thinking", |
| 75 | + }, |
| 76 | + } |
| 77 | + |
| 78 | + reg := GlobalModelRegistry() |
| 79 | + reg.UnregisterClient(auth.ID) |
| 80 | + t.Cleanup(func() { |
| 81 | + reg.UnregisterClient(auth.ID) |
| 82 | + }) |
| 83 | + |
| 84 | + service.registerModelsForAuth(auth) |
| 85 | + |
| 86 | + got := registry.LookupModelInfo(modelID, "compat-thinking") |
| 87 | + if got == nil { |
| 88 | + t.Fatalf("expected model %q to be registered", modelID) |
| 89 | + } |
| 90 | + if got.UserDefined { |
| 91 | + t.Fatalf("expected model %q to use managed thinking when explicitly configured", modelID) |
| 92 | + } |
| 93 | + if got.Thinking == nil { |
| 94 | + t.Fatalf("expected model %q to expose configured thinking support", modelID) |
| 95 | + } |
| 96 | + if len(got.Thinking.Levels) != 3 || got.Thinking.Levels[0] != "low" || got.Thinking.Levels[1] != "medium" || got.Thinking.Levels[2] != "high" { |
| 97 | + t.Fatalf("unexpected thinking levels: %+v", got.Thinking) |
| 98 | + } |
| 99 | +} |
0 commit comments