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

Function TestChatMessageWithFiles

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

Source from the content-addressed store, hash-verified

7188}
7189
7190func TestChatMessageWithFiles(t *testing.T) {
7191 t.Parallel()
7192
7193 t.Run("FileOnly", func(t *testing.T) {
7194 t.Parallel()
7195
7196 ctx := testutil.Context(t, testutil.WaitLong)
7197 client := newChatClient(t)
7198 firstUser := coderdtest.CreateFirstUser(t, client.Client)
7199 _ = createChatModelConfig(t, client)
7200
7201 // Upload a file.
7202 pngData := append([]byte{0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}, make([]byte, 64)...)
7203 uploadResp, err := client.UploadChatFile(ctx, firstUser.OrganizationID, "image/png", "test.png", bytes.NewReader(pngData))
7204 require.NoError(t, err)
7205
7206 // Create a chat with text first.
7207 chat, err := client.CreateChat(ctx, codersdk.CreateChatRequest{
7208 OrganizationID: firstUser.OrganizationID,
7209 Content: []codersdk.ChatInputPart{
7210 {
7211 Type: codersdk.ChatInputPartTypeText,
7212 Text: "initial message",
7213 },
7214 },
7215 })
7216 require.NoError(t, err)
7217
7218 // Send a file-only message (no text).
7219 resp, err := client.CreateChatMessage(ctx, chat.ID, codersdk.CreateChatMessageRequest{
7220 Content: []codersdk.ChatInputPart{
7221 {
7222 Type: codersdk.ChatInputPartTypeFile,
7223 FileID: uploadResp.ID,
7224 },
7225 },
7226 })
7227 require.NoError(t, err)
7228
7229 // Verify the message was accepted.
7230 if resp.Queued {
7231 require.NotNil(t, resp.QueuedMessage)
7232 } else {
7233 require.NotNil(t, resp.Message)
7234 require.Equal(t, codersdk.ChatMessageRoleUser, resp.Message.Role)
7235 }
7236 })
7237
7238 t.Run("TextAndFile", func(t *testing.T) {
7239 t.Parallel()
7240
7241 ctx := testutil.Context(t, testutil.WaitLong)
7242 client := newChatClient(t)
7243 firstUser := coderdtest.CreateFirstUser(t, client.Client)
7244 _ = createChatModelConfig(t, client)
7245
7246 // Upload a file.
7247 pngData := append([]byte{0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}, make([]byte, 64)...)

Callers

nothing calls this directly

Calls 15

ContextFunction · 0.92
CreateFirstUserFunction · 0.92
requireSDKErrorFunction · 0.85
UploadChatFileMethod · 0.80
GetChatMessagesMethod · 0.80
GetChatMethod · 0.80
NotEmptyMethod · 0.80
newChatClientFunction · 0.70
createChatModelConfigFunction · 0.70
RunMethod · 0.65
CreateChatMethod · 0.65
CreateChatMessageMethod · 0.65

Tested by

no test coverage detected