Skip to content

Commit d9a97fd

Browse files
committed
chore: Use running openRAG for tests
1 parent 61e1db1 commit d9a97fd

8 files changed

Lines changed: 220 additions & 38 deletions

File tree

.github/workflows/unit_tests.yml

Lines changed: 100 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,122 @@ jobs:
1313
matrix:
1414
python-version: ["3.12"]
1515

16+
env:
17+
APP_PORT: 8080
18+
RAG_BASE_URL: http://localhost:8080
19+
1620
steps:
1721
- name: Checkout repository
1822
uses: actions/checkout@v4
1923

20-
- name: Set up Python
21-
uses: actions/setup-python@v5
24+
- name: env file
25+
run: |
26+
cp tests/.env-tests .env
27+
28+
# Move storage to /mnt to avoid disk space issues
29+
- name: Free up space and move Docker storage to /mnt
30+
run: |
31+
echo "Stopping Docker..."
32+
sudo systemctl stop docker
33+
34+
echo "Creating new Docker root at /mnt/docker..."
35+
sudo mkdir -p /mnt/docker
36+
sudo rsync -aqxP /var/lib/docker/ /mnt/docker
37+
38+
echo "Updating Docker daemon config..."
39+
echo '{"data-root": "/mnt/docker"}' | sudo tee /etc/docker/daemon.json
40+
41+
cat /etc/docker/daemon.json
42+
43+
echo "Restarting Docker..."
44+
sudo systemctl start docker
45+
46+
echo "Verifying Docker root directory:"
47+
docker info | grep "Docker Root Dir"
48+
49+
# Setup docker builds with cache
50+
- name: Set up Docker Buildx
51+
uses: docker/setup-buildx-action@v3
52+
53+
- name: Build openrag image
54+
uses: docker/build-push-action@v6
2255
with:
23-
python-version: ${{ matrix.python-version }}
56+
context: .
57+
file: ./Dockerfile
58+
tags: linagoraai/openrag:latest
59+
push: false
60+
cache-from: type=gha,scope=openrag
61+
cache-to: type=gha,mode=max,scope=openrag
2462

25-
- name: Install uv
63+
- name: Build vllm CPU image
64+
uses: docker/build-push-action@v6
65+
with:
66+
context: ./extern/vllm
67+
file: ./extern/vllm/Dockerfile.cpu
68+
target: vllm-openai
69+
tags: openrag-vllm-openai-cpu
70+
push: false
71+
load: true
72+
cache-from: type=gha,scope=vllm-cpu
73+
cache-to: type=gha,mode=max,scope=vllm-cpu
74+
75+
- name: Check vllm image
76+
run: docker images | grep vllm || true
77+
78+
# Start openRAG CPU
79+
- name: Start openRAG CPU
2680
run: |
27-
curl -LsSf https://astral.sh/uv/install.sh | sh
28-
echo "$HOME/.local/bin" >> $GITHUB_PATH
81+
docker compose \
82+
-f docker-compose.yaml \
83+
-f docker-compose.ci.yaml \
84+
--profile cpu up -d \
85+
--no-build --pull=never
86+
docker compose --profile cpu up -d
87+
88+
- name: Wait for RAG API
89+
run: |
90+
echo "Waiting for RAG API on ${RAG_BASE_URL}..."
91+
for i in {1..60}; do
92+
if curl -fsS "${RAG_BASE_URL}/health_check" > /dev/null 2>&1; then
93+
echo "RAG API is up!"
94+
exit 0
95+
fi
96+
sleep 5
97+
done
98+
docker compose logs
99+
exit 1
100+
101+
# Install uv with cache
102+
- name: Install uv
103+
uses: astral-sh/setup-uv@v3
29104

30105
- name: Cache uv
31106
uses: actions/cache@v4
32107
with:
33-
path: |
34-
~/.cache/uv
108+
path: ~/.cache/uv
35109
key: uv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml', '**/uv.lock') }}
36110
restore-keys: |
37111
uv-${{ runner.os }}-${{ matrix.python-version }}-
38112
39-
- name: Install dependencies with uv
113+
# Install deps for tests
114+
- name: Install with test dependencies
40115
run: |
41-
uv sync
116+
uv pip install -e ".[test]"
42117
118+
# Run actual tests
43119
- name: Run tests
44120
run: |
45-
uv run pytest
121+
uv run pytest -vv tests
122+
123+
124+
# Dump logs on failure
125+
- name: Dump logs on failure
126+
if: failure()
127+
run: docker compose logs
128+
129+
# Proper shutdown
130+
- name: Shutdown openRAG
131+
if: always()
132+
run: |
133+
docker compose down -v
134+

docker-compose-ci.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
vllm-cpu:
3+
build: null # Do not build for faster startup
4+
image: openrag-vllm-openai-cpu

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ dev = [
5454
"pytest>=8.4.1",
5555
"pytest-asyncio>=1.3.0",
5656
]
57+
58+
[project.optional-dependencies]
59+
test = [
60+
"pytest",
61+
"httpx",
62+
"pytest-timeout"
63+
]
64+
5765
lint = [
5866
"ruff>=0.14.1",
5967
]

pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[pytest]
22
testpaths =
33
openrag
4+
tests
45
pythonpath = ./openrag
56
python_files =
67
test_*.py

tests/.env-tests

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# LLM
2+
BASE_URL=http://localhost:8001/
3+
API_KEY=sk-
4+
MODEL=HuggingFaceTB/SmolLM2-135M-Instruct
5+
6+
# VLM (Visual Language Model) you can set it to the same as LLM if your LLM supports images
7+
VLM_BASE_URL=http://localhost:8002/
8+
VLM_API_KEY=sk-
9+
VLM_MODEL=HuggingFaceTB/SmolVLM-Instruct
10+
11+
## FastAPI App (no need to change it)
12+
# APP_PORT=8080 # this is the forwarded port
13+
# API_NUM_WORKERS=1 # Number of uvicorn workers for the FastAPI app
14+
15+
## To enable API HTTP authentication via HTTPBearer
16+
# AUTH_TOKEN=sk-openrag-1234
17+
18+
# SAVE_UPLOADED_FILES=true # usefull for chainlit source viewing
19+
20+
# Set to true, it will mount chainlit chat ui to the fastapi app (Default: true)
21+
## WITH_CHAINLIT_UI=true
22+
23+
# RETRIEVER
24+
CONTEXTUAL_RETRIEVAL=false
25+
26+
# EMBEDDER
27+
EMBEDDER_MODEL_NAME=ibm-granite/granite-embedding-small-english-r2
28+
EMBEDDER_BASE_URL=http://vllm:8000/v1
29+
# EMBEDDER_API_KEY=EMPTY
30+
31+
# RERANKER
32+
RERANKER_ENABLED=true
33+
RERANKER_MODEL=Alibaba-NLP/gte-multilingual-reranker-base # or jinaai/jina-reranker-v2-base-multilingual
34+
35+
# Prompts
36+
PROMPTS_DIR=../prompts/example1
37+
38+
# Loaders
39+
PDFLoader=MarkerLoader
40+
XDG_CACHE_HOME=/app/model_weights
41+
# If using MarkerLoader
42+
MARKER_MAX_TASKS_PER_CHILD=1
43+
MARKER_MAX_PROCESSES=1
44+
MARKER_MIN_PROCESSES=1
45+
MARKER_POOL_SIZE=1 # Value au increment if you have a cluster of machines
46+
MARKER_NUM_GPUS=0.01
47+
48+
# Ray
49+
RAY_POOL_SIZE=1 # Number of serializer actor instances
50+
RAY_MAX_TASKS_PER_WORKER=2 # Number of tasks per serializer
51+
RAY_DEDUP_LOGS=0 # turns off ray log deduplication that appear across multiple processes
52+
RAY_ENABLE_RECORD_ACTOR_TASK_LOGGING=1 # # to enable logs at task level in ray dashboard
53+
RAY_task_retry_delay_ms=3000
54+
RAY_ENABLE_UV_RUN_RUNTIME_ENV=0 # critical with the newest version of UV
55+
RAY_memory_monitor_refresh_ms=0
56+
57+
# Indexer UI
58+
## 1. replace X.X.X.X with localhost if launching local or with your server IP
59+
## 2. APP_PORT with your FastAPI port (8080 by default)
60+
## 3. Base URL of the Indexer UI (required to prevent CORS issues). Replace INDEXERUI_PORT with its value
61+
## 4. Base URL of your FastAPI backend. Used by the frondend. Replace APP_PORT with the actual port number of your FastAPI backend
62+
63+
VITE_INCLUDE_CREDENTIALS=false # set true if fastapi authentification is enabled
64+
INDEXERUI_PORT=8060 # Port to expose the Indexer UI (default is 3042)
65+
INDEXERUI_URL='http://X.X.X.X:INDEXERUI_PORT'
66+
VITE_API_BASE_URL='http://X.X.X.X:APP_PORT'

tests/conftest.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# tests/conftest.py
2+
import os
3+
import time
4+
import httpx
5+
import pytest
6+
7+
8+
@pytest.fixture(scope="session")
9+
def base_url():
10+
return os.environ.get("RAG_BASE_URL", "http://localhost:8080")
11+
12+
13+
@pytest.fixture(scope="session", autouse=True)
14+
def wait_for_api(base_url):
15+
timeout = 60
16+
start = time.time()
17+
18+
while True:
19+
try:
20+
r = httpx.get(f"{base_url}/health_check", timeout=3)
21+
if r.status_code == 200:
22+
return
23+
except Exception:
24+
pass
25+
26+
if time.time() - start > timeout:
27+
raise RuntimeError("API not ready")
28+
29+
time.sleep(2)

tests/test_partitions.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# tests/test_partition.py
2+
import httpx
3+
import uuid
4+
5+
6+
def test_create_partition(base_url):
7+
client = httpx.Client(timeout=5)
8+
9+
partition_name = "tets-partition"
10+
r = client.post(f"{base_url}/partition/{partition_name}")
11+
assert r.status_code is 200
12+

tests/test_vectordb.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)