-
Notifications
You must be signed in to change notification settings - Fork 1
290 lines (252 loc) · 8.36 KB
/
tests.yml
File metadata and controls
290 lines (252 loc) · 8.36 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
name: Tests
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
workflow_dispatch:
permissions:
contents: read
pull-requests: write
checks: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
name: Test on Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
python-version: ["3.11", "3.12"]
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest pytest-asyncio pytest-cov pytest-xdist
continue-on-error: false
- name: List test files
run: |
echo "Available test files:"
find tests -name "test_*.py" -type f | head -20
echo "Total test files:"
find tests -name "test_*.py" -type f | wc -l
- name: Run tests with coverage (Codecov format)
run: |
pytest tests/ \
--cov=backend \
--cov-branch \
--cov-report=xml \
--cov-report=term \
--cov-report=html \
--junit-xml=junit.xml \
-v \
--tb=short \
--maxfail=10
env:
ENVIRONMENT: test
DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY || 'test_key' }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY || 'test_key' }}
PYTHONPATH: ${{ github.workspace }}
continue-on-error: true
- name: Verify coverage.xml was created
run: |
if [ -f coverage.xml ]; then
echo "✅ coverage.xml exists"
ls -lh coverage.xml
echo "First 20 lines of coverage.xml:"
head -20 coverage.xml
else
echo "❌ coverage.xml not found!"
echo "Listing files in current directory:"
ls -la
echo "Listing files in tests directory:"
ls -la tests/ | head -10
exit 1
fi
continue-on-error: true
- name: Upload coverage to Codecov
if: hashFiles('coverage.xml') != ''
uses: codecov/codecov-action@v5
with:
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
continue-on-error: true
- name: Upload test results
uses: actions/upload-artifact@v6
if: always()
with:
name: test-results-${{ matrix.python-version }}
path: |
junit.xml
htmlcov/
coverage.xml
retention-days: 7
if-no-files-found: ignore
- name: Publish test results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: junit.xml
check_name: "Test Results (Python ${{ matrix.python-version }})"
comment_mode: always
report_individual_runs: true
continue-on-error: true
docker-build:
name: Docker Build (no push)
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image (CHROMA_WARMUP=false)
run: |
docker build \
--build-arg CHROMA_WARMUP=false \
-t stillme-api:ci \
.
- name: Build Docker image (CHROMA_WARMUP=true)
run: |
docker build \
--build-arg CHROMA_WARMUP=true \
-t stillme-api:ci-warmup \
.
continue-on-error: true # Warmup may fail, but build should still work
- name: Smoke test built image
run: |
# Start container in background
docker run -d \
--name stillme-test \
-p 8000:8000 \
-e PORT=8000 \
-e ENVIRONMENT=test \
stillme-api:ci
# Wait for server to start
echo "Waiting for server to start..."
sleep 15
# Test /health endpoint
for i in {1..10}; do
if curl -f http://localhost:8000/health > /dev/null 2>&1; then
echo "✅ /health endpoint returned 200 OK"
curl -i http://localhost:8000/health
break
fi
echo "Waiting for /health endpoint... ($i/10)"
sleep 2
done
# Clean up
docker stop stillme-test || true
docker rm stillme-test || true
continue-on-error: true # Smoke test is optional
smoke-test:
name: Smoke Test (Health & Ready Endpoints)
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest httpx
- name: Start server in background
run: |
export PORT=8000
python start_backend.py &
SERVER_PID=$!
echo "SERVER_PID=$SERVER_PID" >> $GITHUB_ENV
# Wait for server to start
sleep 10
env:
ENVIRONMENT: test
PYTHONPATH: ${{ github.workspace }}
DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY || 'test_key' }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY || 'test_key' }}
- name: Test /health endpoint (liveness)
run: |
for i in {1..30}; do
if curl -f http://localhost:8000/health > /dev/null 2>&1; then
echo "✅ /health endpoint returned 200 OK"
curl -i http://localhost:8000/health
exit 0
fi
echo "Waiting for /health endpoint... ($i/30)"
sleep 2
done
echo "❌ /health endpoint did not return 200 after 60 seconds"
exit 1
- name: Test /ready endpoint (readiness)
run: |
response=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/ready)
echo "Response code: $response"
if [ "$response" = "200" ] || [ "$response" = "503" ]; then
echo "✅ /ready endpoint returned $response (expected 200 or 503)"
curl -i http://localhost:8000/ready
else
echo "❌ /ready endpoint returned unexpected status: $response"
exit 1
fi
- name: Stop server
if: always()
run: |
if [ -n "$SERVER_PID" ]; then
kill $SERVER_PID || true
fi
pkill -f "python start_backend.py" || true
coverage:
name: Coverage Report
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest pytest-asyncio pytest-cov
- name: Generate coverage report
run: |
pytest tests/ \
--cov=backend \
--cov-branch \
--cov-report=term \
--cov-report=html \
-v
env:
ENVIRONMENT: test
PYTHONPATH: ${{ github.workspace }}
- name: Comment PR with coverage
uses: py-cov-action/python-coverage-comment-action@v3
if: github.event_name == 'pull_request'
with:
GITHUB_TOKEN: ${{ github.token }}
MINIMUM_GREEN: 40
MINIMUM_ORANGE: 30