MCPcopy Index your code
hub / github.com/docker/docker-agent / TestHandleStream_Refusal

Function TestHandleStream_Refusal

pkg/runtime/streaming_test.go:57–78  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

55// the refusal finish reason and stops the loop instead of being mistaken for a
56// normal empty completion.
57func 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

Callers

nothing calls this directly

Calls 10

NewFunction · 0.92
WithModelFunction · 0.92
NewFunction · 0.92
WithUserMessageFunction · 0.92
newStreamBuilderFunction · 0.85
handleStreamFunction · 0.85
NewChannelSinkFunction · 0.85
AddRefusalMethod · 0.80
ContextMethod · 0.80
BuildMethod · 0.45

Tested by

no test coverage detected