(t *testing.T)
| 278 | } |
| 279 | |
| 280 | func TestExecuteModelStream(t *testing.T) { |
| 281 | model := "model-execution-stream-model" |
| 282 | requestBody := []byte(fmt.Sprintf(`{"model":%q,"stream":true}`, model)) |
| 283 | executor := &modelExecutionCaptureExecutor{ |
| 284 | stream: func(ctx context.Context, auth *coreauth.Auth, req coreexecutor.Request, opts coreexecutor.Options) (*coreexecutor.StreamResult, error) { |
| 285 | chunks := make(chan coreexecutor.StreamChunk, 1) |
| 286 | chunks <- coreexecutor.StreamChunk{Payload: []byte("stream-one")} |
| 287 | close(chunks) |
| 288 | return &coreexecutor.StreamResult{ |
| 289 | Headers: http.Header{"X-Upstream": []string{"stream"}}, |
| 290 | Chunks: chunks, |
| 291 | }, nil |
| 292 | }, |
| 293 | } |
| 294 | handler := newModelExecutionHandler(t, model, executor, &sdkconfig.SDKConfig{PassthroughHeaders: true}) |
| 295 | |
| 296 | stream, errMsg := handler.ExecuteModelStream(context.Background(), ModelExecutionRequest{ |
| 297 | EntryProtocol: "openai", |
| 298 | ExitProtocol: "claude", |
| 299 | Model: model, |
| 300 | Stream: true, |
| 301 | Body: requestBody, |
| 302 | Headers: http.Header{"X-Callback": []string{"stream"}}, |
| 303 | }) |
| 304 | if errMsg != nil { |
| 305 | t.Fatalf("ExecuteModelStream() error = %+v", errMsg) |
| 306 | } |
| 307 | if stream.StatusCode != http.StatusOK { |
| 308 | t.Fatalf("status = %d, want %d", stream.StatusCode, http.StatusOK) |
| 309 | } |
| 310 | if stream.Headers.Get("X-Upstream") != "stream" { |
| 311 | t.Fatalf("headers = %#v, want upstream header", stream.Headers) |
| 312 | } |
| 313 | chunk, ok := <-stream.Chunks |
| 314 | if !ok { |
| 315 | t.Fatal("stream chunks closed before payload") |
| 316 | } |
| 317 | if chunk.Err != nil { |
| 318 | t.Fatalf("stream chunk error = %+v", chunk.Err) |
| 319 | } |
| 320 | if string(chunk.Payload) != "stream-one" { |
| 321 | t.Fatalf("stream chunk payload = %q, want stream-one", chunk.Payload) |
| 322 | } |
| 323 | if chunk, ok = <-stream.Chunks; ok { |
| 324 | t.Fatalf("unexpected extra stream chunk: %+v", chunk) |
| 325 | } |
| 326 | |
| 327 | gotReq, gotOpts := executor.captured() |
| 328 | if gotReq.Model != model { |
| 329 | t.Fatalf("executor model = %q, want %q", gotReq.Model, model) |
| 330 | } |
| 331 | if string(gotReq.Payload) != string(requestBody) { |
| 332 | t.Fatalf("executor payload = %q, want %q", gotReq.Payload, requestBody) |
| 333 | } |
| 334 | if !gotOpts.Stream { |
| 335 | t.Fatal("executor stream option = false, want true") |
| 336 | } |
| 337 | if gotOpts.SourceFormat != sdktranslator.FormatOpenAI { |
nothing calls this directly
no test coverage detected