-
Notifications
You must be signed in to change notification settings - Fork 104
566 lines (487 loc) · 17.8 KB
/
Copy pathci-python.yml
File metadata and controls
566 lines (487 loc) · 17.8 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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
name: Python CI
on:
push:
branches: [main]
paths:
- 'src/**'
- 'tests/**'
- 'benchmarks/**'
- 'examples/**'
- 'docs/**'
- 'scripts/**'
- 'pyproject.toml'
- 'uv.lock'
- 'Makefile'
- 'docker-compose.test.yml'
- 'codecov.yml'
- '.github/workflows/ci-python.yml'
pull_request:
branches: [main]
paths:
- 'src/**'
- 'tests/**'
- 'benchmarks/**'
- 'examples/**'
- 'docs/**'
- 'scripts/**'
- 'pyproject.toml'
- 'uv.lock'
- 'Makefile'
- 'docker-compose.test.yml'
- 'codecov.yml'
- '.github/workflows/ci-python.yml'
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set up Python
run: uv python install 3.12
- name: Install dependencies
run: uv sync --group dev
- name: Run ruff check
run: uv run ruff check src tests
- name: Run ruff format check
run: uv run ruff format --check src tests
type-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set up Python
run: uv python install 3.12
# All extras so integrations/ is actually analyzed against real framework
# types, not stubbed out. Without them the checkers only shallowly analyze
# integrations/ and would miss real errors. See the type-safety tracking
# issue #144.
- name: Install dependencies
run: uv sync --all-extras --group dev
# Checked surface: src, benchmarks, and the top-level examples/*.py demos.
# Both checkers are blocking and the surface is kept at zero errors.
# mypy is the source of truth; ty is the second, independent checker
# (its complementary rules must also pass).
- name: Run mypy
run: uv run mypy src benchmarks examples/*.py
- name: Run ty
run: uv run ty check src benchmarks examples/*.py
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}
# The `strands` extra is needed for the Strands integration's unit tests:
# tests/unit/integrations/test_strands_*.py all begin with
# `pytest.importorskip("strands")`, so without it they silently skip and
# this job reports green on code it never ran. Kept to that one extra --
# the rest of the suite is designed to run on the dev group alone.
- name: Install dependencies
run: uv sync --group dev --extra strands
- name: Run unit tests
run: uv run pytest tests/unit -v --cov=neo4j_agent_memory --cov-report=xml --cov-report=term-missing
- name: Upload unit test coverage artifact
uses: actions/upload-artifact@v7
if: matrix.python-version == '3.12'
with:
name: coverage-unit
path: .coverage
include-hidden-files: true
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
if: matrix.python-version == '3.12'
with:
files: ./coverage.xml
flags: unit
fail_ci_if_error: false
integration-test:
runs-on: ubuntu-latest
# Use GitHub Actions services for Neo4j - more reliable than testcontainers in CI
services:
neo4j:
image: neo4j:5.26-community
ports:
- 7687:7687
- 7474:7474
env:
NEO4J_AUTH: neo4j/test-password
NEO4J_PLUGINS: '["apoc"]'
NEO4J_dbms_security_procedures_unrestricted: apoc.*
NEO4J_dbms_security_procedures_allowlist: apoc.*
options: >-
--health-cmd "cypher-shell -u neo4j -p test-password 'RETURN 1'"
--health-interval 10s
--health-timeout 10s
--health-retries 20
--health-start-period 30s
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set up Python
run: uv python install 3.12
- name: Install dependencies
run: uv sync --group dev --all-extras
- name: Wait for Neo4j to be ready
run: |
echo "Waiting for Neo4j to be ready..."
for i in {1..60}; do
if curl -s http://localhost:7474 > /dev/null 2>&1; then
echo "Neo4j HTTP interface is ready"
# Also check bolt connection
if uv run python -c "from neo4j import GraphDatabase; d = GraphDatabase.driver('bolt://localhost:7687', auth=('neo4j', 'test-password')); d.verify_connectivity(); d.close(); print('Bolt ready')" 2>/dev/null; then
echo "Neo4j is fully ready!"
break
fi
fi
echo "Attempt $i: Waiting for Neo4j..."
sleep 2
done
# Cache the whole Hugging Face cache dir so tests don't re-download any
# model on every run (a cold download can exceed the no-llm test's
# subprocess timeout). Repeated in each job that pulls a model.
- name: Cache Hugging Face models
uses: actions/cache@v4
with:
path: ~/.cache/huggingface
# Rotating key: restore-keys restores the newest prior cache (so nothing
# re-downloads on a normal run), then the run re-saves under a fresh
# per-commit key so any newly-used model is folded in automatically —
# no manual version bump for contributors to remember.
key: hf-cache-${{ runner.os }}-${{ github.sha }}
restore-keys: |
hf-cache-${{ runner.os }}-
- name: Run integration tests with coverage
# NAMS integration tests have a dedicated workflow
# (.github/workflows/nams-integration.yml) so we exclude them here.
run: |
uv run pytest tests/integration -v \
--ignore=tests/integration/nams \
--tb=short \
--timeout=300 \
-x \
--cov=neo4j_agent_memory \
--cov-report=xml:coverage-integration.xml \
--cov-report=term-missing
env:
NEO4J_URI: bolt://localhost:7687
NEO4J_USERNAME: neo4j
NEO4J_PASSWORD: test-password
- name: Upload integration coverage artifact
uses: actions/upload-artifact@v7
if: always()
with:
name: coverage-integration
path: .coverage
include-hidden-files: true
- name: Upload integration coverage to Codecov
uses: codecov/codecov-action@v4
if: always()
with:
files: ./coverage-integration.xml
flags: integration
fail_ci_if_error: false
integration-test-matrix:
runs-on: ubuntu-latest
needs: integration-test
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]
fail-fast: false
services:
neo4j:
image: neo4j:5.26-community
ports:
- 7687:7687
- 7474:7474
env:
NEO4J_AUTH: neo4j/test-password
NEO4J_PLUGINS: '["apoc"]'
NEO4J_dbms_security_procedures_unrestricted: apoc.*
NEO4J_dbms_security_procedures_allowlist: apoc.*
options: >-
--health-cmd "cypher-shell -u neo4j -p test-password 'RETURN 1'"
--health-interval 10s
--health-timeout 10s
--health-retries 20
--health-start-period 30s
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}
- name: Install all dependencies
run: uv sync --group dev --all-extras
- name: Wait for Neo4j
run: |
for i in {1..60}; do
if curl -s http://localhost:7474 > /dev/null 2>&1; then
sleep 5 # Extra wait for full initialization
break
fi
sleep 2
done
- name: Cache Hugging Face models
uses: actions/cache@v4
with:
path: ~/.cache/huggingface
# Rotating key: restore-keys restores the newest prior cache (so nothing
# re-downloads on a normal run), then the run re-saves under a fresh
# per-commit key so any newly-used model is folded in automatically —
# no manual version bump for contributors to remember.
key: hf-cache-${{ runner.os }}-${{ github.sha }}
restore-keys: |
hf-cache-${{ runner.os }}-
- name: Run integration tests
# NAMS integration tests run in their own workflow
# (.github/workflows/nams-integration.yml).
run: |
uv run pytest tests/integration \
--ignore=tests/integration/nams \
-v \
--tb=short \
--timeout=600 \
--durations=20
env:
NEO4J_URI: bolt://localhost:7687
NEO4J_USERNAME: neo4j
NEO4J_PASSWORD: test-password
# Alternative job using testcontainers (useful for debugging or different environments)
integration-test-testcontainers:
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, '[testcontainers]')
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set up Python
run: uv python install 3.12
- name: Install dependencies
run: uv sync --group dev --all-extras
- name: Cache Hugging Face models
uses: actions/cache@v4
with:
path: ~/.cache/huggingface
# Rotating key: restore-keys restores the newest prior cache (so nothing
# re-downloads on a normal run), then the run re-saves under a fresh
# per-commit key so any newly-used model is folded in automatically —
# no manual version bump for contributors to remember.
key: hf-cache-${{ runner.os }}-${{ github.sha }}
restore-keys: |
hf-cache-${{ runner.os }}-
- name: Run integration tests with testcontainers
run: |
uv run pytest tests/integration \
--ignore=tests/integration/nams \
-v \
--tb=short \
--timeout=600
# No NEO4J_URI set - will use testcontainers
# Example smoke tests - validates that all examples work with current package
example-tests:
runs-on: ubuntu-latest
needs: test # Run after unit tests pass
services:
neo4j:
image: neo4j:5.26-community
ports:
- 7687:7687
- 7474:7474
env:
NEO4J_AUTH: neo4j/test-password
NEO4J_PLUGINS: '["apoc"]'
NEO4J_dbms_security_procedures_unrestricted: apoc.*
NEO4J_dbms_security_procedures_allowlist: apoc.*
options: >-
--health-cmd "cypher-shell -u neo4j -p test-password 'RETURN 1'"
--health-interval 10s
--health-timeout 10s
--health-retries 20
--health-start-period 30s
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set up Python
run: uv python install 3.12
- name: Install all dependencies
run: uv sync --group dev --all-extras
- name: Wait for Neo4j
run: |
echo "Waiting for Neo4j to be ready..."
for i in {1..60}; do
if curl -s http://localhost:7474 > /dev/null 2>&1; then
if uv run python -c "from neo4j import GraphDatabase; d = GraphDatabase.driver('bolt://localhost:7687', auth=('neo4j', 'test-password')); d.verify_connectivity(); d.close()" 2>/dev/null; then
echo "Neo4j is ready!"
break
fi
fi
echo "Attempt $i: Waiting for Neo4j..."
sleep 2
done
- name: Cache Hugging Face models
uses: actions/cache@v4
with:
path: ~/.cache/huggingface
# Rotating key: restore-keys restores the newest prior cache (so nothing
# re-downloads on a normal run), then the run re-saves under a fresh
# per-commit key so any newly-used model is folded in automatically —
# no manual version bump for contributors to remember.
key: hf-cache-${{ runner.os }}-${{ github.sha }}
restore-keys: |
hf-cache-${{ runner.os }}-
- name: Run example smoke tests
run: |
uv run pytest tests/examples \
-v \
--tb=short \
--timeout=120
env:
NEO4J_URI: bolt://localhost:7687
NEO4J_USERNAME: neo4j
NEO4J_PASSWORD: test-password
# Quick example validation (no Neo4j required) - runs in parallel with other tests
example-tests-quick:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set up Python
run: uv python install 3.12
- name: Install dependencies
run: uv sync --group dev --all-extras
- name: Cache Hugging Face models
uses: actions/cache@v4
with:
path: ~/.cache/huggingface
# Rotating key: restore-keys restores the newest prior cache (so nothing
# re-downloads on a normal run), then the run re-saves under a fresh
# per-commit key so any newly-used model is folded in automatically —
# no manual version bump for contributors to remember.
key: hf-cache-${{ runner.os }}-${{ github.sha }}
restore-keys: |
hf-cache-${{ runner.os }}-
- name: Run quick example validation
run: |
uv run pytest \
tests/examples/test_entity_resolution.py \
tests/examples/test_full_stack_apps.py \
tests/examples/test_google_cloud_financial_advisor.py \
tests/examples/test_google_cloud_integration.py \
tests/examples/test_google_adk_demo.py \
tests/examples/test_microsoft_agent_example.py \
tests/examples/test_crewai_example.py \
tests/examples/test_llamaindex_example.py \
tests/examples/test_aws_financial_advisor.py \
tests/examples/test_domain_schemas.py \
tests/examples/test_no_llm_example.py \
tests/examples/test_enrichment_example.py \
tests/examples/test_no_phantom_methods.py \
-v \
--tb=short \
--timeout=60
# Documentation tests - validates code snippets and internal links
docs-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set up Python
run: uv python install 3.12
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install Python dependencies
run: uv sync --group dev
- name: Install docs dependencies
run: cd docs && npm install
- name: Run documentation syntax validation
run: |
uv run pytest tests/docs/test_code_snippets.py \
-v \
--tb=short \
--timeout=60
- name: Run documentation link validation
run: |
uv run pytest tests/docs/test_links.py \
-v \
--tb=short \
--timeout=60
- name: Run documentation build tests
run: |
uv run pytest tests/docs/test_build_pipeline.py \
-v \
--tb=short \
--timeout=180
# Merge coverage from unit and integration tests, check threshold
coverage-report:
runs-on: ubuntu-latest
needs: [test, integration-test]
if: always()
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set up Python
run: uv python install 3.12
- name: Install dependencies
run: uv sync --group dev
- name: Download unit coverage
uses: actions/download-artifact@v4
with:
name: coverage-unit
path: coverage-unit/
continue-on-error: true
- name: Download integration coverage
uses: actions/download-artifact@v4
with:
name: coverage-integration
path: coverage-integration/
continue-on-error: true
- name: Merge coverage reports
run: |
# Combine coverage data from both test jobs
uv run coverage combine coverage-unit/.coverage coverage-integration/.coverage || true
uv run coverage xml -o coverage-merged.xml
uv run coverage report --show-missing
continue-on-error: true
- name: Upload merged coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: ./coverage-merged.xml
flags: merged
fail_ci_if_error: false
- name: Check coverage threshold
run: |
uv run coverage report --fail-under=55 || echo "::warning::Coverage below 55% threshold"
continue-on-error: true
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set up Python
run: uv python install 3.12
- name: Build package
run: uv build
- name: Check package
run: |
uv run pip install dist/*.whl
uv run python -c "import neo4j_agent_memory; print(neo4j_agent_memory.__version__)"
- name: Upload artifacts
uses: actions/upload-artifact@v7
with:
name: dist
path: dist/