From d9e28311f8bc94dd68d04371379aa9a3cdc7b8d0 Mon Sep 17 00:00:00 2001 From: YASHcode-IIITV Date: Tue, 18 Aug 2026 22:50:20 +0530 Subject: [PATCH] test(cli): cover api server auto create session --- .../cli/utils/test_cli_tools_click.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/unittests/cli/utils/test_cli_tools_click.py b/tests/unittests/cli/utils/test_cli_tools_click.py index 1d890bd4e8..3cfd46954b 100644 --- a/tests/unittests/cli/utils/test_cli_tools_click.py +++ b/tests/unittests/cli/utils/test_cli_tools_click.py @@ -1579,6 +1579,35 @@ def test_cli_api_server_invokes_uvicorn( assert result.exit_code == 0 assert _patch_uvicorn.calls, "uvicorn.Server.run must be called" +def test_cli_api_server_passes_auto_create_session( + tmp_path: Path, + monkeypatch: pytest.MonkeyPatch, + _patch_uvicorn: _Recorder, +) -> None: + """`adk api_server --auto_create_session` enables automatic sessions.""" + agents_dir = tmp_path / "agents_api" + agents_dir.mkdir() + + mock_get_app = _Recorder() + monkeypatch.setattr( + "google.adk.cli.fast_api.get_fast_api_app", mock_get_app + ) + + runner = CliRunner() + result = runner.invoke( + cli_tools_click.main, + [ + "api_server", + str(agents_dir), + "--auto_create_session", + ], + ) + + assert result.exit_code == 0 + assert mock_get_app.calls + + called_kwargs = mock_get_app.calls[-1][1] + assert called_kwargs["auto_create_session"] is True def test_cli_web_passes_service_uris( tmp_path: Path, monkeypatch: pytest.MonkeyPatch, _patch_uvicorn: _Recorder