diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml index 4e43ee6..049c0fd 100644 --- a/.forgejo/workflows/ci.yml +++ b/.forgejo/workflows/ci.yml @@ -1,11 +1,14 @@ name: CI -# Per FabledRulebook/forgejo.md: "CI runs analyzers + short unit tests. -# Integration tests that need real Postgres/ffmpeg run locally via -# docker-compose." So this workflow deliberately does NOT spin up service -# containers; DB-dependent tests are marked `@pytest.mark.integration` and -# excluded with `-m "not integration"`. To run integration tests, operator -# uses docker-compose locally. +# CI policy (amends the older FabledRulebook/forgejo.md "lint + unit only" +# stance — operator opted in to running integration in CI): +# - backend-lint-and-test: fast feedback — ruff + `pytest -m "not +# integration"`, no service containers. +# - frontend-build: vitest unit + vite build. +# - integration: spins up pgvector Postgres + Redis service containers, +# migrates a throwaway test DB, runs `pytest -m integration`. This is +# the first time the integration suite runs anywhere, so expect a +# debugging tail until it goes green. on: push: @@ -36,7 +39,7 @@ jobs: - name: Ruff lint run: ruff check backend/ tests/ alembic/ - - name: Pytest (unit tests only — integration tests run locally) + - name: Pytest (unit only — integration runs in the integration job) run: pytest tests/ -v -m "not integration" frontend-build: @@ -57,3 +60,50 @@ jobs: # convert to TS or add JSDoc. - run: npm run test:unit - run: npm run build + + integration: + # First-ever execution of the integration suite. Postgres uses the same + # pgvector image as docker-compose; Redis backs the celery smoke tests. + # Assumes the python-ci runner executes jobs in a container so services + # are reachable by name (postgres/redis). If the runner runs jobs on the + # host instead, switch DB_HOST to localhost + add `ports:` mappings. + runs-on: python-ci + env: + DB_USER: fabledcurator + DB_PASSWORD: ci_integration + DB_HOST: postgres + DB_PORT: "5432" + DB_NAME: fabledcurator_test + SECRET_KEY: ci_integration_placeholder + CELERY_BROKER_URL: redis://redis:6379/0 + CELERY_RESULT_BACKEND: redis://redis:6379/0 + services: + postgres: + image: pgvector/pgvector:pg16 + env: + POSTGRES_USER: fabledcurator + POSTGRES_PASSWORD: ci_integration + POSTGRES_DB: fabledcurator_test + options: >- + --health-cmd "pg_isready -U fabledcurator" + --health-interval 10s + --health-timeout 5s + --health-retries 10 + redis: + image: redis:7-alpine + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 10 + steps: + - uses: actions/checkout@v4 + + - name: Install Python deps + run: pip install -r requirements.txt pytest pytest-asyncio + + - name: Migrate the test database + run: alembic upgrade head + + - name: Pytest (integration only) + run: pytest tests/ -v -m integration diff --git a/pyproject.toml b/pyproject.toml index 3a476ff..eb26856 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,9 +9,9 @@ where = ["."] include = ["backend*"] [tool.pytest.ini_options] -# Per FabledRulebook/forgejo.md: CI runs lint + short unit tests only. -# Integration tests that need a real Postgres/Redis run locally via -# docker-compose; CI passes `-m "not integration"` to skip them. +# The fast backend job runs `-m "not integration"`; the dedicated CI +# `integration` job (pgvector Postgres + Redis service containers) runs +# `-m integration`. Both also runnable locally via docker-compose. markers = [ - "integration: tests that require a real Postgres/Redis. Run locally via docker-compose, skipped in CI.", + "integration: tests that require a real Postgres/Redis. Run by the CI integration job and locally via docker-compose.", ]