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

Function TestSubmitToolResults

coderd/exp_chats_test.go:13769–14102  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13767}
13768
13769func TestSubmitToolResults(t *testing.T) {
13770 t.Parallel()
13771
13772 // setupRequiresAction creates a chat via the DB with dynamic tools,
13773 // inserts an assistant message containing tool-call parts for each
13774 // given toolCallID, and sets the chat status to requires_action.
13775 // It returns the chat row so callers can exercise the endpoint.
13776 setupRequiresAction := func(
13777 ctx context.Context,
13778 t *testing.T,
13779 db database.Store,
13780 ownerID uuid.UUID,
13781 organizationID uuid.UUID,
13782 modelConfigID uuid.UUID,
13783 dynamicToolName string,
13784 toolCallIDs []string,
13785 ) database.Chat {
13786 t.Helper()
13787
13788 // Marshal dynamic tools into the chat row.
13789 dynamicTools := []mcp.Tool{{
13790 Name: dynamicToolName,
13791 Description: "a test dynamic tool",
13792 InputSchema: mcp.ToolInputSchema{Type: "object"},
13793 }}
13794 dtJSON, err := json.Marshal(dynamicTools)
13795 require.NoError(t, err)
13796
13797 chat := dbgen.Chat(t, db, database.Chat{
13798 OrganizationID: organizationID,
13799 OwnerID: ownerID,
13800 LastModelConfigID: modelConfigID,
13801 Title: "tool-results-test",
13802 DynamicTools: pqtype.NullRawMessage{RawMessage: dtJSON, Valid: true},
13803 })
13804
13805 // Build assistant message with tool-call parts.
13806 parts := make([]codersdk.ChatMessagePart, 0, len(toolCallIDs))
13807 for _, id := range toolCallIDs {
13808 parts = append(parts, codersdk.ChatMessagePart{
13809 Type: codersdk.ChatMessagePartTypeToolCall,
13810 ToolCallID: id,
13811 ToolName: dynamicToolName,
13812 Args: json.RawMessage(`{"key":"value"}`),
13813 })
13814 }
13815 content, err := chatprompt.MarshalParts(parts)
13816 require.NoError(t, err)
13817
13818 _ = dbgen.ChatMessage(t, db, database.ChatMessage{
13819 ChatID: chat.ID,
13820 ModelConfigID: uuid.NullUUID{UUID: modelConfigID, Valid: true},
13821 Role: database.ChatMessageRoleAssistant,
13822 Content: content,
13823 })
13824
13825 // Transition to requires_action.
13826 chat, err = db.UpdateChatStatus(dbauthz.AsSystemRestricted(ctx), database.UpdateChatStatusParams{

Callers

nothing calls this directly

Calls 15

SubmitToolResultsMethod · 0.95
ChatFunction · 0.92
MarshalPartsFunction · 0.92
ChatMessageFunction · 0.92
AsSystemRestrictedFunction · 0.92
ContextFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
ScopedRoleAgentsAccessFunction · 0.92
NewExperimentalClientFunction · 0.92
requireSDKErrorFunction · 0.85

Tested by

no test coverage detected