fakeAnthropicSSE builds a minimal Anthropic Messages SSE stream whose sole text content is the provided string.
(t *testing.T, text string)
| 195 | // fakeAnthropicSSE builds a minimal Anthropic Messages SSE stream |
| 196 | // whose sole text content is the provided string. |
| 197 | func 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 |
| 207 | data: {"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 | |
| 209 | event: content_block_start |
| 210 | data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}} |
| 211 | |
| 212 | event: content_block_delta |
| 213 | data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"%s"}} |
| 214 | |
| 215 | event: content_block_stop |
| 216 | data: {"type":"content_block_stop","index":0} |
| 217 | |
| 218 | event: message_delta |
| 219 | data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"output_tokens":20}} |
| 220 | |
| 221 | event: message_stop |
| 222 | data: {"type":"message_stop"} |
| 223 | `, escaped) |
| 224 | } |
| 225 | |
| 226 | func TestGenerateFromAnthropicMock(t *testing.T) { |
| 227 | t.Parallel() |
no test coverage detected