(t *testing.T)
| 12510 | } |
| 12511 | |
| 12512 | func TestChatDebugRuns(t *testing.T) { |
| 12513 | t.Parallel() |
| 12514 | |
| 12515 | t.Run("ListReturnsRunsNewestFirst", func(t *testing.T) { |
| 12516 | t.Parallel() |
| 12517 | |
| 12518 | ctx := testutil.Context(t, testutil.WaitLong) |
| 12519 | client, db := newChatClientWithDatabase(t) |
| 12520 | firstUser := coderdtest.CreateFirstUser(t, client.Client) |
| 12521 | modelConfig := createChatModelConfig(t, client) |
| 12522 | |
| 12523 | memberClientRaw, member := coderdtest.CreateAnotherUser(t, client.Client, firstUser.OrganizationID, rbac.ScopedRoleAgentsAccess(firstUser.OrganizationID)) |
| 12524 | memberClient := codersdk.NewExperimentalClient(memberClientRaw) |
| 12525 | |
| 12526 | chat := dbgen.Chat(t, db, database.Chat{ |
| 12527 | OrganizationID: firstUser.OrganizationID, |
| 12528 | OwnerID: member.ID, |
| 12529 | LastModelConfigID: modelConfig.ID, |
| 12530 | Title: "debug-runs-list", |
| 12531 | }) |
| 12532 | |
| 12533 | base := time.Now().UTC().Add(-time.Hour).Round(time.Second) |
| 12534 | older := seedChatDebugRun(ctx, t, db, chat.ID, base) |
| 12535 | newer := seedChatDebugRun(ctx, t, db, chat.ID, base.Add(10*time.Minute)) |
| 12536 | |
| 12537 | runs, err := memberClient.GetChatDebugRuns(ctx, chat.ID) |
| 12538 | require.NoError(t, err) |
| 12539 | require.Len(t, runs, 2) |
| 12540 | require.Equal(t, newer.ID, runs[0].ID, "newest run must come first") |
| 12541 | require.Equal(t, older.ID, runs[1].ID) |
| 12542 | require.Equal(t, codersdk.ChatDebugRunKindChatTurn, runs[0].Kind) |
| 12543 | require.Equal(t, codersdk.ChatDebugStatusInProgress, runs[0].Status) |
| 12544 | }) |
| 12545 | |
| 12546 | t.Run("ListCapsAt100", func(t *testing.T) { |
| 12547 | t.Parallel() |
| 12548 | |
| 12549 | ctx := testutil.Context(t, testutil.WaitLong) |
| 12550 | client, db := newChatClientWithDatabase(t) |
| 12551 | firstUser := coderdtest.CreateFirstUser(t, client.Client) |
| 12552 | modelConfig := createChatModelConfig(t, client) |
| 12553 | |
| 12554 | chat := dbgen.Chat(t, db, database.Chat{ |
| 12555 | OrganizationID: firstUser.OrganizationID, |
| 12556 | OwnerID: firstUser.UserID, |
| 12557 | LastModelConfigID: modelConfig.ID, |
| 12558 | Title: "debug-runs-cap", |
| 12559 | }) |
| 12560 | |
| 12561 | base := time.Now().UTC().Add(-24 * time.Hour).Round(time.Second) |
| 12562 | // Seed 101 runs with monotonically increasing started_at. The |
| 12563 | // handler caps at 100, so the oldest run (i=0) must be excluded |
| 12564 | // and the remaining runs must be returned newest-first. |
| 12565 | seeded := make([]database.ChatDebugRun, 101) |
| 12566 | for i := range seeded { |
| 12567 | seeded[i] = seedChatDebugRun(ctx, t, db, chat.ID, base.Add(time.Duration(i)*time.Minute)) |
| 12568 | } |
| 12569 |
nothing calls this directly
no test coverage detected