Files
sub2api/backend/internal/pkg/apicompat/responses_server_side_search_test.go
T
Anankke 70ad8365d9 fix(grok): keep xAI server-side search calls out of tool calls
On xAI upstreams a custom_tool_call whose call_id starts with xs_ or as_ is an xAI server-side search call, as the xAI tool usage docs define the prefixes.
The Messages and Chat Completions stream converters and the buffered accumulator no longer return such items as tool_use or tool calls, and stop_reason and finish_reason follow the remaining content.
Grok SearchCount counts each such item once; client custom tools and non-xAI upstreams are unchanged.
2026-11-16 00:40:53 -08:00

31 lines
930 B
Go

package apicompat
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestIsServerSideSearchCall(t *testing.T) {
tests := []struct {
name string
itemType string
callID string
want bool
}{
{"x search", "custom_tool_call", "xs_123", true},
{"attachment search", "custom_tool_call", "as_456", true},
{"padded call id is not a prefix match", "custom_tool_call", " xs_123", false},
{"client custom tool", "custom_tool_call", "call_9", false},
{"prefix is not a substring", "custom_tool_call", "call_xs_9", false},
{"no call id", "custom_tool_call", "", false},
{"function call keeps its client meaning", "function_call", "xs_123", false},
{"other server-side item types are separate items", "x_search_call", "xs_123", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
require.Equal(t, tt.want, IsServerSideSearchCall(tt.itemType, tt.callID))
})
}
}