-
Notifications
You must be signed in to change notification settings - Fork 221
322 lines (287 loc) · 12.1 KB
/
tests.yml
File metadata and controls
322 lines (287 loc) · 12.1 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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
---
name: Run tests
on:
push:
branches: [main]
pull_request:
branches: ['**']
permissions:
contents: write
pull-requests: write
jobs:
sdk-tests:
runs-on: blacksmith-2vcpu-ubuntu-2404
steps:
- name: Checkout
uses: actions/checkout@v5
with: {fetch-depth: 0}
- name: Detect sdk changes
id: changed
uses: tj-actions/changed-files@v47
with:
files: |
openhands-sdk/**
tests/sdk/**
pyproject.toml
uv.lock
.github/workflows/tests.yml
- name: Install uv
if: steps.changed.outputs.any_changed == 'true'
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
python-version: '3.13'
- name: Install deps
if: steps.changed.outputs.any_changed == 'true'
run: uv sync --frozen --group dev
- name: Check for openhands.tools imports in sdk tests
if: steps.changed.outputs.any_changed == 'true'
run: |
echo "Checking for openhands.tools imports in tests/sdk..."
if grep -r "from openhands\.tools" tests/sdk/ || grep -r "import openhands\.tools" tests/sdk/; then
echo "ERROR: Found openhands.tools imports in tests/sdk/"
echo "SDK tests should only import from openhands.sdk"
echo "Please move tests that use openhands.tools to tests/cross/"
exit 1
fi
echo "✓ No openhands.tools imports found in tests/sdk/"
- name: Run sdk tests with coverage
if: steps.changed.outputs.any_changed == 'true'
run: |
# Clean up any existing coverage file
rm -f .coverage
# Use pytest-xdist (-n auto) for parallel execution with proper
# coverage collection. --forked prevents coverage from child processes.
CI=true uv run python -m pytest -vvs \
-n auto \
--cov=openhands-sdk \
--cov-report=term-missing \
--cov-fail-under=0 \
--cov-config=pyproject.toml \
tests/sdk
# Rename coverage file for upload
if [ -f .coverage ]; then
mv .coverage coverage-sdk.dat
echo "SDK coverage file prepared for upload"
fi
- name: Upload sdk coverage
if: steps.changed.outputs.any_changed == 'true' && always()
uses: actions/upload-artifact@v5
with:
name: coverage-sdk
path: coverage-sdk.dat
if-no-files-found: warn
tools-tests:
runs-on: blacksmith-2vcpu-ubuntu-2404
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v5
with: {fetch-depth: 0}
- name: Detect tools changes
id: changed
uses: tj-actions/changed-files@v47
with:
files: |
openhands-tools/**
tests/tools/**
pyproject.toml
uv.lock
.github/workflows/tests.yml
- name: Install uv
if: steps.changed.outputs.any_changed == 'true'
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
python-version: '3.13'
- name: Install deps
if: steps.changed.outputs.any_changed == 'true'
run: uv sync --frozen --group dev
- name: Run tools tests with coverage
if: steps.changed.outputs.any_changed == 'true'
run: |
# Clean up any existing coverage file
rm -f .coverage
# Use --forked for tools tests due to terminal test conflicts
# when running in parallel (shared /tmp paths, subprocess management)
CI=true uv run python -m pytest -vvs \
--forked \
--cov=openhands-tools \
--cov-report=term-missing \
--cov-fail-under=0 \
--cov-config=pyproject.toml \
tests/tools
# Rename coverage file for upload
if [ -f .coverage ]; then
mv .coverage coverage-tools.dat
echo "Tools coverage file prepared for upload"
fi
- name: Upload tools coverage
if: steps.changed.outputs.any_changed == 'true' && always()
uses: actions/upload-artifact@v5
with:
name: coverage-tools
path: coverage-tools.dat
if-no-files-found: warn
agent-server-tests:
runs-on: blacksmith-2vcpu-ubuntu-2404
steps:
- name: Checkout
uses: actions/checkout@v5
with: {fetch-depth: 0}
- name: Detect Agent Server changes
id: changed
uses: tj-actions/changed-files@v47
with:
files: |
openhands-agent-server/**
tests/agent_server/**
pyproject.toml
uv.lock
.github/workflows/tests.yml
- name: Install uv
if: steps.changed.outputs.any_changed == 'true'
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
python-version: '3.13'
- name: Install deps
if: steps.changed.outputs.any_changed == 'true'
run: uv sync --frozen --group dev
- name: Run Agent Server tests with coverage
if: steps.changed.outputs.any_changed == 'true'
run: |
# Clean up any existing coverage file
rm -f .coverage
# Use pytest-xdist (-n auto) for parallel execution with proper
# coverage collection. --forked prevents coverage from child processes.
CI=true uv run python -m pytest -vvs \
-n auto \
--cov=openhands-agent-server \
--cov-report=term-missing \
--cov-fail-under=0 \
--cov-config=pyproject.toml \
tests/agent_server
# Rename coverage file for upload
if [ -f .coverage ]; then
mv .coverage coverage-agent-server.dat
echo "Agent Server coverage file prepared for upload"
fi
- name: Upload Agent Server coverage
if: steps.changed.outputs.any_changed == 'true' && always()
uses: actions/upload-artifact@v5
with:
name: coverage-agent-server
path: coverage-agent-server.dat
if-no-files-found: warn
cross-tests:
runs-on: blacksmith-2vcpu-ubuntu-2404
steps:
- name: Checkout
uses: actions/checkout@v5
with: {fetch-depth: 0}
- name: Detect cross changes
id: changed
uses: tj-actions/changed-files@v47
with:
files: |
tests/**
openhands/**
pyproject.toml
uv.lock
.github/workflows/tests.yml
- name: Install uv
if: steps.changed.outputs.any_changed == 'true'
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
python-version: '3.13'
- name: Install deps
if: steps.changed.outputs.any_changed == 'true'
run: uv sync --frozen --group dev
- name: Run cross tests with coverage
if: steps.changed.outputs.any_changed == 'true'
run: |
# Clean up any existing coverage file
rm -f .coverage
CI=true uv run python -m pytest -vvs \
--basetemp="${{ runner.temp }}/pytest" \
-o tmp_path_retention=none \
-o tmp_path_retention_count=0 \
--cov=openhands \
--cov-report=term-missing \
--cov-fail-under=0 \
--cov-config=pyproject.toml \
tests/cross
# Rename coverage file for upload
if [ -f .coverage ]; then
mv .coverage coverage-cross.dat
echo "Cross coverage file prepared for upload"
fi
- name: Upload cross coverage
if: steps.changed.outputs.any_changed == 'true' && always()
uses: actions/upload-artifact@v5
with:
name: coverage-cross
path: coverage-cross.dat
if-no-files-found: warn
coverage-report:
runs-on: blacksmith-2vcpu-ubuntu-2404
needs: [sdk-tests, tools-tests, agent-server-tests, cross-tests]
if: always() && github.event_name == 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
python-version: '3.13'
- name: Install deps (for coverage CLI)
run: uv sync --frozen --group dev
- name: Download coverage artifacts
uses: actions/download-artifact@v6
with:
path: ./cov
continue-on-error: true
- name: Combine coverage data
run: |
shopt -s nullglob
# For some reason, the github action won't properly upload the original
# .converage* files
# Convert uploaded .dat files back to .coverage format for coverage tool
for dat_file in cov/**/coverage-*.dat; do
if [[ "$dat_file" == *coverage-sdk.dat ]]; then
cp "$dat_file" .coverage.sdk
elif [[ "$dat_file" == *coverage-tools.dat ]]; then
cp "$dat_file" .coverage.tools
elif [[ "$dat_file" == *coverage-agent-server.dat ]]; then
cp "$dat_file" .coverage.agent-server
elif [[ "$dat_file" == *coverage-cross.dat ]]; then
cp "$dat_file" .coverage.cross
fi
done
# Check if we have any coverage files
coverage_files=(.coverage.*)
if [ ${#coverage_files[@]} -eq 0 ]; then
echo "No coverage files found; skipping combined report."
exit 0
fi
echo "Found ${#coverage_files[@]} coverage files"
uv run coverage combine
uv run coverage xml -i -o coverage.xml
uv run coverage report -m
- name: Pytest coverage PR comment
if: always()
continue-on-error: true
uses: MishaKav/pytest-coverage-comment@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
pytest-xml-coverage-path: coverage.xml
title: Coverage Report
create-new-comment: false
hide-report: false
xml-skip-covered: true
report-only-changed-files: true
remove-links-to-files: true
remove-links-to-lines: true