Repository navigation
281 lines (238 loc) · 10.2 KB
/
Copy pathtest.yml
File metadata and controls
281 lines (238 loc) · 10.2 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
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: Confirm the newest mcp major is under test
# test-mcp-v1-floor covers mcp 1.x; this job must exercise 2.x or newer.
run: |
python -c "import importlib.metadata as m; v = m.version('mcp'); print('mcp', v); assert int(v.split('.')[0]) >= 2, v"
- 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-mcp-v1-floor:
# The main test job resolves the newest mcp the SDK allows (2.x). This one
# pins the oldest supported release so mcp 1.x support stays tested.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install dependencies with the mcp floor
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
pip install "mcp==1.23.0"
python -c "import importlib.metadata as m; v = m.version('mcp'); print('mcp', v); assert v == '1.23.0', v"
- name: Run mypy against mcp 1.x
run: |
mypy src/ scripts/
- name: Run tests
run: |
python -m pytest tests/ -v --cov=claude_agent_sdk --cov-report=xml
- name: Upload coverage to Codecov
# Merged with the main job's report, so code that only runs on one
# mcp major is counted from whichever job exercises it.
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0 (sha-pinned)
with:
file: ./coverage.xml
flags: mcp-v1-floor
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 pipeline
# takes its status from `bash`, which exits 0 on an empty script, so a
# failed `curl` shows up later as a confusing "claude: not found" in a
# different step. With it, the step that actually broke is the one that
# fails.
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
# CI's fresh checkout is an untrusted workspace, so Claude Code drops
# the project-scoped permissions.allow grants in this repo's committed
# .claude/settings.json and warns on stderr about it. Record the trust a
# developer grants via the trust dialog once, so runs launched from the
# checkout exercise the real trusted-workspace settings path. Only
# affects CLI runs whose cwd is inside the checkout (some e2e tests
# deliberately use a temp cwd). See scripts/trust_workspace.py.
- name: Trust the workspace for Claude Code
run: python scripts/trust_workspace.py
- 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
env:
# Pin the CLI's default model for the examples instead of taking the
# one the installed CLI ships with, which changes between releases.
# Same value as e2e-tests/conftest.py; see the comment there.
ANTHROPIC_DEFAULT_MODEL: claude-opus-5
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
# Same as in test-e2e: trust the fresh checkout so Claude Code honors the
# project-scoped grants in this repo's committed .claude/settings.json.
- name: Trust the workspace for Claude Code
run: python scripts/trust_workspace.py
- 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