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

Function TestChatPlanModeInstructions

coderd/exp_chats_test.go:11181–11252  ·  view source on GitHub ↗

nolint:tparallel,paralleltest // Subtests share a single coderdtest instance.

(t *testing.T)

Source from the content-addressed store, hash-verified

11179
11180//nolint:tparallel,paralleltest // Subtests share a single coderdtest instance.
11181func 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

Callers

nothing calls this directly

Calls 14

CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
NewExperimentalClientFunction · 0.92
ContextFunction · 0.92
requireSDKErrorFunction · 0.85
createChatModelConfigFunction · 0.70
HelperMethod · 0.65

Tested by

no test coverage detected