返回 DeepSeek-Reasonix
tool_execution_cache_test.go
根目录 / internal / provider / tool_execution_cache_test.go
1 package provider
2
3 import (
4 "encoding/json"
5 "strings"
6 "testing"
7 )
8
9 // TestToolExecutionDoesNotAffectProviderVisibleBytes proves that attaching
10 // local shell execution metadata to a tool result leaves ModelMessages and
11 // therefore provider-visible conversation bytes unchanged.
12 func TestToolExecutionDoesNotAffectProviderVisibleBytes(t *testing.T) {
13 base := []Message{
14 {Role: RoleUser, Content: "run tests"},
15 {Role: RoleAssistant, Content: "", ToolCalls: []ToolCall{{ID: "c1", Name: "bash", Arguments: `{"command":"go test ./..."}`}}},
16 {Role: RoleTool, ToolCallID: "c1", Name: "bash", Content: "ok"},
17 }
18 code := 0
19 withMeta := append([]Message(nil), base...)
20 withMeta[2].ToolExecution = &ToolExecution{
21 Kind: "shell", Shell: "bash", State: "completed", ExitCode: &code,
22 MutationRisk: "none", Verification: "passed", OutputTail: "noise",
23 }
24
25 visBase, err := json.Marshal(ModelMessages(base))
26 if err != nil {
27 t.Fatal(err)
28 }
29 visMeta, err := json.Marshal(ModelMessages(withMeta))
30 if err != nil {
31 t.Fatal(err)
32 }
33 if string(visBase) != string(visMeta) {
34 t.Fatalf("provider-visible messages diverged after local execution metadata\nbase: %s\nmeta: %s", visBase, visMeta)
35 }
36 if strings.Contains(string(visMeta), "tool_execution") || strings.Contains(string(visMeta), "outputTail") {
37 t.Fatalf("local execution field leaked into provider-visible JSON: %s", visMeta)
38 }
39 }
40
40 lines GO