TestHandleStream_Refusal verifies that a refusal terminates the stream with the refusal finish reason and stops the loop instead of being mistaken for a normal empty completion.
(t *testing.T)
| 55 | // the refusal finish reason and stops the loop instead of being mistaken for a |
| 56 | // normal empty completion. |
| 57 | func TestHandleStream_Refusal(t *testing.T) { |
| 58 | t.Parallel() |
| 59 | |
| 60 | stream := newStreamBuilder(). |
| 61 | AddRefusal(). |
| 62 | Build() |
| 63 | |
| 64 | a := agent.New("root", "test", agent.WithModel(&mockProvider{id: "test/mock-model", stream: stream})) |
| 65 | sess := session.New(session.WithUserMessage("go")) |
| 66 | |
| 67 | evCh := make(chan Event, 64) |
| 68 | res, err := handleStream( |
| 69 | t.Context(), nil, stream, a, nil, sess, nil, |
| 70 | defaultTelemetry{}, NewChannelSink(evCh), defaultStreamIdleTimeout, |
| 71 | ) |
| 72 | require.NoError(t, err) |
| 73 | |
| 74 | assert.Equal(t, chat.FinishReasonRefusal, res.FinishReason) |
| 75 | assert.True(t, res.Stopped, "a refusal ends the turn") |
| 76 | assert.Empty(t, res.Calls) |
| 77 | require.NotNil(t, res.Usage) |
| 78 | } |
| 79 | |
| 80 | // TestHandleStream_RefusalDropsPartialToolCalls verifies that tool calls |
| 81 | // streamed before the safety classifier ends the turn with "refusal" are NOT |
nothing calls this directly
no test coverage detected