Skip to content

Commit bbad9ec

Browse files
rei-arificopybara-github
authored andcommitted
fix(cli): fail Agent Engine deploy when config file path is invalid
Merge #5128 ### Link to Issue or Description of Change **1. Link to an existing issue (if applicable):** - Closes: #5127 **Problem:** When `--agent_engine_config_file` is set to a path that does not exist, `to_agent_engine` previously behaved like no config file was provided. **Solution:** This change raises `click.ClickException` with a message that includes the resolved path. ### Testing plan - [x] `uv run python -m pytest tests/unittests/cli/utils/test_cli_deploy.py -v` - [x] Manual test `adk deploy agent_engine ... --agent_engine_config_file /nonexistent.json` and confirm a clear error before remote deploy. The same command with correct filename relative to parent directory of the agent does not fail. **Unit Tests:** - [x] I have added or updated unit tests for my change. - [x] All unit tests pass locally. ``` uv run python -m pytest tests/unittests/cli/utils/test_cli_deploy.py -v =========================================================================================================================== test session starts =========================================================================================================================== platform darwin -- Python 3.11.13, pytest-9.0.2, pluggy-1.6.0 -- /Users/rei/Repos/adk-python/.venv/bin/python3 cachedir: .pytest_cache rootdir: /Users/rei/Repos/adk-python configfile: pyproject.toml plugins: mock-3.15.1, xdist-3.8.0, asyncio-1.3.0, langsmith-0.7.25, anyio-4.13.0 asyncio: mode=Mode.AUTO, debug=False, asyncio_default_fixture_loop_scope=function, asyncio_default_test_loop_scope=function collected 31 items tests/unittests/cli/utils/test_cli_deploy.py::test_resolve_project_with_option PASSED [ 3%] tests/unittests/cli/utils/test_cli_deploy.py::test_resolve_project_from_gcloud PASSED [ 6%] tests/unittests/cli/utils/test_cli_deploy.py::test_resolve_project_from_gcloud_fails PASSED [ 9%] tests/unittests/cli/utils/test_cli_deploy.py::test_get_service_option_by_adk_version[1.3.0-sqlite://s-gs://a-rag://m-None---session_service_uri=sqlite://s --artifact_service_uri=gs://a --memory_service_uri=rag://m] PASSED [ 12%] tests/unittests/cli/utils/test_cli_deploy.py::test_get_service_option_by_adk_version[1.2.5-sqlite://s-gs://a-rag://m-None---session_db_url=sqlite://s --artifact_storage_uri=gs://a] PASSED [ 16%] tests/unittests/cli/utils/test_cli_deploy.py::test_get_service_option_by_adk_version[0.5.0-sqlite://s-gs://a-rag://m-None---session_db_url=sqlite://s] PASSED [ 19%] tests/unittests/cli/utils/test_cli_deploy.py::test_get_service_option_by_adk_version[1.3.0-sqlite://s-None-None-None---session_service_uri=sqlite://s] PASSED [ 22%] tests/unittests/cli/utils/test_cli_deploy.py::test_get_service_option_by_adk_version[1.3.0-None-gs://a-rag://m-None---artifact_service_uri=gs://a --memory_service_uri=rag://m] PASSED [ 25%] tests/unittests/cli/utils/test_cli_deploy.py::test_get_service_option_by_adk_version[1.2.0-None-gs://a-None-None---artifact_storage_uri=gs://a] PASSED [ 29%] tests/unittests/cli/utils/test_cli_deploy.py::test_get_service_option_by_adk_version[1.21.0-None-None-None-False---no_use_local_storage] PASSED [ 32%] tests/unittests/cli/utils/test_cli_deploy.py::test_get_service_option_by_adk_version[1.21.0-None-None-None-True---use_local_storage] PASSED [ 35%] tests/unittests/cli/utils/test_cli_deploy.py::test_get_service_option_by_adk_version[1.21.0-sqlite://s-gs://a-None-False---session_service_uri=sqlite://s --artifact_service_uri=gs://a] PASSED [ 38%] tests/unittests/cli/utils/test_cli_deploy.py::test_agent_engine_app_template_compiles_with_windows_paths PASSED [ 41%] tests/unittests/cli/utils/test_cli_deploy.py::test_to_agent_engine_happy_path[True] PASSED [ 45%] tests/unittests/cli/utils/test_cli_deploy.py::test_to_agent_engine_happy_path[False] PASSED [ 48%] tests/unittests/cli/utils/test_cli_deploy.py::test_to_agent_engine_raises_when_explicit_config_file_missing PASSED [ 51%] tests/unittests/cli/utils/test_cli_deploy.py::test_to_agent_engine_skips_agent_import_validation_by_default PASSED [ 54%] tests/unittests/cli/utils/test_cli_deploy.py::test_to_agent_engine_validates_agent_import_when_enabled PASSED [ 58%] tests/unittests/cli/utils/test_cli_deploy.py::test_to_gke_happy_path[True] PASSED [ 61%] tests/unittests/cli/utils/test_cli_deploy.py::test_to_gke_happy_path[False] PASSED [ 64%] tests/unittests/cli/utils/test_cli_deploy.py::TestValidateAgentImport::test_skips_config_agents PASSED [ 67%] tests/unittests/cli/utils/test_cli_deploy.py::TestValidateAgentImport::test_raises_on_missing_agent_module PASSED [ 70%] tests/unittests/cli/utils/test_cli_deploy.py::TestValidateAgentImport::test_raises_on_missing_export PASSED [ 74%] tests/unittests/cli/utils/test_cli_deploy.py::TestValidateAgentImport::test_success_with_root_agent_export PASSED [ 77%] tests/unittests/cli/utils/test_cli_deploy.py::TestValidateAgentImport::test_success_with_app_export PASSED [ 80%] tests/unittests/cli/utils/test_cli_deploy.py::TestValidateAgentImport::test_success_with_relative_imports PASSED [ 83%] tests/unittests/cli/utils/test_cli_deploy.py::TestValidateAgentImport::test_raises_on_import_error PASSED [ 87%] tests/unittests/cli/utils/test_cli_deploy.py::TestValidateAgentImport::test_raises_on_basellm_import_error PASSED [ 90%] tests/unittests/cli/utils/test_cli_deploy.py::TestValidateAgentImport::test_raises_on_syntax_error PASSED [ 93%] tests/unittests/cli/utils/test_cli_deploy.py::TestValidateAgentImport::test_cleans_up_sys_modules PASSED [ 96%] tests/unittests/cli/utils/test_cli_deploy.py::TestValidateAgentImport::test_restores_sys_path PASSED [100%] =========================================================================================================================== 31 passed in 2.48s ============================================================================================================================ ``` **Manual End-to-End (E2E) Tests:** 1. Install adk cli from this PR 2. Run `adk deploy agent_engine ... --agent_engine_config_file /nonexistent.json # Failure expected` 3. Run `adk deploy agent_engine ... --agent_engine_config_file agent/config.json # Deployment proceeds if file path is correct` ### Checklist - [x] I have read the [CONTRIBUTING.md](https://github.com/google/adk-python/blob/main/CONTRIBUTING.md) document. - [x] I have performed a self-review of my own code. - [n/a] I have commented my code, particularly in hard-to-understand areas. - [x] I have added tests that prove my fix is effective or that my feature works. - [x] New and existing unit tests pass locally with my changes. - [x] I have manually tested my changes end-to-end. - [n/a] Any dependent changes have been merged and published in downstream modules. COPYBARA_INTEGRATE_REVIEW=#5128 from rei-arifi:fix/agent-engine-config-file-missing 0c2f9f7 PiperOrigin-RevId: 895550691
1 parent 2b49163 commit bbad9ec

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/google/adk/cli/cli_deploy.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,13 @@ def to_agent_engine(
949949

950950
click.echo('Resolving files and dependencies...')
951951
agent_config = {}
952+
if agent_engine_config_file and not os.path.exists(
953+
agent_engine_config_file
954+
):
955+
raise click.ClickException(
956+
'Agent engine config file not found: '
957+
f'{parent_folder}/{agent_engine_config_file}'
958+
)
952959
if not agent_engine_config_file:
953960
# Attempt to read the agent engine config from .agent_engine_config.json in the dir (if any).
954961
agent_engine_config_file = os.path.join(

tests/unittests/cli/utils/test_cli_deploy.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,34 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
306306
assert str(rmtree_recorder.get_last_call_args()[0]) == str(tmp_dir)
307307

308308

309+
def test_to_agent_engine_raises_when_explicit_config_file_missing(
310+
monkeypatch: pytest.MonkeyPatch,
311+
agent_dir: Callable[[bool, bool], Path],
312+
tmp_path: Path,
313+
) -> None:
314+
"""It should fail with a clear error when --agent_engine_config_file is missing."""
315+
monkeypatch.setattr(shutil, "rmtree", lambda *a, **k: None)
316+
src_dir = agent_dir(False, False)
317+
missing_config = tmp_path / "no_such_agent_engine_config.json"
318+
expected_abs = str(missing_config.resolve())
319+
320+
with pytest.raises(click.ClickException) as exc_info:
321+
cli_deploy.to_agent_engine(
322+
agent_folder=str(src_dir),
323+
temp_folder="tmp",
324+
adk_app="my_adk_app",
325+
trace_to_cloud=True,
326+
project="my-gcp-project",
327+
region="us-central1",
328+
display_name="My Test Agent",
329+
description="A test agent.",
330+
agent_engine_config_file=str(missing_config),
331+
)
332+
333+
assert "Agent engine config file not found" in str(exc_info.value)
334+
assert expected_abs in str(exc_info.value)
335+
336+
309337
def test_to_agent_engine_skips_agent_import_validation_by_default(
310338
monkeypatch: pytest.MonkeyPatch,
311339
agent_dir: Callable[[bool, bool], Path],

0 commit comments

Comments
 (0)