(t *testing.T)
| 2349 | } |
| 2350 | |
| 2351 | func TestCreateChatInsertsWorkspaceAwarenessMessage(t *testing.T) { |
| 2352 | t.Parallel() |
| 2353 | |
| 2354 | t.Run("WithWorkspace", func(t *testing.T) { |
| 2355 | t.Parallel() |
| 2356 | |
| 2357 | db, ps := dbtestutil.NewDB(t) |
| 2358 | server := newTestServer(t, db, ps, uuid.New()) |
| 2359 | |
| 2360 | ctx := testutil.Context(t, testutil.WaitLong) |
| 2361 | user, org, model := seedChatDependencies(t, db) |
| 2362 | |
| 2363 | tv := dbgen.TemplateVersion(t, db, database.TemplateVersion{ |
| 2364 | OrganizationID: org.ID, |
| 2365 | CreatedBy: user.ID, |
| 2366 | }) |
| 2367 | tpl := dbgen.Template(t, db, database.Template{ |
| 2368 | CreatedBy: user.ID, |
| 2369 | OrganizationID: org.ID, |
| 2370 | ActiveVersionID: tv.ID, |
| 2371 | }) |
| 2372 | workspace := dbgen.Workspace(t, db, database.WorkspaceTable{ |
| 2373 | OwnerID: user.ID, |
| 2374 | OrganizationID: org.ID, |
| 2375 | TemplateID: tpl.ID, |
| 2376 | }) |
| 2377 | |
| 2378 | chat, err := server.CreateChat(ctx, chatd.CreateOptions{ |
| 2379 | OrganizationID: org.ID, |
| 2380 | OwnerID: user.ID, |
| 2381 | WorkspaceID: uuid.NullUUID{UUID: workspace.ID, Valid: true}, |
| 2382 | Title: "test-with-workspace", |
| 2383 | ModelConfigID: model.ID, |
| 2384 | InitialUserContent: []codersdk.ChatMessagePart{codersdk.ChatMessageText("hello")}, |
| 2385 | }) |
| 2386 | require.NoError(t, err) |
| 2387 | |
| 2388 | messages, err := db.GetChatMessagesForPromptByChatID(ctx, chat.ID) |
| 2389 | require.NoError(t, err) |
| 2390 | |
| 2391 | var workspaceMsg *database.ChatMessage |
| 2392 | for _, msg := range messages { |
| 2393 | if msg.Role == database.ChatMessageRoleSystem { |
| 2394 | content := string(msg.Content.RawMessage) |
| 2395 | if strings.Contains(content, "attached to a workspace") { |
| 2396 | workspaceMsg = &msg |
| 2397 | break |
| 2398 | } |
| 2399 | } |
| 2400 | } |
| 2401 | require.NotNil(t, workspaceMsg, "workspace awareness system message should exist") |
| 2402 | require.Equal(t, database.ChatMessageRoleSystem, workspaceMsg.Role) |
| 2403 | require.Equal(t, database.ChatMessageVisibilityModel, workspaceMsg.Visibility) |
| 2404 | }) |
| 2405 | |
| 2406 | t.Run("WithoutWorkspace", func(t *testing.T) { |
| 2407 | t.Parallel() |
| 2408 |
nothing calls this directly
no test coverage detected