MCPcopy Create free account
hub / github.com/coder/coder / TestSubscribeRelaySnapshotDelivered

Function TestSubscribeRelaySnapshotDelivered

enterprise/coderd/x/chatd/chatd_test.go:401–485  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

399}
400
401func 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.

Callers

nothing calls this directly

Calls 10

NewDBFunction · 0.92
ChatMessageTextFunction · 0.92
ContextFunction · 0.92
seedRemoteRunningChatFunction · 0.85
SubscribeAuthorizedMethod · 0.80
newTestServerFunction · 0.70
seedChatDependenciesFunction · 0.70
NewMethod · 0.65
CleanupMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected