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

Function fakeAnthropicSSE

coderd/taskname/taskname_internal_test.go:197–224  ·  view source on GitHub ↗

fakeAnthropicSSE builds a minimal Anthropic Messages SSE stream whose sole text content is the provided string.

(t *testing.T, text string)

Source from the content-addressed store, hash-verified

195// fakeAnthropicSSE builds a minimal Anthropic Messages SSE stream
196// whose sole text content is the provided string.
197func fakeAnthropicSSE(t *testing.T, text string) string {
198 t.Helper()
199
200 // Use json.Marshal to produce a correctly escaped JSON
201 // string value, then strip the surrounding quotes.
202 escapedBytes, err := json.Marshal(text)
203 require.NoError(t, err)
204 escaped := string(escapedBytes[1 : len(escapedBytes)-1])
205
206 return fmt.Sprintf(`event: message_start
207data: {"type":"message_start","message":{"id":"msg_test","type":"message","role":"assistant","model":"claude-haiku-4-5-20241022","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"output_tokens":1}}}
208
209event: content_block_start
210data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}
211
212event: content_block_delta
213data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"%s"}}
214
215event: content_block_stop
216data: {"type":"content_block_stop","index":0}
217
218event: message_delta
219data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"output_tokens":20}}
220
221event: message_stop
222data: {"type":"message_stop"}
223`, escaped)
224}
225
226func TestGenerateFromAnthropicMock(t *testing.T) {
227 t.Parallel()

Callers 1

Calls 2

HelperMethod · 0.65
MarshalMethod · 0.45

Tested by

no test coverage detected