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

Function TestDebugModel_GenerateError

coderd/x/chatd/chatdebug/model_internal_test.go:347–388  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

345}
346
347func TestDebugModel_GenerateError(t *testing.T) {
348 t.Parallel()
349
350 ctrl := gomock.NewController(t)
351 db := dbmock.NewMockStore(ctrl)
352 chatID := uuid.New()
353 ownerID := uuid.New()
354 runID := uuid.New()
355 wantErr := &testError{message: "boom"}
356
357 expectDebugLoggingEnabled(t, db, ownerID)
358 stepID := expectCreateStep(t, db, runID, chatID, OperationGenerate)
359 expectUpdateStep(t, db, stepID, chatID, StatusError, func(params database.UpdateChatDebugStepParams) {
360 require.False(t, params.NormalizedResponse.Valid)
361 require.False(t, params.Usage.Valid)
362 require.True(t, params.Attempts.Valid)
363 require.True(t, params.Error.Valid)
364 require.False(t, params.Metadata.Valid)
365
366 var errPayload normalizedErrorPayload
367 require.NoError(t, json.Unmarshal(params.Error.RawMessage, &errPayload))
368 require.Equal(t, "boom", errPayload.Message)
369 require.Equal(t, "*chatdebug.testError", errPayload.Type)
370 })
371
372 svc := NewService(db, testutil.Logger(t), nil)
373 model := &debugModel{
374 inner: &chattest.FakeModel{
375 GenerateFn: func(context.Context, fantasy.Call) (*fantasy.Response, error) {
376 return nil, wantErr
377 },
378 },
379 svc: svc,
380 opts: RecorderOptions{ChatID: chatID, OwnerID: ownerID},
381 }
382 t.Cleanup(func() { CleanupStepCounter(runID) })
383 ctx := ContextWithRun(context.Background(), &RunContext{RunID: runID, ChatID: chatID})
384
385 resp, err := model.Generate(ctx, fantasy.Call{})
386 require.Nil(t, resp)
387 require.ErrorIs(t, err, wantErr)
388}
389
390// TestDebugModel_GenerateRetryClearsError verifies that when a Generate
391// call fails and is retried on the same reused step, a successful retry

Callers

nothing calls this directly

Calls 13

GenerateMethod · 0.95
NewMockStoreFunction · 0.92
LoggerFunction · 0.92
expectCreateStepFunction · 0.85
expectUpdateStepFunction · 0.85
NewServiceFunction · 0.85
CleanupStepCounterFunction · 0.85
ContextWithRunFunction · 0.85
NewMethod · 0.65
CleanupMethod · 0.65
UnmarshalMethod · 0.45

Tested by

no test coverage detected