(t *testing.T)
| 24 | ) |
| 25 | |
| 26 | func TestRecordPrompt(t *testing.T) { |
| 27 | t.Parallel() |
| 28 | |
| 29 | tests := []struct { |
| 30 | name string |
| 31 | promptWasRecorded bool |
| 32 | prompt string |
| 33 | responseID string |
| 34 | wantRecorded bool |
| 35 | wantPrompt string |
| 36 | }{ |
| 37 | { |
| 38 | name: "records_prompt_successfully", |
| 39 | prompt: "tell me a joke", |
| 40 | responseID: "resp_123", |
| 41 | wantRecorded: true, |
| 42 | wantPrompt: "tell me a joke", |
| 43 | }, |
| 44 | { |
| 45 | name: "records_empty_prompt_successfully", |
| 46 | prompt: "", |
| 47 | responseID: "resp_123", |
| 48 | wantRecorded: true, |
| 49 | wantPrompt: "", |
| 50 | }, |
| 51 | { |
| 52 | name: "skips_recording_on_empty_response_id", |
| 53 | prompt: "tell me a joke", |
| 54 | responseID: "", |
| 55 | wantRecorded: false, |
| 56 | }, |
| 57 | } |
| 58 | |
| 59 | for _, tc := range tests { |
| 60 | t.Run(tc.name, func(t *testing.T) { |
| 61 | t.Parallel() |
| 62 | |
| 63 | rec := &testutil.MockRecorder{} |
| 64 | id := uuid.New() |
| 65 | base := &responsesInterceptionBase{ |
| 66 | id: id, |
| 67 | recorder: rec, |
| 68 | logger: slog.Make(), |
| 69 | } |
| 70 | |
| 71 | base.recordUserPrompt(t.Context(), tc.responseID, tc.prompt) |
| 72 | |
| 73 | prompts := rec.RecordedPromptUsages() |
| 74 | if tc.wantRecorded { |
| 75 | require.Len(t, prompts, 1) |
| 76 | require.Equal(t, id.String(), prompts[0].InterceptionID) |
| 77 | require.Equal(t, tc.responseID, prompts[0].MsgID) |
| 78 | require.Equal(t, tc.wantPrompt, prompts[0].Prompt) |
| 79 | } else { |
| 80 | require.Empty(t, prompts) |
| 81 | } |
| 82 | }) |
| 83 | } |
nothing calls this directly
no test coverage detected