Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
emrgnt-cmplxty committed Oct 4, 2024
1 parent 9d0c824 commit 32bba85
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 25 deletions.
58 changes: 33 additions & 25 deletions .github/workflows/integration-test-workflow-debian.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
name: R2R CLI Integration (ubuntu latest)
name: R2R CLI Integration and Regression Test

on:
pull_request:
branches:
- 'dev*'
- 'dev-minor*'
push:
branches:
- 'dev*'
- 'dev-minor*'
branches: ['**']
workflow_dispatch:

jobs:
build-and-test:
Expand All @@ -20,24 +15,37 @@ jobs:
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
TELEMETRY_ENABLED: false
POSTGRES_HOST: localhost
POSTGRES_DBNAME: postgres
POSTGRES_PORT: 5432
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
POSTGRES_DBNAME: ${{ secrets.POSTGRES_DBNAME }}
POSTGRES_HOST: ${{ secrets.POSTGRES_HOST }}
POSTGRES_PORT: ${{ secrets.POSTGRES_PORT }}
R2R_PROJECT_NAME: ${{ secrets.R2R_PROJECT_NAME }}

steps:
- name: Install and configure PostgreSQL
run: |
sudo apt-get update
sudo apt-get install -y postgresql
sudo systemctl start postgresql.service
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.x'

# Add your other steps here
- name: Install Poetry and dependencies
run: |
curl -sSL https://install.python-poetry.org | python3 -
cd py && poetry install -E core -E ingestion-bundle
- name: Cleanup PostgreSQL
if: always() # Run this step even if the job fails
run: |
sudo systemctl stop postgresql.service
sudo rm -rf /var/lib/postgresql/
- name: Start R2R server
working-directory: ./py
run: |
poetry run r2r serve &
echo "Waiting for services to start..."
sleep 30
- name: Run integration tests
working-directory: ./py
run: |
python tests/integration/r2r_integration_tests.py test_ingest_sample_files_cli
python tests/integration/r2r_integration_tests.py test_document_ingestion_cli
- name: Stop R2R server
if: always()
run: pkill -f "r2r serve"
78 changes: 78 additions & 0 deletions py/tests/integration/runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# File: tests/integration/r2r_integration_tests.py

import json
import subprocess
import sys


def run_command(command):
result = subprocess.run(
command, shell=True, capture_output=True, text=True
)
if result.returncode != 0:
print(f"Command failed: {command}")
print(f"Error: {result.stderr}")
sys.exit(1)
return result.stdout


def test_ingest_sample_files_cli():
print("Testing: Ingest sample files")
run_command("poetry run r2r ingest-sample-files")
print("Ingestion successful")


def test_document_ingestion_cli():
print("Testing: Document ingestion")
output = run_command("poetry run r2r documents-overview")
documents = json.loads(output)

expected_document = {
"id": "9fbe403b-c11c-5aae-8ade-ef22980c3ad1",
"title": "aristotle.txt",
"type": "txt",
"ingestion_status": "success",
"kg_extraction_status": "success",
"version": "v0",
"metadata": {"title": "aristotle.txt", "version": "v0"},
}

if not any(
all(doc.get(k) == v for k, v in expected_document.items())
for doc in documents
):
print("Document ingestion test failed")
print(f"Expected document not found in output: {output}")
sys.exit(1)
print("Document ingestion test passed")


def test_vector_search_cli():
print("Testing: Vector search")
output = run_command(
"poetry run r2r search --query='What was Uber's profit in 2020?'"
)
results = json.loads(output)
if not results.get("results"):
print("Vector search test failed: No results returned")
sys.exit(1)
print("Vector search test passed")


def test_rag_query_cli():
print("Testing: RAG query")
output = run_command("poetry run r2r rag --query='Who was Aristotle?'")
response = json.loads(output)
if not response.get("answer"):
print("RAG query test failed: No answer returned")
sys.exit(1)
print("RAG query test passed")


if __name__ == "__main__":
if len(sys.argv) < 2:
print("Please specify a test function to run")
sys.exit(1)

test_function = sys.argv[1]
globals()[test_function]()

0 comments on commit 32bba85

Please sign in to comment.