MCPcopy Create free account
hub / github.com/coder/coder / TestSubmitToolResultsConcurrency

Function TestSubmitToolResultsConcurrency

coderd/x/chatd/chatd_test.go:4729–4885  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

4727}
4728
4729func TestSubmitToolResultsConcurrency(t *testing.T) {
4730 t.Parallel()
4731
4732 db, ps := dbtestutil.NewDB(t)
4733 ctx := testutil.Context(t, testutil.WaitLong)
4734
4735 // The mock LLM returns a dynamic tool call on the first streaming
4736 // request, then a plain text reply on the second.
4737 var streamedCallCount atomic.Int32
4738 openAIURL := chattest.NewOpenAI(t, func(req *chattest.OpenAIRequest) chattest.OpenAIResponse {
4739 if !req.Stream {
4740 return chattest.OpenAINonStreamingResponse("Concurrency test")
4741 }
4742 if streamedCallCount.Add(1) == 1 {
4743 return chattest.OpenAIStreamingResponse(
4744 chattest.OpenAIToolCallChunk(
4745 "my_dynamic_tool",
4746 `{"input":"hello"}`,
4747 ),
4748 )
4749 }
4750 return chattest.OpenAIStreamingResponse(
4751 chattest.OpenAITextChunks("Done.")...,
4752 )
4753 })
4754
4755 user, org, model := seedChatDependenciesWithProvider(t, db, "openai-compat", openAIURL)
4756 server := newActiveTestServer(t, db, ps)
4757
4758 // Create a chat with a dynamic tool.
4759 dynamicToolsJSON, err := json.Marshal([]mcpgo.Tool{{
4760 Name: "my_dynamic_tool",
4761 Description: "A test dynamic tool.",
4762 InputSchema: mcpgo.ToolInputSchema{
4763 Type: "object",
4764 Properties: map[string]any{
4765 "input": map[string]any{"type": "string"},
4766 },
4767 Required: []string{"input"},
4768 },
4769 }})
4770 require.NoError(t, err)
4771
4772 chat, err := server.CreateChat(ctx, chatd.CreateOptions{
4773 OrganizationID: org.ID,
4774 OwnerID: user.ID,
4775 Title: "concurrency-tool-results",
4776 ModelConfigID: model.ID,
4777 InitialUserContent: []codersdk.ChatMessagePart{
4778 codersdk.ChatMessageText("Please call the dynamic tool."),
4779 },
4780 DynamicTools: dynamicToolsJSON,
4781 })
4782 require.NoError(t, err)
4783
4784 // Wait for the chat to reach requires_action status.
4785 var chatResult database.Chat
4786 require.Eventually(t, func() bool {

Callers

nothing calls this directly

Calls 15

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

Tested by

no test coverage detected