From b38ad2889e4043fad1fe45d013961c0e2af4ca05 Mon Sep 17 00:00:00 2001 From: netvinod Date: Tue, 5 Aug 2025 10:55:27 -0500 Subject: [PATCH 1/3] fix: Update adk_app handling to use custom module without .py extension --- src/google/adk/cli/cli_deploy.py | 28 +++-- src/google/adk/cli/cli_tools_click.py | 3 +- tests/unittests/cli/utils/test_cli_deploy.py | 108 +++++++++++++++++- .../test_vertex_ai_session_service.py | 2 +- 4 files changed, 126 insertions(+), 15 deletions(-) diff --git a/src/google/adk/cli/cli_deploy.py b/src/google/adk/cli/cli_deploy.py index 5dc730e716..6dcf53c3b0 100644 --- a/src/google/adk/cli/cli_deploy.py +++ b/src/google/adk/cli/cli_deploy.py @@ -307,6 +307,7 @@ def to_agent_engine( values of `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` will be overridden by `project` and `region` if they are specified. """ + ADK_APP_OBJECT_NAME = 'adk_app' app_name = os.path.basename(agent_folder) agent_src_path = os.path.join(temp_folder, app_name) # remove agent_src_path if it exists @@ -386,15 +387,22 @@ def to_agent_engine( ) click.echo('Vertex AI initialized.') - adk_app_file = os.path.join(temp_folder, f'{adk_app}.py') - with open(adk_app_file, 'w', encoding='utf-8') as f: - f.write( - _AGENT_ENGINE_APP_TEMPLATE.format( - app_name=app_name, - trace_to_cloud_option=trace_to_cloud, - ) - ) - click.echo(f'Created {adk_app_file}') + click.echo(f'Using adk_app: {adk_app}') + + if not os.path.exists(os.path.join(agent_src_path,f"{adk_app}.py")): + adk_app_file = os.path.join(temp_folder, f'{adk_app}.py') + with open(adk_app_file, 'w', encoding='utf-8') as f: + f.write( + _AGENT_ENGINE_APP_TEMPLATE.format( + app_name=app_name, + trace_to_cloud_option=trace_to_cloud, + ) + ) + click.echo(f'Created {adk_app_file}') + else: + shutil.copy(os.path.join(agent_src_path,f"{adk_app}.py"), temp_folder) + click.echo(f'Using existing {adk_app}.py') + click.echo('Files and dependencies resolved') if absolutize_imports: for root, _, files in os.walk(agent_src_path): @@ -415,7 +423,7 @@ def to_agent_engine( click.echo('Deploying to agent engine...') agent_engine = agent_engines.ModuleAgent( module_name=adk_app, - agent_name='adk_app', + agent_name=ADK_APP_OBJECT_NAME, register_operations={ '': [ 'get_session', diff --git a/src/google/adk/cli/cli_tools_click.py b/src/google/adk/cli/cli_tools_click.py index d02f914f3f..a053ad4e0a 100644 --- a/src/google/adk/cli/cli_tools_click.py +++ b/src/google/adk/cli/cli_tools_click.py @@ -1062,8 +1062,7 @@ def cli_deploy_cloud_run( type=str, default="agent_engine_app", help=( - "Optional. Python file for defining the ADK application" - " (default: a file named agent_engine_app.py)" + "Optional. The module name (without .py) for the Python file defining the ADK Application (default: 'agent_engine_app')." ), ) @click.option( diff --git a/tests/unittests/cli/utils/test_cli_deploy.py b/tests/unittests/cli/utils/test_cli_deploy.py index dfcbf0767c..c98aa34903 100644 --- a/tests/unittests/cli/utils/test_cli_deploy.py +++ b/tests/unittests/cli/utils/test_cli_deploy.py @@ -18,6 +18,7 @@ from __future__ import annotations import importlib +import os from pathlib import Path import shutil import subprocess @@ -452,7 +453,7 @@ def test_to_agent_engine_happy_path( cli_deploy.to_agent_engine( agent_folder=str(src_dir), temp_folder=str(temp_folder), - adk_app="my_adk_app", + adk_app="agent_engine_app", staging_bucket="gs://my-staging-bucket", trace_to_cloud=True, project="my-gcp-project", @@ -466,7 +467,7 @@ def test_to_agent_engine_happy_path( assert (temp_folder / app_name / "__init__.py").is_file() # 2. Verify adk_app.py creation - adk_app_path = temp_folder / "my_adk_app.py" + adk_app_path = temp_folder / f"agent_engine_app.py" assert adk_app_path.is_file() content = adk_app_path.read_text() assert f"from {app_name}.agent import root_agent" in content @@ -511,6 +512,109 @@ def test_to_agent_engine_happy_path( assert str(rmtree_recorder.get_last_call_args()[0]) == str(temp_folder) +@pytest.mark.usefixtures("mock_vertex_ai") +@pytest.mark.parametrize("has_reqs", [True, False]) +@pytest.mark.parametrize("has_env", [True, False]) +def test_to_agent_engine_happy_path_custom_file( + monkeypatch: pytest.MonkeyPatch, + agent_dir: Callable[[bool, bool], Path], + tmp_path: Path, + has_reqs: bool, + has_env: bool, +) -> None: + """ + Tests the happy path for the `to_agent_engine` function. + + Verifies: + 1. Source files are copied. + 2. `adk_app.py` is created correctly. + 3. `requirements.txt` is handled (created if not present). + 4. `.env` file is read if present. + 5. `vertexai.init` and `agent_engines.create` are called with the correct args. + 6. Cleanup is performed. + """ + src_dir = agent_dir(has_reqs, has_env) + temp_folder = tmp_path / "build" + app_name = src_dir.name + rmtree_recorder = _Recorder() + + monkeypatch.setattr(shutil, "rmtree", rmtree_recorder) + # Create a dummy adk_app.py file in the temp_folder + adk_app_content = """ + from test.agent import root_agent + from vertexai.preview.reasoning_engines import AdkApp + + adk_app = AdkApp( + agent=root_agent, + enable_tracing=True, + ) + """ + (src_dir / "my_adk_app.py").write_text(adk_app_content) + + # Execute + cli_deploy.to_agent_engine( + agent_folder=str(src_dir), + temp_folder=str(temp_folder), + adk_app="my_adk_app", + staging_bucket="gs://my-staging-bucket", + trace_to_cloud=True, + project="my-gcp-project", + region="us-central1", + display_name="My Test Agent", + description="A test agent.", + ) + + # 1. Verify file operations + assert (temp_folder / app_name / "agent.py").is_file() + assert (temp_folder / app_name / "__init__.py").is_file() + assert (temp_folder / "my_adk_app.py").is_file() + # 2. Verify adk_app.py creation + adk_app_path = temp_folder / "my_adk_app.py" + assert adk_app_path.is_file() + content = adk_app_path.read_text() + assert f"from test.agent import root_agent" in content + assert f"from agent.agent import root_agent" not in content + assert "adk_app = AdkApp(" in content + assert "enable_tracing=True" in content + + # 3. Verify requirements handling + reqs_path = temp_folder / app_name / "requirements.txt" + assert reqs_path.is_file() + if not has_reqs: + # It should have been created with the default content + assert "google-cloud-aiplatform[adk,agent_engines]" in reqs_path.read_text() + + # 4. Verify Vertex AI SDK calls + vertexai = sys.modules["vertexai"] + vertexai.init.assert_called_once_with( + project="my-gcp-project", + location="us-central1", + staging_bucket="gs://my-staging-bucket", + ) + + # 5. Verify env var handling + dotenv = sys.modules["dotenv"] + if has_env: + dotenv.dotenv_values.assert_called_once() + expected_env_vars = {"FILE_VAR": "value"} + else: + dotenv.dotenv_values.assert_not_called() + expected_env_vars = None + + # 6. Verify agent_engines.create call + vertexai.agent_engines.create.assert_called_once() + create_kwargs = vertexai.agent_engines.create.call_args.kwargs + assert create_kwargs["agent_engine"] == "mock-agent-engine-object" + assert create_kwargs["display_name"] == "My Test Agent" + assert create_kwargs["description"] == "A test agent." + assert create_kwargs["requirements"] == str(reqs_path) + assert create_kwargs["extra_packages"] == [str(temp_folder)] + assert create_kwargs["env_vars"] == expected_env_vars + + # 7. Verify cleanup + assert str(rmtree_recorder.get_last_call_args()[0]) == str(temp_folder) + + @pytest.mark.parametrize("include_requirements", [True, False]) def test_to_gke_happy_path( monkeypatch: pytest.MonkeyPatch, diff --git a/tests/unittests/sessions/test_vertex_ai_session_service.py b/tests/unittests/sessions/test_vertex_ai_session_service.py index 9601c93f7f..cde95a5900 100644 --- a/tests/unittests/sessions/test_vertex_ai_session_service.py +++ b/tests/unittests/sessions/test_vertex_ai_session_service.py @@ -13,7 +13,6 @@ # limitations under the License. import re -import this from typing import Any from typing import List from typing import Optional @@ -27,6 +26,7 @@ from google.adk.sessions.vertex_ai_session_service import VertexAiSessionService from google.genai import types import pytest +import this MOCK_SESSION_JSON_1 = { 'name': ( From 93764b5fba0dabb5474b6a7fb8becedc3c5c7ad6 Mon Sep 17 00:00:00 2001 From: netvinod Date: Thu, 20 Nov 2025 06:03:36 -0600 Subject: [PATCH 2/3] fix: Update adk_app handling to use custom module without .py extension --- src/google/adk/cli/cli_deploy.py | 31 +- tests/unittests/cli/utils/test_cli_deploy.py | 395 +----------------- .../test_vertex_ai_session_service.py | 1 - 3 files changed, 2 insertions(+), 425 deletions(-) diff --git a/src/google/adk/cli/cli_deploy.py b/src/google/adk/cli/cli_deploy.py index b7844f54ce..6b8b1ec5e3 100644 --- a/src/google/adk/cli/cli_deploy.py +++ b/src/google/adk/cli/cli_deploy.py @@ -918,35 +918,6 @@ def to_agent_engine( 'so it is no longer necessary to absolutize imports.' ) click.echo('Deploying to agent engine...') - agent_engine = agent_engines.ModuleAgent( - module_name=adk_app, - agent_name=ADK_APP_OBJECT_NAME, - register_operations={ - '': [ - 'get_session', - 'list_sessions', - 'create_session', - 'delete_session', - ], - 'async': [ - 'async_get_session', - 'async_list_sessions', - 'async_create_session', - 'async_delete_session', - ], - 'async_stream': ['async_stream_query'], - 'stream': ['stream_query', 'streaming_agent_run_with_events'], - }, - sys_paths=[temp_folder[1:]], - ) - agent_config = dict( - agent_engine=agent_engine, - requirements=requirements_file, - display_name=display_name, - description=description, - env_vars=env_vars, - extra_packages=[temp_folder], - ) agent_config['entrypoint_module'] = f'{temp_folder}.{adk_app}' agent_config['entrypoint_object'] = 'adk_app' agent_config['source_packages'] = [temp_folder] @@ -1196,4 +1167,4 @@ def to_gke( shutil.rmtree(temp_folder) click.secho( '\nšŸŽ‰ Deployment to GKE finished successfully!', fg='cyan', bold=True - ) + ) \ No newline at end of file diff --git a/tests/unittests/cli/utils/test_cli_deploy.py b/tests/unittests/cli/utils/test_cli_deploy.py index ceb25b6c51..e0110bb9e9 100644 --- a/tests/unittests/cli/utils/test_cli_deploy.py +++ b/tests/unittests/cli/utils/test_cli_deploy.py @@ -18,7 +18,6 @@ from __future__ import annotations import importlib -import os from pathlib import Path import shutil import subprocess @@ -180,295 +179,6 @@ def test_get_service_option_by_adk_version( expected: str, ) -> None: """It should return the correct service URI flags for a given ADK version.""" - assert ( - cli_deploy._get_service_option_by_adk_version( - adk_version=adk_version, - session_uri=session_uri, - artifact_uri=artifact_uri, - memory_uri=memory_uri, - ) - == expected - ) - - -@pytest.mark.parametrize("include_requirements", [True, False]) -@pytest.mark.parametrize("with_ui", [True, False]) -def test_to_cloud_run_happy_path( - monkeypatch: pytest.MonkeyPatch, - agent_dir: Callable[[bool, bool], Path], - tmp_path: Path, - include_requirements: bool, - with_ui: bool, -) -> None: - """ - End-to-end execution test for `to_cloud_run`. - - This test verifies that for a given configuration: - 1. The agent source files are correctly copied to a temporary build context. - 2. A valid Dockerfile is generated with the correct parameters. - 3. The `gcloud run deploy` command is constructed with the correct arguments. - """ - src_dir = agent_dir(include_requirements, False) - run_recorder = _Recorder() - - monkeypatch.setattr(subprocess, "run", run_recorder) - # Mock rmtree to prevent actual deletion during test run but record calls - rmtree_recorder = _Recorder() - monkeypatch.setattr(shutil, "rmtree", rmtree_recorder) - - # Execute the function under test - cli_deploy.to_cloud_run( - agent_folder=str(src_dir), - project="proj", - region="asia-northeast1", - service_name="svc", - app_name="agent", - temp_folder=str(tmp_path), - port=8080, - trace_to_cloud=True, - with_ui=with_ui, - log_level="info", - verbosity="info", - allow_origins=["http://localhost:3000", "https://my-app.com"], - session_service_uri="sqlite://", - artifact_service_uri="gs://bucket", - memory_service_uri="rag://", - adk_version="1.3.0", - ) - - # 1. Assert that source files were copied correctly - agent_dest_path = tmp_path / "agents" / "agent" - assert (agent_dest_path / "agent.py").is_file() - assert (agent_dest_path / "__init__.py").is_file() - assert ( - agent_dest_path / "requirements.txt" - ).is_file() == include_requirements - - # 2. Assert that the Dockerfile was generated correctly - dockerfile_path = tmp_path / "Dockerfile" - assert dockerfile_path.is_file() - dockerfile_content = dockerfile_path.read_text() - - expected_command = "web" if with_ui else "api_server" - assert f"CMD adk {expected_command} --port=8080" in dockerfile_content - assert "FROM python:3.11-slim" in dockerfile_content - assert ( - 'RUN adduser --disabled-password --gecos "" myuser' in dockerfile_content - ) - assert "USER myuser" in dockerfile_content - assert "ENV GOOGLE_CLOUD_PROJECT=proj" in dockerfile_content - assert "ENV GOOGLE_CLOUD_LOCATION=asia-northeast1" in dockerfile_content - assert "RUN pip install google-adk==1.3.0" in dockerfile_content - assert "--trace_to_cloud" in dockerfile_content - - if include_requirements: - assert ( - 'RUN pip install -r "/app/agents/agent/requirements.txt"' - in dockerfile_content - ) - else: - assert "RUN pip install -r" not in dockerfile_content - - assert ( - "--allow_origins=http://localhost:3000,https://my-app.com" - in dockerfile_content - ) - - # 3. Assert that the gcloud command was constructed correctly - assert len(run_recorder.calls) == 1 - gcloud_args = run_recorder.get_last_call_args()[0] - - expected_gcloud_command = [ - "gcloud", - "run", - "deploy", - "svc", - "--source", - str(tmp_path), - "--project", - "proj", - "--region", - "asia-northeast1", - "--port", - "8080", - "--verbosity", - "info", - "--labels", - "created-by=adk", - ] - assert gcloud_args == expected_gcloud_command - - # 4. Assert cleanup was performed - assert str(rmtree_recorder.get_last_call_args()[0]) == str(tmp_path) - - -def test_to_cloud_run_cleans_temp_dir( - monkeypatch: pytest.MonkeyPatch, - agent_dir: Callable[[bool], Path], -) -> None: - """`to_cloud_run` should always delete the temporary folder on exit.""" - tmp_dir = Path(tempfile.mkdtemp()) - src_dir = agent_dir(False, False) - - deleted: Dict[str, Path] = {} - - def _fake_rmtree(path: str | Path, *a: Any, **k: Any) -> None: - deleted["path"] = Path(path) - - monkeypatch.setattr(cli_deploy.shutil, "rmtree", _fake_rmtree) - monkeypatch.setattr(subprocess, "run", _Recorder()) - - cli_deploy.to_cloud_run( - agent_folder=str(src_dir), - project="proj", - region=None, - service_name="svc", - app_name="app", - temp_folder=str(tmp_dir), - port=8080, - trace_to_cloud=False, - with_ui=False, - log_level="info", - verbosity="info", - adk_version="1.0.0", - session_service_uri=None, - artifact_service_uri=None, - memory_service_uri=None, - ) - - assert deleted["path"] == tmp_dir - - -def test_to_cloud_run_cleans_temp_dir_on_failure( - monkeypatch: pytest.MonkeyPatch, - agent_dir: Callable[[bool, bool], Path], -) -> None: - """`to_cloud_run` should always delete the temporary folder on exit, even if gcloud fails.""" - tmp_dir = Path(tempfile.mkdtemp()) - src_dir = agent_dir(False, False) - - rmtree_recorder = _Recorder() - monkeypatch.setattr(shutil, "rmtree", rmtree_recorder) - # Make the gcloud command fail - monkeypatch.setattr( - subprocess, - "run", - mock.Mock(side_effect=subprocess.CalledProcessError(1, "gcloud")), - ) - - with pytest.raises(subprocess.CalledProcessError): - cli_deploy.to_cloud_run( - agent_folder=str(src_dir), - project="proj", - region="us-central1", - service_name="svc", - app_name="app", - temp_folder=str(tmp_dir), - port=8080, - trace_to_cloud=False, - with_ui=False, - log_level="info", - verbosity="info", - adk_version="1.0.0", - session_service_uri=None, - artifact_service_uri=None, - memory_service_uri=None, - ) - - # Check that rmtree was called on the temp folder in the finally block - assert rmtree_recorder.calls, "shutil.rmtree should have been called" - assert str(rmtree_recorder.get_last_call_args()[0]) == str(tmp_dir) - - -@pytest.mark.usefixtures("mock_vertex_ai") -@pytest.mark.parametrize("has_reqs", [True, False]) -@pytest.mark.parametrize("has_env", [True, False]) -def test_to_agent_engine_happy_path( - monkeypatch: pytest.MonkeyPatch, - agent_dir: Callable[[bool, bool], Path], - tmp_path: Path, - has_reqs: bool, - has_env: bool, -) -> None: - """ - Tests the happy path for the `to_agent_engine` function. - - Verifies: - 1. Source files are copied. - 2. `adk_app.py` is created correctly. - 3. `requirements.txt` is handled (created if not present). - 4. `.env` file is read if present. - 5. `vertexai.init` and `agent_engines.create` are called with the correct args. - 6. Cleanup is performed. - """ - src_dir = agent_dir(has_reqs, has_env) - temp_folder = tmp_path / "build" - app_name = src_dir.name - rmtree_recorder = _Recorder() - - monkeypatch.setattr(shutil, "rmtree", rmtree_recorder) - - # Execute - cli_deploy.to_agent_engine( - agent_folder=str(src_dir), - temp_folder=str(temp_folder), - adk_app="agent_engine_app", - staging_bucket="gs://my-staging-bucket", - trace_to_cloud=True, - project="my-gcp-project", - region="us-central1", - display_name="My Test Agent", - description="A test agent.", - ) - - # 1. Verify file operations - assert (temp_folder / app_name / "agent.py").is_file() - assert (temp_folder / app_name / "__init__.py").is_file() - - # 2. Verify adk_app.py creation - adk_app_path = temp_folder / f"agent_engine_app.py" - assert adk_app_path.is_file() - content = adk_app_path.read_text() - assert f"from {app_name}.agent import root_agent" in content - assert "adk_app = AdkApp(" in content - assert "enable_tracing=True" in content - - # 3. Verify requirements handling - reqs_path = temp_folder / app_name / "requirements.txt" - assert reqs_path.is_file() - if not has_reqs: - # It should have been created with the default content - assert "google-cloud-aiplatform[adk,agent_engines]" in reqs_path.read_text() - - # 4. Verify Vertex AI SDK calls - vertexai = sys.modules["vertexai"] - vertexai.init.assert_called_once_with( - project="my-gcp-project", - location="us-central1", - staging_bucket="gs://my-staging-bucket", - ) - - # 5. Verify env var handling - dotenv = sys.modules["dotenv"] - if has_env: - dotenv.dotenv_values.assert_called_once() - expected_env_vars = {"FILE_VAR": "value"} - else: - dotenv.dotenv_values.assert_not_called() - expected_env_vars = None - - # 6. Verify agent_engines.create call - vertexai.agent_engines.create.assert_called_once() - create_kwargs = vertexai.agent_engines.create.call_args.kwargs - assert create_kwargs["agent_engine"] == "mock-agent-engine-object" - assert create_kwargs["display_name"] == "My Test Agent" - assert create_kwargs["description"] == "A test agent." - assert create_kwargs["requirements"] == str(reqs_path) - assert create_kwargs["extra_packages"] == [str(temp_folder)] - assert create_kwargs["env_vars"] == expected_env_vars - - # 7. Verify cleanup - assert str(rmtree_recorder.get_last_call_args()[0]) == str(temp_folder) actual = cli_deploy._get_service_option_by_adk_version( adk_version=adk_version, session_uri=session_uri, @@ -478,109 +188,6 @@ def test_to_agent_engine_happy_path( assert actual.rstrip() == expected.rstrip() -@pytest.mark.usefixtures("mock_vertex_ai") -@pytest.mark.parametrize("has_reqs", [True, False]) -@pytest.mark.parametrize("has_env", [True, False]) -def test_to_agent_engine_happy_path_custom_file( - monkeypatch: pytest.MonkeyPatch, - agent_dir: Callable[[bool, bool], Path], - tmp_path: Path, - has_reqs: bool, - has_env: bool, -) -> None: - """ - Tests the happy path for the `to_agent_engine` function. - - Verifies: - 1. Source files are copied. - 2. `adk_app.py` is created correctly. - 3. `requirements.txt` is handled (created if not present). - 4. `.env` file is read if present. - 5. `vertexai.init` and `agent_engines.create` are called with the correct args. - 6. Cleanup is performed. - """ - src_dir = agent_dir(has_reqs, has_env) - temp_folder = tmp_path / "build" - app_name = src_dir.name - rmtree_recorder = _Recorder() - - monkeypatch.setattr(shutil, "rmtree", rmtree_recorder) - # Create a dummy adk_app.py file in the temp_folder - adk_app_content = """ - from test.agent import root_agent - from vertexai.preview.reasoning_engines import AdkApp - - adk_app = AdkApp( - agent=root_agent, - enable_tracing=True, - ) - """ - (src_dir / "my_adk_app.py").write_text(adk_app_content) - - # Execute - cli_deploy.to_agent_engine( - agent_folder=str(src_dir), - temp_folder=str(temp_folder), - adk_app="my_adk_app", - staging_bucket="gs://my-staging-bucket", - trace_to_cloud=True, - project="my-gcp-project", - region="us-central1", - display_name="My Test Agent", - description="A test agent.", - ) - - # 1. Verify file operations - assert (temp_folder / app_name / "agent.py").is_file() - assert (temp_folder / app_name / "__init__.py").is_file() - assert (temp_folder / "my_adk_app.py").is_file() - # 2. Verify adk_app.py creation - adk_app_path = temp_folder / "my_adk_app.py" - assert adk_app_path.is_file() - content = adk_app_path.read_text() - assert f"from test.agent import root_agent" in content - assert f"from agent.agent import root_agent" not in content - assert "adk_app = AdkApp(" in content - assert "enable_tracing=True" in content - - # 3. Verify requirements handling - reqs_path = temp_folder / app_name / "requirements.txt" - assert reqs_path.is_file() - if not has_reqs: - # It should have been created with the default content - assert "google-cloud-aiplatform[adk,agent_engines]" in reqs_path.read_text() - - # 4. Verify Vertex AI SDK calls - vertexai = sys.modules["vertexai"] - vertexai.init.assert_called_once_with( - project="my-gcp-project", - location="us-central1", - staging_bucket="gs://my-staging-bucket", - ) - - # 5. Verify env var handling - dotenv = sys.modules["dotenv"] - if has_env: - dotenv.dotenv_values.assert_called_once() - expected_env_vars = {"FILE_VAR": "value"} - else: - dotenv.dotenv_values.assert_not_called() - expected_env_vars = None - - # 6. Verify agent_engines.create call - vertexai.agent_engines.create.assert_called_once() - create_kwargs = vertexai.agent_engines.create.call_args.kwargs - assert create_kwargs["agent_engine"] == "mock-agent-engine-object" - assert create_kwargs["display_name"] == "My Test Agent" - assert create_kwargs["description"] == "A test agent." - assert create_kwargs["requirements"] == str(reqs_path) - assert create_kwargs["extra_packages"] == [str(temp_folder)] - assert create_kwargs["env_vars"] == expected_env_vars - - # 7. Verify cleanup - assert str(rmtree_recorder.get_last_call_args()[0]) == str(temp_folder) - - @pytest.mark.parametrize("include_requirements", [True, False]) def test_to_gke_happy_path( monkeypatch: pytest.MonkeyPatch, @@ -681,4 +288,4 @@ def mock_subprocess_run(*args, **kwargs): assert "type: LoadBalancer" in yaml_content # 4. Verify cleanup - assert str(rmtree_recorder.get_last_call_args()[0]) == str(tmp_path) + assert str(rmtree_recorder.get_last_call_args()[0]) == str(tmp_path) \ No newline at end of file diff --git a/tests/unittests/sessions/test_vertex_ai_session_service.py b/tests/unittests/sessions/test_vertex_ai_session_service.py index fd339a361d..14d2b15b6e 100644 --- a/tests/unittests/sessions/test_vertex_ai_session_service.py +++ b/tests/unittests/sessions/test_vertex_ai_session_service.py @@ -33,7 +33,6 @@ from google.api_core import exceptions as api_core_exceptions from google.genai import types as genai_types import pytest -import this MOCK_SESSION_JSON_1 = { 'name': ( From 24847ab8c7738b9d9143084767ea2c4378475691 Mon Sep 17 00:00:00 2001 From: netvinod Date: Thu, 4 Dec 2025 21:00:11 -0600 Subject: [PATCH 3/3] fix: run autoformat.sh --- contributing/samples/gepa/experiment.py | 1 - contributing/samples/gepa/run_experiment.py | 1 - src/google/adk/cli/cli_deploy.py | 6 +++--- src/google/adk/cli/cli_tools_click.py | 3 ++- tests/unittests/cli/utils/test_cli_deploy.py | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/contributing/samples/gepa/experiment.py b/contributing/samples/gepa/experiment.py index 2f5d03a772..f68b349d9c 100644 --- a/contributing/samples/gepa/experiment.py +++ b/contributing/samples/gepa/experiment.py @@ -43,7 +43,6 @@ from tau_bench.types import EnvRunResult from tau_bench.types import RunConfig import tau_bench_agent as tau_bench_agent_lib - import utils diff --git a/contributing/samples/gepa/run_experiment.py b/contributing/samples/gepa/run_experiment.py index cfd850b3a3..1bc4ee58c8 100644 --- a/contributing/samples/gepa/run_experiment.py +++ b/contributing/samples/gepa/run_experiment.py @@ -25,7 +25,6 @@ from absl import flags import experiment from google.genai import types - import utils _OUTPUT_DIR = flags.DEFINE_string( diff --git a/src/google/adk/cli/cli_deploy.py b/src/google/adk/cli/cli_deploy.py index 46b700b2f9..e2c47770f3 100644 --- a/src/google/adk/cli/cli_deploy.py +++ b/src/google/adk/cli/cli_deploy.py @@ -866,7 +866,7 @@ def to_agent_engine( click.echo(f'Using adk_app: {adk_app}') - if not os.path.exists(os.path.join(agent_src_path,f"{adk_app}.py")): + if not os.path.exists(os.path.join(agent_src_path, f'{adk_app}.py')): adk_app_file = os.path.join(temp_folder, f'{adk_app}.py') with open(adk_app_file, 'w', encoding='utf-8') as f: f.write( @@ -877,7 +877,7 @@ def to_agent_engine( ) click.echo(f'Created {adk_app_file}') else: - shutil.copy(os.path.join(agent_src_path,f"{adk_app}.py"), temp_folder) + shutil.copy(os.path.join(agent_src_path, f'{adk_app}.py'), temp_folder) click.echo(f'Using existing {adk_app}.py') is_config_agent = False @@ -1167,4 +1167,4 @@ def to_gke( shutil.rmtree(temp_folder) click.secho( '\nšŸŽ‰ Deployment to GKE finished successfully!', fg='cyan', bold=True - ) \ No newline at end of file + ) diff --git a/src/google/adk/cli/cli_tools_click.py b/src/google/adk/cli/cli_tools_click.py index 51a14e9cb7..1b9411bba6 100644 --- a/src/google/adk/cli/cli_tools_click.py +++ b/src/google/adk/cli/cli_tools_click.py @@ -1582,7 +1582,8 @@ def cli_deploy_cloud_run( type=str, default="agent_engine_app", help=( - "Optional. The module name (without .py) for the Python file defining the ADK Application (default: 'agent_engine_app')." + "Optional. The module name (without .py) for the Python file defining" + " the ADK Application (default: 'agent_engine_app')." ), ) @click.option( diff --git a/tests/unittests/cli/utils/test_cli_deploy.py b/tests/unittests/cli/utils/test_cli_deploy.py index e0110bb9e9..696344eb44 100644 --- a/tests/unittests/cli/utils/test_cli_deploy.py +++ b/tests/unittests/cli/utils/test_cli_deploy.py @@ -288,4 +288,4 @@ def mock_subprocess_run(*args, **kwargs): assert "type: LoadBalancer" in yaml_content # 4. Verify cleanup - assert str(rmtree_recorder.get_last_call_args()[0]) == str(tmp_path) \ No newline at end of file + assert str(rmtree_recorder.get_last_call_args()[0]) == str(tmp_path)