返回 DeepSeek-Reasonix
reasoning_gateway_test.go
根目录 / internal / provider / openai / reasoning_gateway_test.go
1 package openai
2
3 import (
4 "encoding/json"
5 "strings"
6 "testing"
7
8 "reasonix/internal/provider"
9 )
10
11 // A generic gateway explicitly configured with thinking=enabled inherits the
12 // DeepSeek reasoning replay contract for every reasoning-carrying turn.
13 func TestBuildRequestThinkingEnabledGatewayRoundTripsAllReasoning(t *testing.T) {
14 p, err := New(provider.Config{
15 Name: "custom", BaseURL: "https://gateway.example/v1", Model: "ds4-flash", APIKey: "k",
16 Extra: map[string]any{"thinking": "enabled"},
17 })
18 if err != nil {
19 t.Fatal(err)
20 }
21 if !provider.RequiresToolCallReasoning(p) || !provider.AllowsEmptyReasoningFallback(p) {
22 t.Fatal("thinking-enabled gateway must use DeepSeek tool reasoning replay")
23 }
24 req := p.(*client).buildRequest(provider.Request{Messages: []provider.Message{
25 {Role: provider.RoleAssistant, ToolCalls: []provider.ToolCall{{ID: "c1", Name: "read_file", Arguments: `{"path":"main.go"}`}}},
26 {Role: provider.RoleTool, ToolCallID: "c1", Name: "read_file", Content: "package main"},
27 {Role: provider.RoleAssistant, ReasoningContent: "read first", ToolCalls: []provider.ToolCall{{ID: "c2", Name: "read_file", Arguments: `{"path":"go.mod"}`}}},
28 {Role: provider.RoleTool, ToolCallID: "c2", Name: "read_file", Content: "module demo"},
29 {Role: provider.RoleAssistant, Content: "done", ReasoningContent: "do not replay"},
30 }})
31 if got := req.Messages[0].ReasoningContent; got == nil || *got != "" {
32 t.Fatalf("empty fallback = %v", got)
33 }
34 if got := req.Messages[2].ReasoningContent; got == nil || *got != "read first" {
35 t.Fatalf("captured replay = %v", got)
36 }
37 body, err := json.Marshal(req.Messages)
38 if err != nil {
39 t.Fatal(err)
40 }
41 if got := req.Messages[4].ReasoningContent; got == nil || *got != "do not replay" {
42 t.Fatalf("plain assistant reasoning = %v, want it replayed", got)
43 }
44 if !strings.Contains(string(body), "do not replay") {
45 t.Fatalf("plain assistant reasoning missing from wire body: %s", body)
46 }
47 }
48
48 lines GO