(t *testing.T)
| 6323 | } |
| 6324 | |
| 6325 | func TestInterruptChatDoesNotSendWebPushNotification(t *testing.T) { |
| 6326 | t.Parallel() |
| 6327 | |
| 6328 | db, ps := dbtestutil.NewDB(t) |
| 6329 | ctx := testutil.Context(t, testutil.WaitLong) |
| 6330 | |
| 6331 | // Set up a mock OpenAI that blocks until the request context is |
| 6332 | // canceled (i.e. until the chat is interrupted). |
| 6333 | streamStarted := make(chan struct{}) |
| 6334 | openAIURL := chattest.NewOpenAI(t, func(req *chattest.OpenAIRequest) chattest.OpenAIResponse { |
| 6335 | if !req.Stream { |
| 6336 | return chattest.OpenAINonStreamingResponse("title") |
| 6337 | } |
| 6338 | chunks := make(chan chattest.OpenAIChunk, 1) |
| 6339 | go func() { |
| 6340 | defer close(chunks) |
| 6341 | chunks <- chattest.OpenAITextChunks("partial")[0] |
| 6342 | select { |
| 6343 | case <-streamStarted: |
| 6344 | default: |
| 6345 | close(streamStarted) |
| 6346 | } |
| 6347 | // Block until the chat context is canceled by the interrupt. |
| 6348 | <-req.Context().Done() |
| 6349 | }() |
| 6350 | return chattest.OpenAIResponse{StreamingChunks: chunks} |
| 6351 | }) |
| 6352 | |
| 6353 | // Mock webpush dispatcher that records calls. |
| 6354 | mockPush := &mockWebpushDispatcher{} |
| 6355 | |
| 6356 | logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}) |
| 6357 | server := chatd.New(chatd.Config{ |
| 6358 | Logger: logger, |
| 6359 | Database: db, |
| 6360 | ReplicaID: uuid.New(), |
| 6361 | Pubsub: ps, |
| 6362 | PendingChatAcquireInterval: 10 * time.Millisecond, |
| 6363 | InFlightChatStaleAfter: testutil.WaitSuperLong, |
| 6364 | WebpushDispatcher: mockPush, |
| 6365 | }) |
| 6366 | t.Cleanup(func() { |
| 6367 | require.NoError(t, server.Close()) |
| 6368 | }) |
| 6369 | |
| 6370 | user, org, model := seedChatDependencies(t, db) |
| 6371 | setOpenAIProviderBaseURL(ctx, t, db, openAIURL) |
| 6372 | |
| 6373 | chat, err := server.CreateChat(ctx, chatd.CreateOptions{ |
| 6374 | OrganizationID: org.ID, |
| 6375 | OwnerID: user.ID, |
| 6376 | Title: "interrupt-no-push", |
| 6377 | ModelConfigID: model.ID, |
| 6378 | InitialUserContent: []codersdk.ChatMessagePart{codersdk.ChatMessageText("hello")}, |
| 6379 | }) |
| 6380 | require.NoError(t, err) |
| 6381 | seedLastTurnSummary(ctx, t, db, chat, "previous summary") |
| 6382 |
nothing calls this directly
no test coverage detected