package modeladapter import ( "reflect" "testing" ) func TestSanitizeProviderMessagesMergesLegacyAssistantTextAndToolCallTurnsIdempotently(t *testing.T) { input := []Message{ { Role: "assistant", Content: "Now let me pass stream.Mode in service.go.", ReasoningContent: "I need to update service.go.", }, { Role: "assistant", Content: "", ReasoningContent: "I need to update service.go.", ToolCalls: []ToolCallDescriptor{ { ID: "call_1", Type: "function", Function: ToolCallFunctionShape{ Name: "PatchEdit", Arguments: `{"path":"/workspace/service.go"}`, }, }, }, }, { Role: "tool", Content: `{"success":{"path":"/workspace/service.go"}}`, ToolCallID: "call_1", Name: "PatchEdit", }, } first := sanitizeProviderMessages(input) if len(first) != 2 { t.Fatalf("message count = %d, want 2: %#v", len(first), first) } assistant := first[0] if assistant.Content != input[0].Content { t.Fatalf("assistant content = %q", assistant.Content) } if assistant.ReasoningContent != input[0].ReasoningContent { t.Fatalf("assistant reasoning = %q, want one copy of %q", assistant.ReasoningContent, input[0].ReasoningContent) } if len(assistant.ToolCalls) != 1 || assistant.ToolCalls[0].ID != "call_1" { t.Fatalf("assistant tool calls = %#v", assistant.ToolCalls) } second := sanitizeProviderMessages(first) if !reflect.DeepEqual(second, first) { t.Fatalf("sanitizing normalized messages changed them:\nfirst: %#v\nsecond: %#v", first, second) } }