(t *testing.T)
| 399 | } |
| 400 | |
| 401 | func TestSubscribeRelaySnapshotDelivered(t *testing.T) { |
| 402 | t.Parallel() |
| 403 | |
| 404 | db, ps := dbtestutil.NewDB(t) |
| 405 | workerID := uuid.New() |
| 406 | subscriberID := uuid.New() |
| 407 | |
| 408 | provider := func(_ context.Context, _ uuid.UUID, _ uuid.UUID, _ http.Header) ( |
| 409 | []codersdk.ChatStreamEvent, <-chan codersdk.ChatStreamEvent, func(), error, |
| 410 | ) { |
| 411 | // Return a non-empty snapshot with two parts. |
| 412 | snapshot := []codersdk.ChatStreamEvent{ |
| 413 | { |
| 414 | Type: codersdk.ChatStreamEventTypeMessagePart, |
| 415 | MessagePart: &codersdk.ChatStreamMessagePart{ |
| 416 | Role: "assistant", |
| 417 | Part: codersdk.ChatMessageText("snap-one"), |
| 418 | }, |
| 419 | }, |
| 420 | { |
| 421 | Type: codersdk.ChatStreamEventTypeMessagePart, |
| 422 | MessagePart: &codersdk.ChatStreamMessagePart{ |
| 423 | Role: "assistant", |
| 424 | Part: codersdk.ChatMessageText("snap-two"), |
| 425 | }, |
| 426 | }, |
| 427 | } |
| 428 | ch := make(chan codersdk.ChatStreamEvent, 10) |
| 429 | // Also send a live part after the snapshot. |
| 430 | ch <- codersdk.ChatStreamEvent{ |
| 431 | Type: codersdk.ChatStreamEventTypeMessagePart, |
| 432 | MessagePart: &codersdk.ChatStreamMessagePart{ |
| 433 | Role: "assistant", |
| 434 | Part: codersdk.ChatMessageText("live-part"), |
| 435 | }, |
| 436 | } |
| 437 | return snapshot, ch, func() {}, nil |
| 438 | } |
| 439 | |
| 440 | subscriber := newTestServer(t, db, ps, subscriberID, provider, nil) |
| 441 | |
| 442 | ctx := testutil.Context(t, testutil.WaitLong) |
| 443 | user, org, model := seedChatDependencies(t, db) |
| 444 | |
| 445 | chat := seedRemoteRunningChat(ctx, t, db, org.ID, user, model, workerID, "relay-snapshot") |
| 446 | staleChat := chat |
| 447 | staleChat.Status = database.ChatStatusWaiting |
| 448 | staleChat.WorkerID = uuid.NullUUID{} |
| 449 | staleChat.StartedAt = sql.NullTime{} |
| 450 | staleChat.HeartbeatAt = sql.NullTime{} |
| 451 | |
| 452 | initialSnapshot, events, cancel, ok := subscriber.SubscribeAuthorized(ctx, staleChat, nil, 0) |
| 453 | require.True(t, ok) |
| 454 | t.Cleanup(cancel) |
| 455 | |
| 456 | // The relay snapshot parts are forwarded through the events |
| 457 | // channel by the enterprise SubscribeFn. Collect them along |
| 458 | // with the live part. |
nothing calls this directly
no test coverage detected