MCPcopy Index your code
hub / github.com/coder/coder / TestPromoteQueuedWhileRequiresActionMixedTools

Function TestPromoteQueuedWhileRequiresActionMixedTools

coderd/x/chatd/chatd_test.go:9362–9561  ·  view source on GitHub ↗

TestPromoteQueuedWhileRequiresActionMixedTools guards against duplicating already-resolved built-in tool results: synthetic results must be scoped to dynamic tool names only.

(t *testing.T)

Source from the content-addressed store, hash-verified

9360// duplicating already-resolved built-in tool results: synthetic
9361// results must be scoped to dynamic tool names only.
9362func TestPromoteQueuedWhileRequiresActionMixedTools(t *testing.T) {
9363 t.Parallel()
9364
9365 db, ps := dbtestutil.NewDB(t)
9366 ctx := testutil.Context(t, testutil.WaitLong)
9367
9368 var streamedCallCount atomic.Int32
9369 openAIURL := chattest.NewOpenAI(t, func(req *chattest.OpenAIRequest) chattest.OpenAIResponse {
9370 if !req.Stream {
9371 return chattest.OpenAINonStreamingResponse("mixed-tools-promote")
9372 }
9373 if streamedCallCount.Add(1) == 1 {
9374 builtinChunk := chattest.OpenAIToolCallChunk(
9375 "read_file",
9376 `{"path":"/tmp/test.txt"}`,
9377 )
9378 dynamicChunk := chattest.OpenAIToolCallChunk(
9379 "my_dynamic_tool",
9380 `{"input":"hello world"}`,
9381 )
9382 mergedChunk := builtinChunk
9383 dynCall := dynamicChunk.Choices[0].ToolCalls[0]
9384 dynCall.Index = 1
9385 mergedChunk.Choices[0].ToolCalls = append(
9386 mergedChunk.Choices[0].ToolCalls,
9387 dynCall,
9388 )
9389 return chattest.OpenAIStreamingResponse(mergedChunk)
9390 }
9391 return chattest.OpenAIStreamingResponse(
9392 chattest.OpenAITextChunks("Resumed after mixed-tool promotion.")...,
9393 )
9394 })
9395
9396 user, org, model := seedChatDependenciesWithProvider(t, db, "openai-compat", openAIURL)
9397 server := newActiveTestServer(t, db, ps)
9398
9399 dynamicToolsJSON, err := json.Marshal([]mcpgo.Tool{{
9400 Name: "my_dynamic_tool",
9401 Description: "A test dynamic tool.",
9402 InputSchema: mcpgo.ToolInputSchema{
9403 Type: "object",
9404 Properties: map[string]any{
9405 "input": map[string]any{"type": "string"},
9406 },
9407 Required: []string{"input"},
9408 },
9409 }})
9410 require.NoError(t, err)
9411
9412 chat, err := server.CreateChat(ctx, chatd.CreateOptions{
9413 OrganizationID: org.ID,
9414 OwnerID: user.ID,
9415 Title: "promote-while-requires-action-mixed",
9416 ModelConfigID: model.ID,
9417 InitialUserContent: []codersdk.ChatMessagePart{
9418 codersdk.ChatMessageText("Call both tools."),
9419 },

Callers

nothing calls this directly

Calls 15

NewDBFunction · 0.92
ContextFunction · 0.92
NewOpenAIFunction · 0.92
OpenAIToolCallChunkFunction · 0.92
OpenAIStreamingResponseFunction · 0.92
OpenAITextChunksFunction · 0.92
ChatMessageTextFunction · 0.92
EventuallyFunction · 0.92
ParseContentFunction · 0.92
newActiveTestServerFunction · 0.85

Tested by

no test coverage detected