nolint:tparallel,paralleltest // Subtests share a single coderdtest instance.
(t *testing.T)
| 11179 | |
| 11180 | //nolint:tparallel,paralleltest // Subtests share a single coderdtest instance. |
| 11181 | func TestChatPlanModeInstructions(t *testing.T) { |
| 11182 | t.Parallel() |
| 11183 | |
| 11184 | adminClient, _ := newChatClientWithDatabase(t) |
| 11185 | firstUser := coderdtest.CreateFirstUser(t, adminClient.Client) |
| 11186 | _ = createChatModelConfig(t, adminClient) |
| 11187 | memberClientRaw, _ := coderdtest.CreateAnotherUser(t, adminClient.Client, firstUser.OrganizationID) |
| 11188 | memberClient := codersdk.NewExperimentalClient(memberClientRaw) |
| 11189 | |
| 11190 | updateChatPlanModeInstructions := func(t *testing.T, ctx context.Context, req codersdk.UpdateChatPlanModeInstructionsRequest) { |
| 11191 | t.Helper() |
| 11192 | |
| 11193 | err := adminClient.UpdateChatPlanModeInstructions(ctx, req) |
| 11194 | require.NoError(t, err) |
| 11195 | } |
| 11196 | |
| 11197 | getChatPlanModeInstructions := func(t *testing.T, ctx context.Context) codersdk.ChatPlanModeInstructionsResponse { |
| 11198 | t.Helper() |
| 11199 | |
| 11200 | resp, err := adminClient.GetChatPlanModeInstructions(ctx) |
| 11201 | require.NoError(t, err) |
| 11202 | return resp |
| 11203 | } |
| 11204 | |
| 11205 | roundTripTests := []struct { |
| 11206 | name string |
| 11207 | updates []string |
| 11208 | want string |
| 11209 | }{ |
| 11210 | { |
| 11211 | name: "DefaultGETReturnsEmpty", |
| 11212 | want: "", |
| 11213 | }, |
| 11214 | { |
| 11215 | name: "PUTThenGETRoundTrips", |
| 11216 | updates: []string{"Use plan mode for multi-step changes."}, |
| 11217 | want: "Use plan mode for multi-step changes.", |
| 11218 | }, |
| 11219 | } |
| 11220 | for _, tt := range roundTripTests { |
| 11221 | t.Run(tt.name, func(t *testing.T) { |
| 11222 | ctx := testutil.Context(t, testutil.WaitLong) |
| 11223 | |
| 11224 | for _, instructions := range tt.updates { |
| 11225 | updateChatPlanModeInstructions(t, ctx, codersdk.UpdateChatPlanModeInstructionsRequest{ |
| 11226 | PlanModeInstructions: instructions, |
| 11227 | }) |
| 11228 | } |
| 11229 | |
| 11230 | resp := getChatPlanModeInstructions(t, ctx) |
| 11231 | require.Equal(t, tt.want, resp.PlanModeInstructions) |
| 11232 | }) |
| 11233 | } |
| 11234 | |
| 11235 | t.Run("OversizedPayloadReturns400", func(t *testing.T) { |
| 11236 | ctx := testutil.Context(t, testutil.WaitLong) |
| 11237 | tooLong := strings.Repeat("a", 131073) |
| 11238 |
nothing calls this directly
no test coverage detected