mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-17 18:35:19 +02:00
chore: implement E2E testing setup with Docker Compose and update workflow for backend and Redis services
This commit is contained in:
parent
2c8828f60c
commit
68f45335bc
9 changed files with 433 additions and 233 deletions
231
.github/workflows/e2e-tests.yml
vendored
231
.github/workflows/e2e-tests.yml
vendored
|
|
@ -7,6 +7,7 @@ on:
|
|||
paths:
|
||||
- 'surfsense_web/**'
|
||||
- 'surfsense_backend/**'
|
||||
- 'docker/docker-compose.e2e.yml'
|
||||
- '.github/workflows/e2e-tests.yml'
|
||||
workflow_dispatch:
|
||||
|
||||
|
|
@ -19,173 +20,36 @@ jobs:
|
|||
name: Journey
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event.pull_request.draft == false
|
||||
timeout-minutes: 45
|
||||
|
||||
# Postgres runs as a step (not a service)
|
||||
services:
|
||||
redis:
|
||||
image: redis:8-alpine
|
||||
ports:
|
||||
- 6379:6379
|
||||
options: >-
|
||||
--health-cmd "redis-cli ping"
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
timeout-minutes: 30
|
||||
|
||||
env:
|
||||
DATABASE_URL: postgresql+asyncpg://postgres:postgres@localhost:5432/surfsense_e2e
|
||||
CELERY_BROKER_URL: redis://localhost:6379/0
|
||||
CELERY_RESULT_BACKEND: redis://localhost:6379/0
|
||||
REDIS_APP_URL: redis://localhost:6379/0
|
||||
SECRET_KEY: ci-test-secret-key-not-for-production
|
||||
AUTH_TYPE: LOCAL
|
||||
REGISTRATION_ENABLED: "TRUE"
|
||||
ETL_SERVICE: DOCLING
|
||||
EMBEDDING_MODEL: sentence-transformers/all-MiniLM-L6-v2
|
||||
NEXT_FRONTEND_URL: http://localhost:3000
|
||||
|
||||
# Sentinel keys — fakes never read them; turns leaked real calls into 401s.
|
||||
COMPOSIO_API_KEY: e2e-deny-real-call-sentinel
|
||||
COMPOSIO_ENABLED: "TRUE"
|
||||
OPENAI_API_KEY: e2e-deny-real-call-sentinel
|
||||
ANTHROPIC_API_KEY: e2e-deny-real-call-sentinel
|
||||
LITELLM_API_KEY: e2e-deny-real-call-sentinel
|
||||
|
||||
MICROSOFT_CLIENT_ID: fake-microsoft-client-id
|
||||
MICROSOFT_CLIENT_SECRET: fake-microsoft-client-secret
|
||||
ONEDRIVE_REDIRECT_URI: http://localhost:8000/api/v1/auth/onedrive/connector/callback
|
||||
DROPBOX_APP_KEY: fake-dropbox-app-key
|
||||
DROPBOX_APP_SECRET: fake-dropbox-app-secret
|
||||
DROPBOX_REDIRECT_URI: http://localhost:8000/api/v1/auth/dropbox/connector/callback
|
||||
|
||||
# Test user that the backend creates via /auth/register before Playwright runs.
|
||||
PLAYWRIGHT_TEST_EMAIL: e2e-test@surfsense.net
|
||||
PLAYWRIGHT_TEST_PASSWORD: E2eTestPassword123!
|
||||
# Frontend env: Playwright's webServer (surfsense_web/playwright.config.ts)
|
||||
# spawns `pnpm build && pnpm start` in CI; these get baked into the build.
|
||||
NEXT_PUBLIC_FASTAPI_BACKEND_URL: http://localhost:8000
|
||||
NEXT_PUBLIC_FASTAPI_BACKEND_AUTH_TYPE: LOCAL
|
||||
|
||||
PLAYWRIGHT_TEST_EMAIL: e2e-test@surfsense.net
|
||||
PLAYWRIGHT_TEST_PASSWORD: E2eTestPassword123!
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
# Started early so it warms up while Python deps install.
|
||||
- name: Start Postgres
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
# ─── Backend stack ─────────────────────────────────────────────────
|
||||
# Builds the e2e image (multi-stage, deps cached via GHA), brings up
|
||||
# db + redis + backend + celery_worker, blocks until every healthcheck
|
||||
# is green. No `uv` invocation on the runner; no PID files; no curl
|
||||
# polling loops; readiness is gated by Docker healthchecks.
|
||||
- name: Build & start backend stack
|
||||
run: |
|
||||
docker run -d \
|
||||
--name surfsense_postgres \
|
||||
-p 5432:5432 \
|
||||
-e POSTGRES_USER=postgres \
|
||||
-e POSTGRES_PASSWORD=postgres \
|
||||
-e POSTGRES_DB=surfsense_e2e \
|
||||
pgvector/pgvector:pg17 \
|
||||
postgres \
|
||||
-c wal_level=logical \
|
||||
-c max_wal_senders=10 \
|
||||
-c max_replication_slots=10
|
||||
docker compose -f docker/docker-compose.e2e.yml \
|
||||
up -d --build --wait --wait-timeout 300
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: '3.12'
|
||||
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v8.1.0
|
||||
|
||||
- name: Cache backend dependencies
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
~/.cache/uv
|
||||
surfsense_backend/.venv
|
||||
key: python-deps-${{ hashFiles('surfsense_backend/uv.lock') }}
|
||||
restore-keys: |
|
||||
python-deps-
|
||||
|
||||
- name: Cache HuggingFace models
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: ~/.cache/huggingface
|
||||
key: hf-models-${{ env.EMBEDDING_MODEL }}-${{ env.ETL_SERVICE }}
|
||||
|
||||
- name: Install backend dependencies
|
||||
working-directory: surfsense_backend
|
||||
run: uv sync
|
||||
|
||||
- name: Wait for Postgres readiness
|
||||
run: |
|
||||
for i in $(seq 1 30); do
|
||||
if docker exec surfsense_postgres pg_isready -U postgres -d surfsense_e2e > /dev/null 2>&1; then
|
||||
echo "Postgres ready after ${i} attempts"
|
||||
exit 0
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
echo "::error::Postgres failed to become ready within 60s"
|
||||
docker logs surfsense_postgres --tail 100
|
||||
exit 1
|
||||
|
||||
- name: Run database migrations
|
||||
working-directory: surfsense_backend
|
||||
run: uv run alembic upgrade head
|
||||
|
||||
# Do NOT replace with `uvicorn main:app`. run_backend.py hijacks
|
||||
# sys.modules["composio"] before app import; production binds it
|
||||
# at import time so plain uvicorn would call the real SDK.
|
||||
- name: Start backend (E2E entrypoint with sys.modules hijack)
|
||||
working-directory: surfsense_backend
|
||||
env:
|
||||
HTTPS_PROXY: http://127.0.0.1:1
|
||||
HTTP_PROXY: http://127.0.0.1:1
|
||||
NO_PROXY: localhost,127.0.0.1,0.0.0.0,huggingface.co,*.huggingface.co,*.hf.co,cdn-lfs.huggingface.co
|
||||
run: |
|
||||
uv run python tests/e2e/run_backend.py \
|
||||
> backend.log 2>&1 &
|
||||
echo $! > backend.pid
|
||||
|
||||
# Worker is a separate interpreter, so the composio hijack must be reapplied.
|
||||
- name: Start Celery worker (E2E entrypoint)
|
||||
working-directory: surfsense_backend
|
||||
env:
|
||||
HTTPS_PROXY: http://127.0.0.1:1
|
||||
HTTP_PROXY: http://127.0.0.1:1
|
||||
NO_PROXY: localhost,127.0.0.1,0.0.0.0,huggingface.co,*.huggingface.co,*.hf.co,cdn-lfs.huggingface.co
|
||||
run: |
|
||||
uv run python tests/e2e/run_celery.py \
|
||||
> celery.log 2>&1 &
|
||||
echo $! > celery.pid
|
||||
|
||||
- name: Wait for backend readiness
|
||||
run: |
|
||||
for i in $(seq 1 60); do
|
||||
if curl -sf http://localhost:8000/openapi.json > /dev/null; then
|
||||
echo "Backend up after ${i} attempts"
|
||||
exit 0
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
echo "::error::Backend failed to start within 120s"
|
||||
echo "===== backend.log (tail 200) ====="
|
||||
tail -200 surfsense_backend/backend.log || true
|
||||
echo "===== celery.log (tail 200) ====="
|
||||
tail -200 surfsense_backend/celery.log || true
|
||||
exit 1
|
||||
|
||||
- name: Wait for Celery worker readiness
|
||||
working-directory: surfsense_backend
|
||||
run: |
|
||||
for i in $(seq 1 30); do
|
||||
if uv run celery -A app.celery_app inspect ping --timeout 2 \
|
||||
> /dev/null 2>&1; then
|
||||
echo "Celery worker up after ${i} attempts"
|
||||
exit 0
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
echo "::error::Celery worker failed to start within 60s"
|
||||
echo "===== celery.log (tail 200) ====="
|
||||
tail -200 celery.log || true
|
||||
exit 1
|
||||
- name: Show backend stack status
|
||||
if: always()
|
||||
run: docker compose -f docker/docker-compose.e2e.yml ps
|
||||
|
||||
- name: Register E2E test user
|
||||
run: |
|
||||
|
|
@ -201,13 +65,14 @@ jobs:
|
|||
exit 1
|
||||
fi
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v6
|
||||
# ─── Frontend (host-side) ──────────────────────────────────────────
|
||||
# Playwright's webServer block in playwright.config.ts spawns
|
||||
# `pnpm build && pnpm start` in CI mode and waits for :3000.
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: '20'
|
||||
|
||||
- name: Install pnpm
|
||||
uses: pnpm/action-setup@v6
|
||||
- uses: pnpm/action-setup@v6
|
||||
with:
|
||||
version: 10
|
||||
|
||||
|
|
@ -221,8 +86,7 @@ jobs:
|
|||
with:
|
||||
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
|
||||
key: pnpm-${{ runner.os }}-${{ hashFiles('surfsense_web/pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
pnpm-${{ runner.os }}-
|
||||
restore-keys: pnpm-${{ runner.os }}-
|
||||
|
||||
- name: Install web dependencies
|
||||
working-directory: surfsense_web
|
||||
|
|
@ -253,10 +117,26 @@ jobs:
|
|||
restore-keys: |
|
||||
nextjs-${{ runner.os }}-${{ hashFiles('surfsense_web/pnpm-lock.yaml') }}-
|
||||
|
||||
# ─── Tests ─────────────────────────────────────────────────────────
|
||||
- name: Run Playwright tests
|
||||
working-directory: surfsense_web
|
||||
run: pnpm test:e2e:prod
|
||||
|
||||
# ─── Failure diagnostics ───────────────────────────────────────────
|
||||
- name: Dump backend stack logs on failure
|
||||
if: failure()
|
||||
run: |
|
||||
mkdir -p ./compose-logs
|
||||
docker compose -f docker/docker-compose.e2e.yml logs --no-color --timestamps \
|
||||
> ./compose-logs/all-services.log 2>&1 || true
|
||||
for svc in db redis backend celery_worker; do
|
||||
docker compose -f docker/docker-compose.e2e.yml logs --no-color --timestamps "$svc" \
|
||||
> "./compose-logs/${svc}.log" 2>&1 || true
|
||||
done
|
||||
docker compose -f docker/docker-compose.e2e.yml ps \
|
||||
> ./compose-logs/ps.txt 2>&1 || true
|
||||
|
||||
# ─── Artifacts ─────────────────────────────────────────────────────
|
||||
- name: Upload Playwright HTML report
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v7
|
||||
|
|
@ -273,26 +153,15 @@ jobs:
|
|||
path: surfsense_web/test-results/
|
||||
retention-days: 14
|
||||
|
||||
- name: Upload backend + celery logs
|
||||
- name: Upload backend stack logs
|
||||
if: failure()
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: backend-celery-logs
|
||||
path: |
|
||||
surfsense_backend/backend.log
|
||||
surfsense_backend/celery.log
|
||||
name: backend-stack-logs
|
||||
path: ./compose-logs/
|
||||
retention-days: 7
|
||||
|
||||
- name: Stop backend + Celery worker
|
||||
# ─── Teardown ──────────────────────────────────────────────────────
|
||||
- name: Tear down backend stack
|
||||
if: always()
|
||||
working-directory: surfsense_backend
|
||||
run: |
|
||||
for f in backend.pid celery.pid; do
|
||||
if [ -f "$f" ]; then
|
||||
kill "$(cat $f)" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
|
||||
- name: Stop Postgres
|
||||
if: always()
|
||||
run: docker rm -f surfsense_postgres 2>/dev/null || true
|
||||
run: docker compose -f docker/docker-compose.e2e.yml down -v --remove-orphans
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue