Runs the workflow scenario to completion, draining the event stream. If ``event_sink`` is provided, collected events are appended to it as they are drained. This lets callers inspect the events that were emitted before an exception propagates (e.g. when ``failing=True``).
(
*, failing: bool = False, event_sink: list[Event] | None = None
)
| 406 | |
| 407 | |
| 408 | async def run_node_scenario( |
| 409 | *, failing: bool = False, event_sink: list[Event] | None = None |
| 410 | ) -> list[Event]: |
| 411 | """Runs the workflow scenario to completion, draining the event stream. |
| 412 | |
| 413 | If ``event_sink`` is provided, collected events are appended to it as they |
| 414 | are drained. This lets callers inspect the events that were emitted before |
| 415 | an exception propagates (e.g. when ``failing=True``). |
| 416 | """ |
| 417 | workflow = build_test_workflow(failing=failing) |
| 418 | runner = InMemoryRunner(app_name=NODE_APP_NAME, node=workflow) |
| 419 | session = await runner.session_service.create_session( |
| 420 | app_name=NODE_APP_NAME, user_id=NODE_USER_ID |
| 421 | ) |
| 422 | content = Content(parts=[Part.from_text(text=USER_PROMPT)], role="user") |
| 423 | |
| 424 | collected_events: list[Event] = event_sink if event_sink is not None else [] |
| 425 | |
| 426 | async with aclosing( |
| 427 | runner.run_async( |
| 428 | user_id=NODE_USER_ID, |
| 429 | session_id=session.id, |
| 430 | new_message=content, |
| 431 | ) |
| 432 | ) as agen: |
| 433 | async for event in agen: |
| 434 | collected_events.append(event) |
| 435 | |
| 436 | return collected_events |
| 437 | |
| 438 | |
| 439 | async def run_agent_scenario(runner: TestInMemoryRunner) -> None: |
no test coverage detected