diff --git a/.github/actions/spelling/allow.txt b/.github/actions/spelling/allow.txt index 11496c9f7..8d0b13c8c 100644 --- a/.github/actions/spelling/allow.txt +++ b/.github/actions/spelling/allow.txt @@ -63,6 +63,7 @@ Llm lstrips mikeas mockurl +mysqladmin notif oauthoidc oidc @@ -71,6 +72,7 @@ otherurl postgres POSTGRES postgresql +proot protoc pyi pypistats diff --git a/scripts/docker-compose.test.yml b/scripts/docker-compose.test.yml new file mode 100644 index 000000000..a2df936e1 --- /dev/null +++ b/scripts/docker-compose.test.yml @@ -0,0 +1,29 @@ +services: + postgres: + image: postgres:15-alpine + environment: + POSTGRES_USER: a2a + POSTGRES_PASSWORD: a2a_password + POSTGRES_DB: a2a_test + ports: + - "5432:5432" + healthcheck: + test: ["CMD-SHELL", "pg_isready"] + interval: 10s + timeout: 5s + retries: 5 + + mysql: + image: mysql:8.0 + environment: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: a2a_test + MYSQL_USER: a2a + MYSQL_PASSWORD: a2a_password + ports: + - "3306:3306" + healthcheck: + test: ["CMD-SHELL", "mysqladmin ping -h localhost -u root -proot"] + interval: 10s + timeout: 5s + retries: 5 diff --git a/scripts/run_integration_tests.sh b/scripts/run_integration_tests.sh new file mode 100755 index 000000000..5b9767136 --- /dev/null +++ b/scripts/run_integration_tests.sh @@ -0,0 +1,102 @@ +#!/bin/bash +set -e + +# Get the directory of this script +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" + +# Docker compose file path +COMPOSE_FILE="$SCRIPT_DIR/docker-compose.test.yml" + +# Initialize variables +DEBUG_MODE=false +STOP_MODE=false +SERVICES=() +PYTEST_ARGS=() + +# Parse arguments +while [[ $# -gt 0 ]]; do + case $1 in + --debug) + DEBUG_MODE=true + shift + ;; + --stop) + STOP_MODE=true + shift + ;; + --postgres) + SERVICES+=("postgres") + shift + ;; + --mysql) + SERVICES+=("mysql") + shift + ;; + *) + # Preserve other arguments for pytest + PYTEST_ARGS+=("$1") + shift + ;; + esac +done + +# Handle --stop +if [[ "$STOP_MODE" == "true" ]]; then + echo "Stopping test databases..." + docker compose -f "$COMPOSE_FILE" down + exit 0 +fi + +# Default to running both databases if none specified +if [[ ${#SERVICES[@]} -eq 0 ]]; then + SERVICES=("postgres" "mysql") +fi + +# Cleanup function to stop docker containers +cleanup() { + echo "Stopping test databases..." + docker compose -f "$COMPOSE_FILE" down +} + +# Start the databases +echo "Starting/Verifying databases: ${SERVICES[*]}..." +docker compose -f "$COMPOSE_FILE" up -d --wait "${SERVICES[@]}" + +# Set up environment variables based on active services +# Only export DSNs for started services so tests skip missing ones +for service in "${SERVICES[@]}"; do + if [[ "$service" == "postgres" ]]; then + export POSTGRES_TEST_DSN="postgresql+asyncpg://a2a:a2a_password@localhost:5432/a2a_test" + elif [[ "$service" == "mysql" ]]; then + export MYSQL_TEST_DSN="mysql+aiomysql://a2a:a2a_password@localhost:3306/a2a_test" + fi +done + +# Handle --debug mode +if [[ "$DEBUG_MODE" == "true" ]]; then + echo "---------------------------------------------------" + echo "Debug mode enabled. Databases are running." + echo "You can connect to them using the following DSNs." + echo "" + echo "Run the following commands to set up your environment:" + echo "" + [[ -n "$POSTGRES_TEST_DSN" ]] && echo "export POSTGRES_TEST_DSN=\"$POSTGRES_TEST_DSN\"" + [[ -n "$MYSQL_TEST_DSN" ]] && echo "export MYSQL_TEST_DSN=\"$MYSQL_TEST_DSN\"" + echo "" + echo "---------------------------------------------------" + echo "Run ./scripts/run_integration_tests.sh --stop to shut databases down." + exit 0 +fi + +# Register cleanup trap for normal test run +trap cleanup EXIT + +# Run the tests +echo "Running integration tests..." +cd "$PROJECT_ROOT" + +uv run --extra all pytest -v \ + tests/server/tasks/test_database_task_store.py \ + tests/server/tasks/test_database_push_notification_config_store.py \ + "${PYTEST_ARGS[@]}"