(t *testing.T)
| 667 | } |
| 668 | |
| 669 | func 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. |
nothing calls this directly
no test coverage detected