10000 feat: Add support for installing OS level agent dependencies via requirements.sh by runa · Pull Request #1524 · google/adk-python · GitHub
[go: up one dir, main page]

Skip to content

feat: Add support for installing OS level agent dependencies via requirements.sh #1524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: Add test for requirements.sh in cli_deploy
This commit introduces a new test case for the `to_cloud_run` function in `cli_deploy.py`.

The new test, `test_to_cloud_run_with_requirements_sh`, specifically verifies that if a `requirements.sh` file is present in my source directory, the generated Dockerfile includes a command to execute this script.

The `agent_dir` fixture has been updated to support the creation of a dummy `requirements.sh` file for testing purposes.
  • Loading branch information
google-labs-jules[bot] committed Jun 19, 2025
commit 7356270962dd4464a519b413f84db4e4572a22a7
70 changes: 64 additions & 6 deletions tests/unittests/cli/utils/test_cli_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,24 @@ def _mute_click(monkeypatch: pytest.MonkeyPatch) -> None:


@pytest.fixture()
def agent_dir(tmp_path: Path) -> Callable[[bool], Path]:
def agent_dir(
tmp_path: Path,
) -> Callable[[bool, bool], Path]:
"""Return a factory that creates a dummy agent directory tree."""

def _factory(include_requirements: bool) -> Path:
def _factory(
include_requirements: bool, include_requirements_sh: bool = False
) -> Path:
base = tmp_path / "agent"
base.mkdir()
(base / "agent.py").write_text("# dummy agent")
(base / "__init__.py").touch()
if include_requirements:
(base / "requirements.txt").write_text("pytest\n")
if include_requirements_sh:
(base / "requirements.sh").write_text(
'echo "Hello from requirements.sh"\n'
)
return base

return _factory
Expand Down Expand Up @@ -124,17 +132,19 @@ def test_get_service_option_by_adk_version() -> None:

# to_cloud_run
@pytest.mark.parametrize("include_requirements", [True, False])
@pytest.mark.parametrize("include_requirements_sh", [True, False])
def test_to_cloud_run_happy_path(
monkeypatch: pytest.MonkeyPatch,
agent_dir: Callable[[bool], Path],
agent_dir: Callable[[bool, bool], Path],
include_requirements: bool,
include_requirements_sh: bool,
) -> None:
"""
End-to-end execution test for `to_cloud_run` covering both presence and
absence of *requirements.txt*.
"""
tmp_dir = Path(tempfile.mkdtemp())
src_dir = agent_dir(include_requirements)
src_dir = agent_dir(include_requirements, include_requirements_sh)

copy_recorder = _Recorder()
run_recorder = _Recorder()
Expand Down Expand Up @@ -179,13 +189,61 @@ def _recording_copytree(*args: Any, **kwargs: Any):
shutil.rmtree(tmp_dir, ignore_errors=True)


def test_to_cloud_run_with_requirements_sh(
monkeypatch: pytest.MonkeyPatch,
agent_dir: Callable[[bool, bool], Path],
) -> None:
"""Test that requirements.sh is executed when present."""
tmp_dir = Path(tempfile.mkdtemp())
# Create agent directory with requirements.sh
src_dir = agent_dir(include_requirements=False, include_requirements_sh=True)

run_recorder = _Recorder()

# Cache the ORIGINAL copytree before patching
original_copytree = cli_deploy.shutil.copytree

def _recording_copytree(*args: Any, **kwargs: Any):
return original_copytree(*args, **kwargs)

monkeypatch.setattr(cli_deploy.shutil, "copytree", _recording_copytree)
# Skip actual cleanup so that we can inspect generated files later.
monkeypatch.setattr(cli_deploy.shutil, "rmtree", lambda *_a, **_k: None)
monkeypatch.setattr(subprocess, "run", run_recorder)

cli_deploy.to_cloud_run(
agent_folder=str(src_dir),
project="proj",
region="asia-northeast1",
service_name="svc",
app_name="app",
temp_folder=str(tmp_dir),
port=8080,
trace_to_cloud=False, # Keep it simple for this test
with_ui=False, # Keep it simple for this test
verbosity="info",
adk_version="0.0.5", # adk_version that includes requirements.sh logic
session_service_uri=None,
artifact_service_uri=None,
memory_service_uri=None,
)

dockerfile_content = (tmp_dir / "Dockerfile").read_text()
assert "RUN sh /app/agents/app/requirements.sh" in dockerfile_content, (
"Dockerfile should contain command to run requirements.sh"
)

# Manual cleanup
shutil.rmtree(tmp_dir, ignore_errors=True)


def test_to_cloud_run_cleans_temp_dir(
monkeypatch: pytest.MonkeyPatch,
agent_dir: Callable[[bool], Path],
agent_dir: Callable[[bool, bool], Path],
) -> None:
"""`to_cloud_run` should always delete the temporary folder on exit."""
tmp_dir = Path(tempfile.mkdtemp())
src_dir = agent_dir(False)
src_dir = agent_dir(False, False)

deleted: Dict[str, Path] = {}

Expand Down
0