MCPcopy Create free account
hub / github.com/coder/aibridge / TestInjectTools_ParallelToolCalls

Function TestInjectTools_ParallelToolCalls

intercept/messages/base_test.go:490–606  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

488}
489
490func TestInjectTools_ParallelToolCalls(t *testing.T) {
491 t.Parallel()
492
493 t.Run("does not modify tool choice when no tools to inject", func(t *testing.T) {
494 t.Parallel()
495
496 i := &interceptionBase{
497 reqPayload: mustMessagesPayload(t, `{"tool_choice":{"type":"auto"}}`),
498 mcpProxy: &mockServerProxier{tools: nil}, // No tools to inject.
499 logger: slog.Make(),
500 }
501
502 i.injectTools()
503
504 // Tool choice should remain unchanged - DisableParallelToolUse should not be set.
505 toolChoice := gjson.GetBytes(i.reqPayload, "tool_choice")
506 require.Equal(t, string(constant.ValueOf[constant.Auto]()), toolChoice.Get("type").String())
507 require.False(t, toolChoice.Get("disable_parallel_tool_use").Exists())
508 })
509
510 t.Run("disables parallel tool use for empty tool choice (default)", func(t *testing.T) {
511 t.Parallel()
512
513 i := &interceptionBase{
514 reqPayload: mustMessagesPayload(t, `{}`),
515 mcpProxy: &mockServerProxier{
516 tools: []*mcp.Tool{{ID: "test_tool", Name: "test", Description: "Test"}},
517 },
518 logger: slog.Make(),
519 }
520
521 i.injectTools()
522
523 toolChoice := gjson.GetBytes(i.reqPayload, "tool_choice")
524 require.Equal(t, string(constant.ValueOf[constant.Auto]()), toolChoice.Get("type").String())
525 require.True(t, toolChoice.Get("disable_parallel_tool_use").Exists())
526 require.True(t, toolChoice.Get("disable_parallel_tool_use").Bool())
527 })
528
529 t.Run("disables parallel tool use for explicit auto tool choice", func(t *testing.T) {
530 t.Parallel()
531
532 i := &interceptionBase{
533 reqPayload: mustMessagesPayload(t, `{"tool_choice":{"type":"auto"}}`),
534 mcpProxy: &mockServerProxier{
535 tools: []*mcp.Tool{{ID: "test_tool", Name: "test", Description: "Test"}},
536 },
537 logger: slog.Make(),
538 }
539
540 i.injectTools()
541
542 toolChoice := gjson.GetBytes(i.reqPayload, "tool_choice")
543 require.Equal(t, string(constant.ValueOf[constant.Auto]()), toolChoice.Get("type").String())
544 require.True(t, toolChoice.Get("disable_parallel_tool_use").Exists())
545 require.True(t, toolChoice.Get("disable_parallel_tool_use").Bool())
546 })
547

Callers

nothing calls this directly

Calls 3

injectToolsMethod · 0.95
mustMessagesPayloadFunction · 0.85
GetMethod · 0.80

Tested by

no test coverage detected