From 44565fb0cbdd8e8f194d8fc64d9eb9e35954038a Mon Sep 17 00:00:00 2001 From: Rei Arifi Date: Fri, 3 Apr 2026 17:40:00 +0200 Subject: [PATCH] fix(cli): fail Agent Engine deploy when config file path is invalid --- src/google/adk/cli/cli_deploy.py | 7 +++++ tests/unittests/cli/utils/test_cli_deploy.py | 28 ++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/google/adk/cli/cli_deploy.py b/src/google/adk/cli/cli_deploy.py index b2072dfd0e..e4839be747 100644 --- a/src/google/adk/cli/cli_deploy.py +++ b/src/google/adk/cli/cli_deploy.py @@ -949,6 +949,13 @@ def to_agent_engine( click.echo('Resolving files and dependencies...') agent_config = {} + if agent_engine_config_file and not os.path.exists( + agent_engine_config_file + ): + raise click.ClickException( + 'Agent engine config file not found: ' + f'{parent_folder}/{agent_engine_config_file}' + ) if not agent_engine_config_file: # Attempt to read the agent engine config from .agent_engine_config.json in the dir (if any). agent_engine_config_file = os.path.join( diff --git a/tests/unittests/cli/utils/test_cli_deploy.py b/tests/unittests/cli/utils/test_cli_deploy.py index 22b029a976..ed1aa8cc60 100644 --- a/tests/unittests/cli/utils/test_cli_deploy.py +++ b/tests/unittests/cli/utils/test_cli_deploy.py @@ -306,6 +306,34 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: assert str(rmtree_recorder.get_last_call_args()[0]) == str(tmp_dir) +def test_to_agent_engine_raises_when_explicit_config_file_missing( + monkeypatch: pytest.MonkeyPatch, + agent_dir: Callable[[bool, bool], Path], + tmp_path: Path, +) -> None: + """It should fail with a clear error when --agent_engine_config_file is missing.""" + monkeypatch.setattr(shutil, "rmtree", lambda *a, **k: None) + src_dir = agent_dir(False, False) + missing_config = tmp_path / "no_such_agent_engine_config.json" + expected_abs = str(missing_config.resolve()) + + with pytest.raises(click.ClickException) as exc_info: + cli_deploy.to_agent_engine( + agent_folder=str(src_dir), + temp_folder="tmp", + adk_app="my_adk_app", + trace_to_cloud=True, + project="my-gcp-project", + region="us-central1", + display_name="My Test Agent", + description="A test agent.", + agent_engine_config_file=str(missing_config), + ) + + assert "Agent engine config file not found" in str(exc_info.value) + assert expected_abs in str(exc_info.value) + + def test_to_agent_engine_skips_agent_import_validation_by_default( monkeypatch: pytest.MonkeyPatch, agent_dir: Callable[[bool, bool], Path],