MCPcopy Index your code
hub / github.com/coder/coder / TestAIBridgeListSessions

Function TestAIBridgeListSessions

enterprise/coderd/aibridge_test.go:669–1737  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

667}
668
669func TestAIBridgeListSessions(t *testing.T) {
670 t.Parallel()
671
672 t.Run("EmptyDB", func(t *testing.T) {
673 t.Parallel()
674 client, _ := coderdenttest.New(t, aibridgeOpts(t))
675 ctx := testutil.Context(t, testutil.WaitLong)
676 //nolint:gocritic // Owner role is irrelevant here.
677 res, err := client.AIBridgeListSessions(ctx, codersdk.AIBridgeListSessionsFilter{})
678 require.NoError(t, err)
679 require.Empty(t, res.Sessions)
680 require.EqualValues(t, 0, res.Count)
681 })
682
683 t.Run("OK", func(t *testing.T) {
684 t.Parallel()
685 client, db, firstUser := coderdenttest.NewWithDatabase(t, aibridgeOpts(t))
686 ctx := testutil.Context(t, testutil.WaitLong)
687
688 now := dbtime.Now()
689
690 // Session 1: Two interceptions sharing client_session_id "session-A".
691 s1i1EndedAt := now.Add(time.Minute)
692 s1i1 := dbgen.AIBridgeInterception(t, db, database.InsertAIBridgeInterceptionParams{
693 InitiatorID: firstUser.UserID,
694 Provider: "anthropic",
695 Model: "claude-4",
696 StartedAt: now,
697 Client: sql.NullString{String: "claude-code", Valid: true},
698 ClientSessionID: sql.NullString{String: "session-A", Valid: true},
699 }, &s1i1EndedAt)
700 s1i2EndedAt := now.Add(2 * time.Minute)
701 dbgen.AIBridgeInterception(t, db, database.InsertAIBridgeInterceptionParams{
702 InitiatorID: firstUser.UserID,
703 Provider: "anthropic",
704 Model: "claude-4-haiku",
705 StartedAt: now.Add(time.Minute),
706 Client: sql.NullString{String: "claude-code", Valid: true},
707 ClientSessionID: sql.NullString{String: "session-A", Valid: true},
708 ThreadRootInterceptionID: uuid.NullUUID{UUID: s1i1.ID, Valid: true},
709 ThreadParentInterceptionID: uuid.NullUUID{UUID: s1i1.ID, Valid: true},
710 }, &s1i2EndedAt)
711
712 // Add token usages to session 1 interceptions.
713 dbgen.AIBridgeTokenUsage(t, db, database.InsertAIBridgeTokenUsageParams{
714 InterceptionID: s1i1.ID,
715 InputTokens: 100,
716 OutputTokens: 50,
717 CreatedAt: now,
718 })
719 dbgen.AIBridgeTokenUsage(t, db, database.InsertAIBridgeTokenUsageParams{
720 InterceptionID: s1i1.ID,
721 InputTokens: 200,
722 OutputTokens: 75,
723 CreatedAt: now.Add(time.Second),
724 })
725
726 // Add user prompts to session 1.

Callers

nothing calls this directly

Calls 15

StatusCodeMethod · 0.95
NewFunction · 0.92
ContextFunction · 0.92
NewWithDatabaseFunction · 0.92
NowFunction · 0.92
AIBridgeInterceptionFunction · 0.92
AIBridgeTokenUsageFunction · 0.92
AIBridgeUserPromptFunction · 0.92
CreateAnotherUserFunction · 0.92
RoleAuditorFunction · 0.92
aibridgeOptsFunction · 0.85
AIBridgeListSessionsMethod · 0.80

Tested by

no test coverage detected