(t *testing.T)
| 6646 | } |
| 6647 | |
| 6648 | func TestSuccessfulChatSendsWebPushWithSummary(t *testing.T) { |
| 6649 | t.Parallel() |
| 6650 | |
| 6651 | db, ps := dbtestutil.NewDB(t) |
| 6652 | ctx := testutil.Context(t, testutil.WaitLong) |
| 6653 | |
| 6654 | const assistantText = "I have completed the task successfully and all tests are passing now." |
| 6655 | const summaryText = "Finished unit tests" |
| 6656 | |
| 6657 | var nonStreamingRequests atomic.Int32 |
| 6658 | openAIURL := chattest.NewOpenAI(t, func(req *chattest.OpenAIRequest) chattest.OpenAIResponse { |
| 6659 | if !req.Stream { |
| 6660 | if strings.Contains(string(req.RawBody), "propose_turn_status_label") { |
| 6661 | nonStreamingRequests.Add(1) |
| 6662 | return chattest.OpenAINonStreamingResponse(fmt.Sprintf(`{"label":%q}`, summaryText)) |
| 6663 | } |
| 6664 | return chattest.OpenAINonStreamingResponse(`{"title":"Summary push test"}`) |
| 6665 | } |
| 6666 | return chattest.OpenAIStreamingResponse( |
| 6667 | chattest.OpenAITextChunks(assistantText)..., |
| 6668 | ) |
| 6669 | }) |
| 6670 | |
| 6671 | mockPush := &mockWebpushDispatcher{} |
| 6672 | |
| 6673 | logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}) |
| 6674 | server := chatd.New(chatd.Config{ |
| 6675 | Logger: logger, |
| 6676 | Database: db, |
| 6677 | ReplicaID: uuid.New(), |
| 6678 | Pubsub: ps, |
| 6679 | PendingChatAcquireInterval: 10 * time.Millisecond, |
| 6680 | InFlightChatStaleAfter: testutil.WaitSuperLong, |
| 6681 | WebpushDispatcher: mockPush, |
| 6682 | }) |
| 6683 | server.Start() |
| 6684 | t.Cleanup(func() { |
| 6685 | require.NoError(t, server.Close()) |
| 6686 | }) |
| 6687 | |
| 6688 | user, org, model := seedChatDependencies(t, db) |
| 6689 | setOpenAIProviderBaseURL(ctx, t, db, openAIURL) |
| 6690 | |
| 6691 | chat, err := server.CreateChat(ctx, chatd.CreateOptions{ |
| 6692 | OrganizationID: org.ID, |
| 6693 | OwnerID: user.ID, |
| 6694 | Title: "summary-push-test", |
| 6695 | ModelConfigID: model.ID, |
| 6696 | InitialUserContent: []codersdk.ChatMessagePart{codersdk.ChatMessageText("do the thing")}, |
| 6697 | }) |
| 6698 | require.NoError(t, err) |
| 6699 | |
| 6700 | // The push notification is dispatched asynchronously after the |
| 6701 | // chat finishes, so we poll for it rather than checking |
| 6702 | // immediately after the status transitions to waiting. |
| 6703 | var fromDB database.Chat |
| 6704 | testutil.Eventually(ctx, t, func(ctx context.Context) bool { |
| 6705 | var dbErr error |
nothing calls this directly
no test coverage detected