From f9d97effd7a1a6d8123eb3569118d7ee9c2ce1e0 Mon Sep 17 00:00:00 2001 From: Dylan Snyder <114695692+dylan-apex@users.noreply.github.com> Date: Wed, 21 Jan 2026 12:47:23 -0600 Subject: [PATCH 1/4] chore: add unit test bash script --- CONTRIBUTING.md | 18 +++++++++++++++++ unittests.sh | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100755 unittests.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c620c8ab96..07907ef946 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -188,6 +188,24 @@ part before or alongside your code PR. pytest ./tests/unittests ``` + **Alternatively**, use the included `unittests.sh` script which handles + environment setup and restoration automatically: + + ```shell + ./unittests.sh + ``` + + This script will: + - Set up the test environment with minimal dependencies (`test`, `eval`, `a2a`) + - Run the unit tests + - Restore the full development environment (`--all-extras`) + + To also run auto-formatting after successful tests: + + ```shell + ./unittests.sh format + ``` + 6. **Auto-format the code:** **NOTE**: We use `isort` and `pyink` for styles. Use the included diff --git a/unittests.sh b/unittests.sh new file mode 100755 index 0000000000..5a4f89c0ad --- /dev/null +++ b/unittests.sh @@ -0,0 +1,51 @@ +#!/bin/bash +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# Runs all unit tests for adk codebase. Sets up dev environment re: Contributing.md +# Usage: ./unittests.sh [format] +# format - Optional argument to run autoformat.sh if tests pass + +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "$SCRIPT_DIR" + +RUN_FORMAT=false +if [[ "$1" == "format" ]]; then + RUN_FORMAT=true +fi + +echo "Setting up test environment..." +uv sync --extra test --extra eval --extra a2a + +echo "Running unit tests..." +TEST_EXIT_CODE=0 +pytest ./tests/unittests || TEST_EXIT_CODE=$? + +echo "Restoring full development environment..." +uv sync --all-extras + +if [[ $TEST_EXIT_CODE -ne 0 ]]; then + echo "Unit tests failed with exit code $TEST_EXIT_CODE" + exit $TEST_EXIT_CODE +fi + +echo "Unit tests passed!" + +if [[ "$RUN_FORMAT" == "true" ]]; then + echo "Running autoformat..." + ./autoformat.sh +fi From abd17007b423a4eb89f25fd39a0d12c88026f83c Mon Sep 17 00:00:00 2001 From: Dylan <114695692+dylan-apex@users.noreply.github.com> Date: Wed, 21 Jan 2026 12:58:44 -0600 Subject: [PATCH 2/4] Update unittests.sh Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- unittests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittests.sh b/unittests.sh index 5a4f89c0ad..c00de158b4 100755 --- a/unittests.sh +++ b/unittests.sh @@ -24,7 +24,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" RUN_FORMAT=false -if [[ "$1" == "format" ]]; then +if [[ "${1:-}" == "format" ]]; then RUN_FORMAT=true fi From fb7ce2b148d96af2eb091dda601ea82cd22b5cfa Mon Sep 17 00:00:00 2001 From: Dylan <114695692+dylan-apex@users.noreply.github.com> Date: Wed, 21 Jan 2026 12:58:50 -0600 Subject: [PATCH 3/4] Update unittests.sh Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- unittests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittests.sh b/unittests.sh index c00de158b4..a5f11b0045 100755 --- a/unittests.sh +++ b/unittests.sh @@ -18,7 +18,7 @@ # Usage: ./unittests.sh [format] # format - Optional argument to run autoformat.sh if tests pass -set -e +set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" From c44d57b18f11cfa83a72a3b5262c81bb30e02bfb Mon Sep 17 00:00:00 2001 From: Dylan <114695692+dylan-apex@users.noreply.github.com> Date: Wed, 21 Jan 2026 12:58:59 -0600 Subject: [PATCH 4/4] Update unittests.sh Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- unittests.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/unittests.sh b/unittests.sh index a5f11b0045..4bccb85257 100755 --- a/unittests.sh +++ b/unittests.sh @@ -23,6 +23,14 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" +# Ensure the environment is restored if the script is interrupted. +cleanup_on_interrupt() { + echo -e "\nScript interrupted. Restoring full development environment..." + uv sync --all-extras + exit 130 # Standard exit code for Ctrl+C +} +trap cleanup_on_interrupt INT TERM + RUN_FORMAT=false if [[ "${1:-}" == "format" ]]; then RUN_FORMAT=true