-
Notifications
You must be signed in to change notification settings - Fork 1.2k
217 lines (184 loc) · 7.51 KB
/
Copy pathtest.yml
File metadata and controls
217 lines (184 loc) · 7.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
name: Test
on:
pull_request:
push:
branches:
- "main"
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Run tests
run: |
python -m pytest tests/ -v --cov=claude_agent_sdk --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0 (sha-pinned)
with:
file: ./coverage.xml
fail_ci_if_error: false
test-e2e:
# Skip on forks since they can't mint the OIDC token used for Claude API auth
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
runs-on: ${{ matrix.os }}
needs: test # Run after unit tests pass
permissions:
contents: read
# Required to mint the OIDC token exchanged for a Claude API access
# token (workload identity federation)
id-token: write
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install Claude Code (Linux/macOS)
if: runner.os == 'Linux' || runner.os == 'macOS'
# `shell: bash` runs with -eo pipefail. Without pipefail the step takes
# its status from `bash`, which exits 0 on an empty script, so a failed
# `curl` leaves the CLI uninstalled and the step green.
shell: bash
run: |
curl -fsSL https://claude.ai/install.sh | bash
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install Claude Code (Windows)
if: runner.os == 'Windows'
run: |
irm https://claude.ai/install.ps1 | iex
$claudePath = "$env:USERPROFILE\.local\bin"
echo "$claudePath" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
shell: pwsh
- name: Verify Claude Code installation
run: claude -v
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Set up Claude API auth (workload identity federation)
uses: ./.github/actions/setup-claude-auth
- name: Run end-to-end tests with real API
env:
ANTHROPIC_FEDERATION_RULE_ID: ${{ vars.ANTHROPIC_FEDERATION_RULE_ID }}
ANTHROPIC_ORGANIZATION_ID: ${{ vars.ANTHROPIC_ORGANIZATION_ID }}
ANTHROPIC_SERVICE_ACCOUNT_ID: ${{ vars.ANTHROPIC_SERVICE_ACCOUNT_ID }}
run: |
python -m pytest e2e-tests/ -v -m e2e
test-e2e-docker:
# Skip on forks since they can't mint the OIDC token used for Claude API auth
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
needs: test # Run after unit tests pass
permissions:
contents: read
# Required to mint the OIDC token exchanged for a Claude API access
# token (workload identity federation)
id-token: write
# Run e2e tests in Docker to catch container-specific issues like #406
steps:
- uses: actions/checkout@v4
- name: Build Docker test image
run: docker build -f Dockerfile.test -t claude-sdk-test .
- name: Set up Claude API auth (workload identity federation)
uses: ./.github/actions/setup-claude-auth
- name: Run e2e tests in Docker
env:
ANTHROPIC_FEDERATION_RULE_ID: ${{ vars.ANTHROPIC_FEDERATION_RULE_ID }}
ANTHROPIC_ORGANIZATION_ID: ${{ vars.ANTHROPIC_ORGANIZATION_ID }}
ANTHROPIC_SERVICE_ACCOUNT_ID: ${{ vars.ANTHROPIC_SERVICE_ACCOUNT_ID }}
# Bind-mount the identity token file so the background refresher on
# the host keeps the in-container copy fresh too
run: |
docker run --rm \
-e ANTHROPIC_FEDERATION_RULE_ID \
-e ANTHROPIC_ORGANIZATION_ID \
-e ANTHROPIC_SERVICE_ACCOUNT_ID \
-e ANTHROPIC_IDENTITY_TOKEN_FILE=/run/claude-identity-token \
-v "$ANTHROPIC_IDENTITY_TOKEN_FILE:/run/claude-identity-token:ro" \
claude-sdk-test python -m pytest e2e-tests/ -v -m e2e
test-examples:
# Skip on forks since they can't mint the OIDC token used for Claude API auth
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
needs: test-e2e # Run after e2e tests
permissions:
contents: read
# Required to mint the OIDC token exchanged for a Claude API access
# token (workload identity federation)
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install Claude Code (Linux)
if: runner.os == 'Linux'
# `shell: bash` runs with -eo pipefail; see the note in the test job.
shell: bash
run: |
curl -fsSL https://claude.ai/install.sh | bash
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install Claude Code (Windows)
if: runner.os == 'Windows'
run: |
irm https://claude.ai/install.ps1 | iex
$claudePath = "$env:USERPROFILE\.local\bin"
echo "$claudePath" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
shell: pwsh
- name: Verify Claude Code installation
run: claude -v
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
- name: Set up Claude API auth (workload identity federation)
uses: ./.github/actions/setup-claude-auth
- name: Run example scripts (Linux)
if: runner.os == 'Linux'
env:
ANTHROPIC_FEDERATION_RULE_ID: ${{ vars.ANTHROPIC_FEDERATION_RULE_ID }}
ANTHROPIC_ORGANIZATION_ID: ${{ vars.ANTHROPIC_ORGANIZATION_ID }}
ANTHROPIC_SERVICE_ACCOUNT_ID: ${{ vars.ANTHROPIC_SERVICE_ACCOUNT_ID }}
PYTHONUNBUFFERED: "1"
run: |
python examples/quick_start.py
timeout 300 python examples/streaming_mode.py all
timeout 120 python examples/hooks.py PreToolUse
timeout 120 python examples/hooks.py DecisionFields
- name: Run example scripts (Windows)
if: runner.os == 'Windows'
env:
ANTHROPIC_FEDERATION_RULE_ID: ${{ vars.ANTHROPIC_FEDERATION_RULE_ID }}
ANTHROPIC_ORGANIZATION_ID: ${{ vars.ANTHROPIC_ORGANIZATION_ID }}
ANTHROPIC_SERVICE_ACCOUNT_ID: ${{ vars.ANTHROPIC_SERVICE_ACCOUNT_ID }}
PYTHONUNBUFFERED: "1"
run: |
python examples/quick_start.py
$job = Start-Job { python examples/streaming_mode.py all }
Wait-Job $job -Timeout 300 | Out-Null
Stop-Job $job
Receive-Job $job
$job = Start-Job { python examples/hooks.py PreToolUse }
Wait-Job $job -Timeout 120 | Out-Null
Stop-Job $job
Receive-Job $job
$job = Start-Job { python examples/hooks.py DecisionFields }
Wait-Job $job -Timeout 120 | Out-Null
Stop-Job $job
Receive-Job $job
shell: pwsh