nolint:tparallel // subtests share state via client, firstUser, modelConfig
(t *testing.T)
| 13363 | |
| 13364 | //nolint:tparallel // subtests share state via client, firstUser, modelConfig |
| 13365 | func TestUserChatCompactionThresholds(t *testing.T) { |
| 13366 | t.Parallel() |
| 13367 | |
| 13368 | client, _ := newChatClientWithDatabase(t) |
| 13369 | firstUser := coderdtest.CreateFirstUser(t, client.Client) |
| 13370 | modelConfig := createChatModelConfig(t, client) |
| 13371 | |
| 13372 | t.Run("EmptyByDefault", func(t *testing.T) { //nolint:paralleltest // subtests share parent state |
| 13373 | ctx := testutil.Context(t, testutil.WaitLong) |
| 13374 | |
| 13375 | thresholds, err := client.GetUserChatCompactionThresholds(ctx) |
| 13376 | require.NoError(t, err) |
| 13377 | require.Empty(t, thresholds.Thresholds) |
| 13378 | }) |
| 13379 | |
| 13380 | t.Run("PutAndGet", func(t *testing.T) { //nolint:paralleltest // subtests share parent state |
| 13381 | ctx := testutil.Context(t, testutil.WaitLong) |
| 13382 | |
| 13383 | override, err := client.UpdateUserChatCompactionThreshold(ctx, modelConfig.ID, codersdk.UpdateUserChatCompactionThresholdRequest{ |
| 13384 | ThresholdPercent: 75, |
| 13385 | }) |
| 13386 | require.NoError(t, err) |
| 13387 | require.Equal(t, modelConfig.ID, override.ModelConfigID) |
| 13388 | require.EqualValues(t, 75, override.ThresholdPercent) |
| 13389 | |
| 13390 | thresholds, err := client.GetUserChatCompactionThresholds(ctx) |
| 13391 | require.NoError(t, err) |
| 13392 | require.Len(t, thresholds.Thresholds, 1) |
| 13393 | require.Equal(t, modelConfig.ID, thresholds.Thresholds[0].ModelConfigID) |
| 13394 | require.EqualValues(t, 75, thresholds.Thresholds[0].ThresholdPercent) |
| 13395 | }) |
| 13396 | |
| 13397 | t.Run("UpsertChangesValue", func(t *testing.T) { //nolint:paralleltest // subtests share parent state |
| 13398 | ctx := testutil.Context(t, testutil.WaitLong) |
| 13399 | |
| 13400 | _, err := client.UpdateUserChatCompactionThreshold(ctx, modelConfig.ID, codersdk.UpdateUserChatCompactionThresholdRequest{ |
| 13401 | ThresholdPercent: 50, |
| 13402 | }) |
| 13403 | require.NoError(t, err) |
| 13404 | |
| 13405 | override, err := client.UpdateUserChatCompactionThreshold(ctx, modelConfig.ID, codersdk.UpdateUserChatCompactionThresholdRequest{ |
| 13406 | ThresholdPercent: 75, |
| 13407 | }) |
| 13408 | require.NoError(t, err) |
| 13409 | require.EqualValues(t, 75, override.ThresholdPercent) |
| 13410 | |
| 13411 | thresholds, err := client.GetUserChatCompactionThresholds(ctx) |
| 13412 | require.NoError(t, err) |
| 13413 | require.Len(t, thresholds.Thresholds, 1) |
| 13414 | require.EqualValues(t, 75, thresholds.Thresholds[0].ThresholdPercent) |
| 13415 | }) |
| 13416 | |
| 13417 | t.Run("BoundaryValues", func(t *testing.T) { //nolint:paralleltest // subtests share parent state |
| 13418 | ctx := testutil.Context(t, testutil.WaitLong) |
| 13419 | |
| 13420 | override, err := client.UpdateUserChatCompactionThreshold(ctx, modelConfig.ID, codersdk.UpdateUserChatCompactionThresholdRequest{ |
| 13421 | ThresholdPercent: 0, |
| 13422 | }) |
nothing calls this directly
no test coverage detected