-
-
Notifications
You must be signed in to change notification settings - Fork 0
164 lines (145 loc) · 5.55 KB
/
Copy pathtest-split-backend.yml
File metadata and controls
164 lines (145 loc) · 5.55 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
name: Split-Backend E2E Tests
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
e2e-split-backend:
runs-on: ubuntu-latest
timeout-minutes: 15
services:
postgres:
image: pgvector/pgvector:pg16
env:
POSTGRES_DB: rag_vector_db
POSTGRES_USER: rag_user
POSTGRES_PASSWORD: rag_password
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U rag_user -d rag_vector_db"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: 'pip'
- name: Cache HuggingFace embedding model
uses: actions/cache@v4
with:
path: ~/.cache/huggingface/hub
key: hf-model-all-MiniLM-L6-v2
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest requests
- name: Bootstrap API key, start server, run E2E tests
env:
DB_HOST: localhost
DB_PORT: 5432
DB_NAME: rag_vector_db
DB_USER: rag_user
DB_PASSWORD: rag_password
API_HOST: 127.0.0.1
API_PORT: 9000
API_REQUIRE_AUTH: "true"
API_AUTH_FORCE_ALL: "true"
run: |
set -euo pipefail
# ── Run database migrations ────────────────────────────────
echo "::group::Run database migrations"
python -c "
import sys
sys.path.insert(0, '.')
from alembic.config import Config
from alembic import command
cfg = Config('alembic.ini')
command.upgrade(cfg, 'head')
print('Migrations complete')
"
echo "::endgroup::"
# ── Bootstrap API key ───────────────────────────────────────
echo "::group::Bootstrap API key"
API_KEY=$(python -c "
import sys, os
sys.path.insert(0, '.')
os.environ.setdefault('DB_HOST', 'localhost')
from auth import create_api_key_record
record = create_api_key_record('e2e-test')
print(record['key'])
")
echo "API key created (prefix: ${API_KEY:0:12}...)"
echo "::endgroup::"
# ── Start API server ────────────────────────────────────────
echo "::group::Start API server"
nohup python -m uvicorn api:app \
--host 127.0.0.1 \
--port 9000 \
--log-level info \
> server.log 2>&1 &
SERVER_PID=$!
echo "Server started (PID: $SERVER_PID)"
echo "::endgroup::"
# Cleanup on exit
trap "echo 'Stopping server (PID: $SERVER_PID)...'; kill $SERVER_PID 2>/dev/null || true" EXIT
# ── Wait for healthy ────────────────────────────────────────
echo "::group::Wait for server health"
HEALTHY=false
for i in $(seq 1 60); do
# Check if server process died
if ! kill -0 $SERVER_PID 2>/dev/null; then
echo "ERROR: Server process died!"
echo "=== server.log ==="
cat server.log
exit 1
fi
STATUS=$(curl -s http://127.0.0.1:9000/health | python -c "import sys,json; print(json.load(sys.stdin).get('status',''))" 2>/dev/null || echo "")
if [ "$STATUS" = "healthy" ]; then
HEALTHY=true
echo "Server healthy after $((i * 2))s"
break
fi
echo "Waiting... ($i/60, status=$STATUS)"
sleep 2
done
# Post-loop guard: fail if health was never reached
if [ "$HEALTHY" != "true" ]; then
echo "ERROR: Server did not become healthy within 120s"
echo "=== server.log ==="
cat server.log
exit 1
fi
echo "::endgroup::"
# ── Warm up embedding model ──────────────────────────────
# The model loads lazily on first embedding request. Fire a search
# now (before pytest) so the 120s test timeout is never at risk.
echo "::group::Warm up embedding model"
echo "Sending warm-up search to trigger model load (up to 300s)..."
curl -s -X POST http://127.0.0.1:9000/api/v1/search \
-H "X-API-Key: $API_KEY" \
-H "Content-Type: application/json" \
-d '{"query": "warmup", "top_k": 1}' \
--max-time 300 > /dev/null || echo "Warm-up request timed out (model may still be loading)"
echo "Warm-up complete"
echo "::endgroup::"
# ── Run E2E tests ───────────────────────────────────────────
echo "::group::Run E2E tests"
E2E_API_KEY="$API_KEY" E2E_BASE_URL="http://127.0.0.1:9000" \
python -m pytest tests/test_e2e_split_backend.py -v --tb=short
echo "::endgroup::"
echo "All E2E tests passed!"
- name: Upload server log on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: server-log
path: server.log
if-no-files-found: ignore
retention-days: 7