Integration test for `adk run` with query using CliRunner (No mocks).
(tmp_path: Path)
| 22 | |
| 23 | |
| 24 | def test_cli_run_integration(tmp_path: Path) -> None: |
| 25 | """Integration test for `adk run` with query using CliRunner (No mocks).""" |
| 26 | # Arrange |
| 27 | agent_dir = tmp_path / "dummy_agent" |
| 28 | agent_dir.mkdir() |
| 29 | |
| 30 | # Create __init__.py |
| 31 | with open(agent_dir / "__init__.py", "w") as f: |
| 32 | f.write("from . import agent\n") |
| 33 | |
| 34 | # Create agent.py |
| 35 | agent_code = """ |
| 36 | from google.adk.agents import Agent |
| 37 | from google.adk.events.event import Event |
| 38 | from typing import AsyncGenerator |
| 39 | |
| 40 | class DummyAgent(Agent): |
| 41 | async def run_async(self, ctx) -> AsyncGenerator[Event, None]: |
| 42 | # Yield a text response |
| 43 | from google.adk.events.event import Event |
| 44 | text = ctx.user_content.parts[0].text if ctx.user_content and ctx.user_content.parts else "No input" |
| 45 | yield Event(author="dummy", output=f"Echo: {text}") |
| 46 | |
| 47 | root_agent = DummyAgent(name="dummy", model="gemini-2.5-flash") |
| 48 | """ |
| 49 | with open(agent_dir / "agent.py", "w") as f: |
| 50 | f.write(agent_code) |
| 51 | |
| 52 | runner = CliRunner() |
| 53 | |
| 54 | # Act |
| 55 | result = runner.invoke( |
| 56 | cli_tools_click.main, |
| 57 | ["run", "--jsonl", str(agent_dir), "hello world"], |
| 58 | ) |
| 59 | |
| 60 | # Assert |
| 61 | assert result.exit_code == 0 |
| 62 | |
| 63 | # Check stdout |
| 64 | stdout = result.stdout |
| 65 | assert stdout, "Stdout should not be empty" |
| 66 | |
| 67 | # Parse JSONL lines |
| 68 | lines = stdout.strip().split("\n") |
| 69 | assert len(lines) > 0 |
| 70 | |
| 71 | # The last line should be the final output or event |
| 72 | last_line = lines[-1] |
| 73 | try: |
| 74 | data = json.loads(last_line) |
| 75 | assert "output" in data |
| 76 | assert "Echo: hello world" in data["output"] |
| 77 | except json.JSONDecodeError: |
| 78 | pytest.fail(f"Stdout contained non-JSON line: {last_line}") |