|
| 1 | +package executor |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/router-for-me/CLIProxyAPI/v6/internal/thinking" |
| 7 | +) |
| 8 | + |
| 9 | +func TestIFlowExecutorParseSuffix(t *testing.T) { |
| 10 | + tests := []struct { |
| 11 | + name string |
| 12 | + model string |
| 13 | + wantBase string |
| 14 | + wantLevel string |
| 15 | + }{ |
| 16 | + {"no suffix", "glm-4", "glm-4", ""}, |
| 17 | + {"glm with suffix", "glm-4.1-flash(high)", "glm-4.1-flash", "high"}, |
| 18 | + {"minimax no suffix", "minimax-m2", "minimax-m2", ""}, |
| 19 | + {"minimax with suffix", "minimax-m2.1(medium)", "minimax-m2.1", "medium"}, |
| 20 | + } |
| 21 | + |
| 22 | + for _, tt := range tests { |
| 23 | + t.Run(tt.name, func(t *testing.T) { |
| 24 | + result := thinking.ParseSuffix(tt.model) |
| 25 | + if result.ModelName != tt.wantBase { |
| 26 | + t.Errorf("ParseSuffix(%q).ModelName = %q, want %q", tt.model, result.ModelName, tt.wantBase) |
| 27 | + } |
| 28 | + }) |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +func TestPreserveReasoningContentInMessages(t *testing.T) { |
| 33 | + tests := []struct { |
| 34 | + name string |
| 35 | + input []byte |
| 36 | + want []byte // nil means output should equal input |
| 37 | + }{ |
| 38 | + { |
| 39 | + "non-glm model passthrough", |
| 40 | + []byte(`{"model":"gpt-4","messages":[]}`), |
| 41 | + nil, |
| 42 | + }, |
| 43 | + { |
| 44 | + "glm model with empty messages", |
| 45 | + []byte(`{"model":"glm-4","messages":[]}`), |
| 46 | + nil, |
| 47 | + }, |
| 48 | + { |
| 49 | + "glm model preserves existing reasoning_content", |
| 50 | + []byte(`{"model":"glm-4","messages":[{"role":"assistant","content":"hi","reasoning_content":"thinking..."}]}`), |
| 51 | + nil, |
| 52 | + }, |
| 53 | + } |
| 54 | + |
| 55 | + for _, tt := range tests { |
| 56 | + t.Run(tt.name, func(t *testing.T) { |
| 57 | + got := preserveReasoningContentInMessages(tt.input) |
| 58 | + want := tt.want |
| 59 | + if want == nil { |
| 60 | + want = tt.input |
| 61 | + } |
| 62 | + if string(got) != string(want) { |
| 63 | + t.Errorf("preserveReasoningContentInMessages() = %s, want %s", got, want) |
| 64 | + } |
| 65 | + }) |
| 66 | + } |
| 67 | +} |
0 commit comments