From c886d6640d4aff3b1422c914561ca72c6d47a3dc Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Sun, 8 Mar 2026 02:20:58 +0530 Subject: [PATCH 1/7] feat: add GA workflow for backend tests including both unit and integration tests --- .github/workflows/backend-tests.yml | 141 ++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 .github/workflows/backend-tests.yml diff --git a/.github/workflows/backend-tests.yml b/.github/workflows/backend-tests.yml new file mode 100644 index 000000000..4a2fa5397 --- /dev/null +++ b/.github/workflows/backend-tests.yml @@ -0,0 +1,141 @@ +name: Backend Tests + +on: + pull_request: + branches: [main, dev] + types: [opened, synchronize, reopened, ready_for_review] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + unit-tests: + name: Unit Tests + runs-on: ubuntu-latest + if: github.event.pull_request.draft == false + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Check if backend files changed + id: backend-changes + uses: dorny/paths-filter@v3 + with: + filters: | + backend: + - 'surfsense_backend/**' + + - name: Set up Python + if: steps.backend-changes.outputs.backend == 'true' + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install UV + if: steps.backend-changes.outputs.backend == 'true' + uses: astral-sh/setup-uv@v3 + + - name: Cache dependencies + if: steps.backend-changes.outputs.backend == 'true' + uses: actions/cache@v4 + with: + path: | + ~/.cache/uv + surfsense_backend/.venv + key: python-deps-${{ hashFiles('surfsense_backend/uv.lock') }} + restore-keys: | + python-deps- + + - name: Install dependencies + if: steps.backend-changes.outputs.backend == 'true' + working-directory: surfsense_backend + run: uv sync + + - name: Run unit tests + if: steps.backend-changes.outputs.backend == 'true' + working-directory: surfsense_backend + run: uv run pytest -m unit + + integration-tests: + name: Integration Tests + runs-on: ubuntu-latest + if: github.event.pull_request.draft == false + + services: + postgres: + image: pgvector/pgvector:pg17 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: surfsense_test + ports: + - 5432:5432 + options: >- + --health-cmd "pg_isready -U postgres -d surfsense_test" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Check if backend files changed + id: backend-changes + uses: dorny/paths-filter@v3 + with: + filters: | + backend: + - 'surfsense_backend/**' + + - name: Set up Python + if: steps.backend-changes.outputs.backend == 'true' + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install UV + if: steps.backend-changes.outputs.backend == 'true' + uses: astral-sh/setup-uv@v3 + + - name: Cache dependencies + if: steps.backend-changes.outputs.backend == 'true' + uses: actions/cache@v4 + with: + path: | + ~/.cache/uv + surfsense_backend/.venv + key: python-deps-${{ hashFiles('surfsense_backend/uv.lock') }} + restore-keys: | + python-deps- + + - name: Install dependencies + if: steps.backend-changes.outputs.backend == 'true' + working-directory: surfsense_backend + run: uv sync + + - name: Run integration tests + if: steps.backend-changes.outputs.backend == 'true' + working-directory: surfsense_backend + env: + TEST_DATABASE_URL: postgresql+asyncpg://postgres:postgres@localhost:5432/surfsense_test + run: uv run pytest -m integration + + test-gate: + name: Test Gate + runs-on: ubuntu-latest + needs: [unit-tests, integration-tests] + if: always() + + steps: + - name: Check all test jobs + run: | + if [[ "${{ needs.unit-tests.result }}" == "failure" || + "${{ needs.integration-tests.result }}" == "failure" ]]; then + echo "Backend tests failed" + exit 1 + else + echo "All backend tests passed" + fi From 53f3be2873b1cd658ed94fdd787ea0b322fcfdc2 Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Sun, 8 Mar 2026 02:23:01 +0530 Subject: [PATCH 2/7] chore: update GitHub Actions workflow to use latest versions of actions/checkout, astral-sh/setup-uv, and actions/cache --- .github/workflows/backend-tests.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/backend-tests.yml b/.github/workflows/backend-tests.yml index 4a2fa5397..b9c385f34 100644 --- a/.github/workflows/backend-tests.yml +++ b/.github/workflows/backend-tests.yml @@ -17,7 +17,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Check if backend files changed id: backend-changes @@ -35,11 +35,11 @@ jobs: - name: Install UV if: steps.backend-changes.outputs.backend == 'true' - uses: astral-sh/setup-uv@v3 + uses: astral-sh/setup-uv@v7 - name: Cache dependencies if: steps.backend-changes.outputs.backend == 'true' - uses: actions/cache@v4 + uses: actions/cache@v5 with: path: | ~/.cache/uv @@ -80,7 +80,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Check if backend files changed id: backend-changes @@ -98,11 +98,11 @@ jobs: - name: Install UV if: steps.backend-changes.outputs.backend == 'true' - uses: astral-sh/setup-uv@v3 + uses: astral-sh/setup-uv@v7 - name: Cache dependencies if: steps.backend-changes.outputs.backend == 'true' - uses: actions/cache@v4 + uses: actions/cache@v5 with: path: | ~/.cache/uv From 36836a1d8b22e5807887ddab6d3ee8b5bda245a1 Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Sun, 8 Mar 2026 02:33:35 +0530 Subject: [PATCH 3/7] chore: add embedding model in env for backend tests workflow --- .github/workflows/backend-tests.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/backend-tests.yml b/.github/workflows/backend-tests.yml index b9c385f34..46ecbd14e 100644 --- a/.github/workflows/backend-tests.yml +++ b/.github/workflows/backend-tests.yml @@ -14,6 +14,8 @@ jobs: name: Unit Tests runs-on: ubuntu-latest if: github.event.pull_request.draft == false + env: + EMBEDDING_MODEL: sentence-transformers/all-MiniLM-L6-v2 steps: - name: Checkout code @@ -48,6 +50,13 @@ jobs: restore-keys: | python-deps- + - name: Cache HuggingFace models + if: steps.backend-changes.outputs.backend == 'true' + uses: actions/cache@v5 + with: + path: ~/.cache/huggingface + key: hf-models-${{ env.EMBEDDING_MODEL }} + - name: Install dependencies if: steps.backend-changes.outputs.backend == 'true' working-directory: surfsense_backend @@ -62,6 +71,8 @@ jobs: name: Integration Tests runs-on: ubuntu-latest if: github.event.pull_request.draft == false + env: + EMBEDDING_MODEL: sentence-transformers/all-MiniLM-L6-v2 services: postgres: @@ -111,6 +122,13 @@ jobs: restore-keys: | python-deps- + - name: Cache HuggingFace models + if: steps.backend-changes.outputs.backend == 'true' + uses: actions/cache@v5 + with: + path: ~/.cache/huggingface + key: hf-models-${{ env.EMBEDDING_MODEL }} + - name: Install dependencies if: steps.backend-changes.outputs.backend == 'true' working-directory: surfsense_backend From ca3710a239aed2b652f4a61241d19db82ce92b35 Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Sun, 8 Mar 2026 02:41:05 +0530 Subject: [PATCH 4/7] fix: remove slowapi limiter for testing --- .../tests/integration/document_upload/conftest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/surfsense_backend/tests/integration/document_upload/conftest.py b/surfsense_backend/tests/integration/document_upload/conftest.py index 6daa171d6..41639fc2f 100644 --- a/surfsense_backend/tests/integration/document_upload/conftest.py +++ b/surfsense_backend/tests/integration/document_upload/conftest.py @@ -22,7 +22,7 @@ from sqlalchemy import text from sqlalchemy.ext.asyncio import create_async_engine from sqlalchemy.pool import NullPool -from app.app import app +from app.app import app, limiter from app.config import config as app_config from app.db import Base from app.services.task_dispatcher import get_task_dispatcher @@ -35,6 +35,8 @@ from tests.utils.helpers import ( get_search_space_id, ) +limiter.enabled = False + _EMBEDDING_DIM = app_config.embedding_model_instance.dimension _ASYNCPG_URL = TEST_DATABASE_URL.replace("postgresql+asyncpg://", "postgresql://") From ea004ec66432dac620b6c4c48dbdd7e04dcf92c4 Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Sun, 8 Mar 2026 02:45:04 +0530 Subject: [PATCH 5/7] chore: add SECRET_KEY environment variable for CI testing in backend workflow --- .github/workflows/backend-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/backend-tests.yml b/.github/workflows/backend-tests.yml index 46ecbd14e..d7f3f2bdc 100644 --- a/.github/workflows/backend-tests.yml +++ b/.github/workflows/backend-tests.yml @@ -139,6 +139,7 @@ jobs: working-directory: surfsense_backend env: TEST_DATABASE_URL: postgresql+asyncpg://postgres:postgres@localhost:5432/surfsense_test + SECRET_KEY: ci-test-secret-key-not-for-production run: uv run pytest -m integration test-gate: From 560e51c95ffad9c13dc1c23a13d6a5101242ef7d Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Sun, 8 Mar 2026 02:49:13 +0530 Subject: [PATCH 6/7] chore: add ETL_SERVICE environment variable for CI testing in backend workflow --- .github/workflows/backend-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/backend-tests.yml b/.github/workflows/backend-tests.yml index d7f3f2bdc..6e0a6db6d 100644 --- a/.github/workflows/backend-tests.yml +++ b/.github/workflows/backend-tests.yml @@ -140,6 +140,7 @@ jobs: env: TEST_DATABASE_URL: postgresql+asyncpg://postgres:postgres@localhost:5432/surfsense_test SECRET_KEY: ci-test-secret-key-not-for-production + ETL_SERVICE: DOCLING run: uv run pytest -m integration test-gate: From 8122370cec3a0752d0e521eb471323fdf47985ef Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Sun, 8 Mar 2026 02:53:47 +0530 Subject: [PATCH 7/7] test: mark test_connector_document.py with unit pytest marker --- .../tests/unit/indexing_pipeline/test_connector_document.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/surfsense_backend/tests/unit/indexing_pipeline/test_connector_document.py b/surfsense_backend/tests/unit/indexing_pipeline/test_connector_document.py index 228777626..2136f2152 100644 --- a/surfsense_backend/tests/unit/indexing_pipeline/test_connector_document.py +++ b/surfsense_backend/tests/unit/indexing_pipeline/test_connector_document.py @@ -4,6 +4,8 @@ from pydantic import ValidationError from app.db import DocumentType from app.indexing_pipeline.connector_document import ConnectorDocument +pytestmark = pytest.mark.unit + def test_valid_document_created_with_required_fields(): """All optional fields default correctly when only required fields are supplied."""