Skip to content

Commit 49e923d

Browse files
ashwin-antclaude
andcommitted
Add Docker-based test infrastructure for e2e tests
Add Docker test infrastructure to catch container-specific issues like #406 where filesystem-based agents may silently fail in Docker environments. Changes: - Add Dockerfile.test: Python 3.12 image with Claude Code CLI installed - Add scripts/test-docker.sh: Local script to run tests in Docker - Add test-e2e-docker job to CI workflow - Add .dockerignore to speed up Docker builds Usage: ./scripts/test-docker.sh unit # Run unit tests in Docker ./scripts/test-docker.sh e2e # Run e2e tests (needs ANTHROPIC_API_KEY) ./scripts/test-docker.sh all # Run all tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 904c2ec commit 49e923d

File tree

4 files changed

+173
-0
lines changed

4 files changed

+173
-0
lines changed

.dockerignore

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Git
2+
.git
3+
.gitignore
4+
5+
# Python
6+
__pycache__
7+
*.py[cod]
8+
*$py.class
9+
*.so
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
27+
# Virtual environments
28+
.env
29+
.venv
30+
env/
31+
venv/
32+
ENV/
33+
34+
# IDE
35+
.idea/
36+
.vscode/
37+
*.swp
38+
*.swo
39+
40+
# Testing/Coverage
41+
.coverage
42+
.pytest_cache/
43+
htmlcov/
44+
.tox/
45+
.nox/
46+
47+
# Misc
48+
*.log
49+
.DS_Store

.github/workflows/test.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,24 @@ jobs:
8181
run: |
8282
python -m pytest e2e-tests/ -v -m e2e
8383
84+
test-e2e-docker:
85+
runs-on: ubuntu-latest
86+
needs: test # Run after unit tests pass
87+
# Run e2e tests in Docker to catch container-specific issues like #406
88+
89+
steps:
90+
- uses: actions/checkout@v4
91+
92+
- name: Build Docker test image
93+
run: docker build -f Dockerfile.test -t claude-sdk-test .
94+
95+
- name: Run e2e tests in Docker
96+
env:
97+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
98+
run: |
99+
docker run --rm -e ANTHROPIC_API_KEY \
100+
claude-sdk-test python -m pytest e2e-tests/ -v -m e2e
101+
84102
test-examples:
85103
runs-on: ubuntu-latest
86104
needs: test-e2e # Run after e2e tests

Dockerfile.test

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Dockerfile for running SDK tests in a containerized environment
2+
# This helps catch Docker-specific issues like #406
3+
4+
FROM python:3.12-slim
5+
6+
# Install dependencies for Claude CLI and git (needed for some tests)
7+
RUN apt-get update && apt-get install -y \
8+
curl \
9+
git \
10+
&& rm -rf /var/lib/apt/lists/*
11+
12+
# Install Claude Code CLI
13+
RUN curl -fsSL https://claude.ai/install.sh | bash
14+
ENV PATH="/root/.local/bin:$PATH"
15+
16+
# Set up working directory
17+
WORKDIR /app
18+
19+
# Copy the SDK source
20+
COPY . .
21+
22+
# Install SDK with dev dependencies
23+
RUN pip install -e ".[dev]"
24+
25+
# Verify CLI installation
26+
RUN claude -v
27+
28+
# Default: run unit tests
29+
CMD ["python", "-m", "pytest", "tests/", "-v"]

scripts/test-docker.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
# Run SDK tests in a Docker container
3+
# This helps catch Docker-specific issues like #406
4+
#
5+
# Usage:
6+
# ./scripts/test-docker.sh [unit|e2e|all]
7+
#
8+
# Examples:
9+
# ./scripts/test-docker.sh unit # Run unit tests only
10+
# ANTHROPIC_API_KEY=sk-... ./scripts/test-docker.sh e2e # Run e2e tests
11+
# ANTHROPIC_API_KEY=sk-... ./scripts/test-docker.sh all # Run all tests
12+
13+
set -e
14+
15+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16+
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
17+
18+
cd "$PROJECT_DIR"
19+
20+
usage() {
21+
echo "Usage: $0 [unit|e2e|all]"
22+
echo ""
23+
echo "Commands:"
24+
echo " unit - Run unit tests only (no API key needed)"
25+
echo " e2e - Run e2e tests (requires ANTHROPIC_API_KEY)"
26+
echo " all - Run both unit and e2e tests"
27+
echo ""
28+
echo "Examples:"
29+
echo " $0 unit"
30+
echo " ANTHROPIC_API_KEY=sk-... $0 e2e"
31+
exit 1
32+
}
33+
34+
echo "Building Docker test image..."
35+
docker build -f Dockerfile.test -t claude-sdk-test .
36+
37+
case "${1:-unit}" in
38+
unit)
39+
echo ""
40+
echo "Running unit tests in Docker..."
41+
docker run --rm claude-sdk-test \
42+
python -m pytest tests/ -v
43+
;;
44+
e2e)
45+
if [ -z "$ANTHROPIC_API_KEY" ]; then
46+
echo "Error: ANTHROPIC_API_KEY environment variable is required for e2e tests"
47+
echo ""
48+
echo "Usage: ANTHROPIC_API_KEY=sk-... $0 e2e"
49+
exit 1
50+
fi
51+
echo ""
52+
echo "Running e2e tests in Docker..."
53+
docker run --rm -e ANTHROPIC_API_KEY \
54+
claude-sdk-test python -m pytest e2e-tests/ -v -m e2e
55+
;;
56+
all)
57+
echo ""
58+
echo "Running unit tests in Docker..."
59+
docker run --rm claude-sdk-test \
60+
python -m pytest tests/ -v
61+
62+
echo ""
63+
if [ -n "$ANTHROPIC_API_KEY" ]; then
64+
echo "Running e2e tests in Docker..."
65+
docker run --rm -e ANTHROPIC_API_KEY \
66+
claude-sdk-test python -m pytest e2e-tests/ -v -m e2e
67+
else
68+
echo "Skipping e2e tests (ANTHROPIC_API_KEY not set)"
69+
fi
70+
;;
71+
*)
72+
usage
73+
;;
74+
esac
75+
76+
echo ""
77+
echo "Done!"

0 commit comments

Comments
 (0)