-
Notifications
You must be signed in to change notification settings - Fork 0
512 lines (439 loc) · 16.2 KB
/
test.yml
File metadata and controls
512 lines (439 loc) · 16.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
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
name: Python SDK Tests
on:
push:
branches: [main, develop]
paths:
- 'src/**'
- 'tests/**'
- 'pyproject.toml'
- '.github/workflows/test.yml'
pull_request:
branches: [main, develop]
paths:
- 'src/**'
- 'tests/**'
- 'pyproject.toml'
- '.github/workflows/test.yml'
workflow_dispatch: # Allow manual trigger
schedule:
# Weekly mutation testing — Mondays at 03:00 UTC. The mutmut job is
# the only consumer of this trigger; other jobs ignore it via the
# `if: github.event_name == ...` guards on each job.
- cron: '0 3 * * 1'
env:
PYTHON_VERSION: '3.11'
COVERAGE_THRESHOLD: 85
jobs:
# =============================================================================
# Fast Unit Tests (< 5 minutes)
# =============================================================================
test-fast:
name: Unit Tests
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Run unit tests
run: |
# integration_sepolia is also marker-gated in pyproject.toml,
# but ignore the dir explicitly so the runner doesn't even
# collect them (saves seconds + clearer "X deselected" output).
pytest tests/ \
--ignore=tests/integration/ \
--ignore=tests/integration_sepolia/ \
--ignore=tests/benchmarks/ \
-v \
--tb=short \
-x # Stop on first failure
- name: Upload test results
uses: actions/upload-artifact@v4
if: failure()
with:
name: test-results-${{ matrix.python-version }}
path: |
pytest.log
.pytest_cache/
# =============================================================================
# Coverage Report
# =============================================================================
test-coverage:
name: Coverage Report
runs-on: ubuntu-latest
timeout-minutes: 15
needs: test-fast
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
pip install pytest-cov
- name: Run tests with coverage
run: |
pytest tests/ \
--ignore=tests/integration/ \
--ignore=tests/benchmarks/ \
--cov=src/agirails \
--cov-report=xml \
--cov-report=html \
--cov-report=term-missing \
--cov-fail-under=${{ env.COVERAGE_THRESHOLD }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
flags: unittests
name: python-sdk-coverage
fail_ci_if_error: false
- name: Upload coverage HTML report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: htmlcov/
# =============================================================================
# Security Tests
# =============================================================================
test-security:
name: Security Tests
runs-on: ubuntu-latest
timeout-minutes: 10
needs: test-fast
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
pip install bandit pip-audit safety
- name: Run security tests
run: |
pytest tests/test_security/ -v --tb=short
- name: Run bandit security linter
run: |
bandit -r src/agirails -ll -ii --format json -o bandit-report.json || true
bandit -r src/agirails -ll -ii
- name: Run pip-audit for dependency vulnerabilities
run: |
pip-audit --format json --output pip-audit-report.json || true
pip-audit
- name: Upload security reports
uses: actions/upload-artifact@v4
if: always()
with:
name: security-reports
path: |
bandit-report.json
pip-audit-report.json
# =============================================================================
# Property-Based Tests (Hypothesis)
# =============================================================================
test-properties:
name: Property-Based Tests
runs-on: ubuntu-latest
timeout-minutes: 15
needs: test-fast
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Run property-based tests
run: |
pytest tests/test_properties/ \
-v \
--tb=short \
--hypothesis-show-statistics \
--hypothesis-seed=0 # Reproducible
# =============================================================================
# Parity Tests (Python <-> TypeScript SDK)
# =============================================================================
test-parity:
name: SDK Parity Tests
runs-on: ubuntu-latest
timeout-minutes: 10
needs: test-fast
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Run parity tests (Python-only fixtures)
run: |
pytest tests/test_parity.py -v --tb=short
- name: Run cross-SDK parity tests (TS-signed → Python verify)
# tests/test_cross_sdk/ uses pre-generated JSON fixtures in
# tests/fixtures/cross_sdk/ that are produced by the TypeScript
# SDK's CounterOfferBuilder/CounterAcceptBuilder. Fixtures are
# committed to the repo; no Node setup needed at CI time.
# To regenerate (after any wire-format change), run locally:
# NODE_PATH=../sdk-js/node_modules node scripts/generate_parity_vectors.js
run: |
pytest tests/test_cross_sdk/ -v --tb=short
- name: Run golden hash snapshots
# Pinned bytes32 outputs for canonical-JSON + builder.compute_hash.
# If anyone silently changes serialization, this fails before
# integrators see broken transactions.
run: |
pytest tests/test_golden/ -v --tb=short
# =============================================================================
# Integration Tests (Requires Anvil - Push only)
# =============================================================================
test-integration:
name: Integration Tests
runs-on: ubuntu-latest
timeout-minutes: 20
if: github.event_name == 'push'
needs: [test-fast, test-security]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
- name: Install Foundry (Anvil)
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Start Anvil in background
run: |
anvil --fork-url ${{ secrets.BASE_SEPOLIA_RPC_URL || 'https://sepolia.base.org' }} &
sleep 5 # Wait for Anvil to start
- name: Run integration tests
env:
ANVIL_RPC_URL: http://localhost:8545
run: |
pytest tests/integration/ -v --tb=short || echo "Integration tests completed (some may be skipped)"
- name: Stop Anvil
if: always()
run: pkill anvil || true
# =============================================================================
# Benchmarks (Main only)
# =============================================================================
test-benchmarks:
name: Performance Benchmarks
runs-on: ubuntu-latest
timeout-minutes: 15
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
needs: test-fast
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
pip install pytest-benchmark
- name: Run benchmarks
run: |
pytest tests/benchmarks/ \
-v \
--benchmark-only \
--benchmark-json=benchmark-results.json \
--benchmark-min-rounds=10 \
--benchmark-warmup=on
- name: Upload benchmark results
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: benchmark-results.json
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
if: github.event_name == 'push'
with:
tool: 'pytest'
output-file-path: benchmark-results.json
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
alert-threshold: '150%'
comment-on-alert: true
fail-on-alert: false
# =============================================================================
# Linting & Type Checking
# =============================================================================
lint:
name: Lint & Type Check
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff mypy
pip install -e ".[dev]"
- name: Run Ruff linter
run: |
ruff check src/agirails --output-format github
- name: Run Ruff formatter check
run: |
ruff format --check src/agirails
- name: Run mypy type checker
run: |
mypy src/agirails --ignore-missing-imports --no-error-summary || true
# =============================================================================
# Summary Job
# =============================================================================
test-summary:
name: Test Summary
runs-on: ubuntu-latest
needs: [test-fast, test-coverage, test-security, test-properties, test-parity, lint]
if: always()
steps:
- name: Check test results
run: |
echo "## Test Results Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Job | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-----|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Unit Tests | ${{ needs.test-fast.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Coverage | ${{ needs.test-coverage.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Security | ${{ needs.test-security.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Properties | ${{ needs.test-properties.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Parity | ${{ needs.test-parity.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Lint | ${{ needs.lint.result }} |" >> $GITHUB_STEP_SUMMARY
- name: Fail if any required job failed
if: |
needs.test-fast.result == 'failure' ||
needs.test-coverage.result == 'failure' ||
needs.test-security.result == 'failure' ||
needs.lint.result == 'failure'
run: exit 1
# =============================================================================
# Live Base sepolia — manual gate only.
#
# Runs the gated `integration_sepolia` test suite against the real
# Base sepolia kernel (0x9d25…0021b). Costs 1-5 sepolia txes per
# full run, signed by the wallet whose keystore + password are
# supplied as repo secrets.
#
# Required secrets:
# ACTP_KEY_PASSWORD — keystore decryption password
# ACTP_KEYSTORE_BASE64 — base64-encoded keystore JSON (committed
# keystore-file path doesn't exist in CI)
# =============================================================================
live-sepolia:
name: Live Base sepolia integration
runs-on: ubuntu-latest
timeout-minutes: 20
if: github.event_name == 'workflow_dispatch'
needs: test-fast
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Materialize keystore from secret
env:
ACTP_KEYSTORE_BASE64: ${{ secrets.ACTP_KEYSTORE_BASE64 }}
run: |
if [ -z "$ACTP_KEYSTORE_BASE64" ]; then
echo "::error::ACTP_KEYSTORE_BASE64 secret not configured; skipping live tests"
exit 78 # neutral skip
fi
mkdir -p ~/.actp/mainnet-deployer
echo "$ACTP_KEYSTORE_BASE64" | base64 -d > ~/.actp/mainnet-deployer/deployer
chmod 600 ~/.actp/mainnet-deployer/deployer
- name: Run live sepolia integration
env:
ACTP_KEY_PASSWORD: ${{ secrets.ACTP_KEY_PASSWORD }}
run: |
pytest tests/integration_sepolia/ \
-m integration_sepolia \
-v --tb=short
# =============================================================================
# Mutation testing — weekly schedule + manual.
#
# mutmut introduces small code mutations (negate condition, swap
# operator, etc.) and re-runs the test suite. Each "survived"
# mutation means our tests didn't catch a behaviour change — points
# at gaps in test coverage that line coverage alone can't see.
# Configured in pyproject.toml [tool.mutmut].
# =============================================================================
mutation-test:
name: Mutation testing
runs-on: ubuntu-latest
timeout-minutes: 360 # 6h cap
if: github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev,mutation]"
- name: Run mutmut
run: |
mutmut run --paths-to-mutate src/agirails/utils/security.py,src/agirails/runtime/mock_runtime.py,src/agirails/protocol/proofs.py || true
mutmut results > mutmut_results.txt
mutmut junitxml > mutmut_results.xml || true
echo "## Mutation Results" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
tail -40 mutmut_results.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: Upload mutation report
uses: actions/upload-artifact@v4
if: always()
with:
name: mutmut-results
path: |
mutmut_results.txt
mutmut_results.xml