(t *testing.T)
| 342 | } |
| 343 | |
| 344 | func TestSessionFromEvents(t *testing.T) { |
| 345 | t.Parallel() |
| 346 | |
| 347 | tests := []struct { |
| 348 | name string |
| 349 | events []map[string]any |
| 350 | title string |
| 351 | question string |
| 352 | wantMessages int |
| 353 | wantContent string |
| 354 | }{ |
| 355 | { |
| 356 | name: "empty events", |
| 357 | events: []map[string]any{}, |
| 358 | title: "test", |
| 359 | question: "hello", |
| 360 | wantMessages: 1, // just the user message |
| 361 | wantContent: "", |
| 362 | }, |
| 363 | { |
| 364 | name: "agent choice events", |
| 365 | events: []map[string]any{ |
| 366 | {"type": "agent_choice", "content": "Hello ", "agent_name": "root"}, |
| 367 | {"type": "agent_choice", "content": "world!"}, |
| 368 | {"type": "stream_stopped"}, |
| 369 | }, |
| 370 | title: "test", |
| 371 | question: "greet me", |
| 372 | wantMessages: 2, // user + assistant |
| 373 | wantContent: "Hello world!", |
| 374 | }, |
| 375 | { |
| 376 | name: "tool calls and responses", |
| 377 | events: []map[string]any{ |
| 378 | {"type": "agent_choice", "content": "Let me help.", "agent_name": "root"}, |
| 379 | { |
| 380 | "type": "tool_call", |
| 381 | "tool_call": map[string]any{ |
| 382 | "id": "call_123", |
| 383 | "type": "function", |
| 384 | "function": map[string]any{ |
| 385 | "name": "read_file", |
| 386 | "arguments": `{"path": "test.txt"}`, |
| 387 | }, |
| 388 | }, |
| 389 | }, |
| 390 | { |
| 391 | "type": "tool_call_response", |
| 392 | "tool_call_id": "call_123", |
| 393 | "response": "file content", |
| 394 | }, |
| 395 | {"type": "agent_choice", "content": "Done!"}, |
| 396 | {"type": "stream_stopped"}, |
| 397 | }, |
| 398 | title: "test", |
| 399 | question: "read file", |
| 400 | wantMessages: 4, // user + assistant (with tool call) + tool response + assistant |
| 401 | wantContent: "Done!", |
nothing calls this directly
no test coverage detected