test(cast): add new test for dropping multiple nil function call tool calls

- Introduced a new test case to verify that multiple nil FunctionCall tool calls are correctly removed from the message content, ensuring only relevant text parts are retained.
- Removed the previous test file `newbodypair_reg_test.go` as its functionality is now covered in the updated test suite.
This commit is contained in:
Dmitry Ng
2026-08-03 17:23:23 +03:00
parent b8c1b7d9a6
commit 21338d858f
2 changed files with 20 additions and 28 deletions

View File

@@ -3213,3 +3213,23 @@ func TestSanitizeToolCallArguments(t *testing.T) {
})
}
}
func TestNewBodyPair_DropsMultipleNilFunctionCallToolCalls(t *testing.T) {
aiMsg := &llms.MessageContent{
Role: llms.ChatMessageTypeAI,
Parts: []llms.ContentPart{
llms.ToolCall{ID: "a", Type: "function", FunctionCall: nil},
llms.ToolCall{ID: "b", Type: "function", FunctionCall: nil},
llms.TextContent{Text: "keep me"},
},
}
NewBodyPair(aiMsg, nil)
assert.Len(t, aiMsg.Parts, 1, "both nil-FunctionCall tool calls should be removed, text kept")
if assert.Len(t, aiMsg.Parts, 1) {
txt, ok := aiMsg.Parts[0].(llms.TextContent)
assert.True(t, ok, "surviving part should be the TextContent, got %T", aiMsg.Parts[0])
assert.Equal(t, "keep me", txt.Text)
}
}

View File

@@ -1,28 +0,0 @@
package cast
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/vxcontrol/langchaingo/llms"
)
func TestNewBodyPair_DropsMultipleNilFunctionCallToolCalls(t *testing.T) {
aiMsg := &llms.MessageContent{
Role: llms.ChatMessageTypeAI,
Parts: []llms.ContentPart{
llms.ToolCall{ID: "a", Type: "function", FunctionCall: nil},
llms.ToolCall{ID: "b", Type: "function", FunctionCall: nil},
llms.TextContent{Text: "keep me"},
},
}
NewBodyPair(aiMsg, nil)
assert.Len(t, aiMsg.Parts, 1, "both nil-FunctionCall tool calls should be removed, text kept")
if assert.Len(t, aiMsg.Parts, 1) {
txt, ok := aiMsg.Parts[0].(llms.TextContent)
assert.True(t, ok, "surviving part should be the TextContent, got %T", aiMsg.Parts[0])
assert.Equal(t, "keep me", txt.Text)
}
}