Running Tests
DocuGardener has three test suites: Python unit + integration tests (pytest), frontend component tests (Vitest), and end-to-end browser tests (Playwright).
Python Tests (pytest)
The Python test suite covers the analysis pipeline, LLM provider integrations, quota enforcement, RQ job handling, and API routes.
Setup
# From the project root python -m venv .venv source .venv/bin/activate # Windows: .venvScriptsactivate pip install -e ".[dev]"
Running
# All tests source .venv/bin/activate && pytest # Specific test file pytest tests/unit/test_anthropic_provider.py # Specific test pytest tests/unit/test_rq_stability.py::TestRQStability::test_priority_queues # With output pytest -s -v
Test structure
| Path | What it covers |
|---|---|
| tests/unit/ | Pure logic: LLM clients, quota, rate limiter, pipeline stages, HMAC, rules compiler |
| tests/integration/ | API routes hitting a real test DB (PostgreSQL must be running) |
| tests/e2e/ | Full end-to-end flows (requires E2E_ENABLED=1 and a running stack) |
| tests/conftest.py | Root fixtures — stubs gitpython on macOS where Xcode licence is absent |
Infrastructure-dependent tests: Integration tests under
tests/integration/ require a running PostgreSQL instance. Run pytest tests/unit/ -q to run only self-contained unit tests with no external dependencies.Frontend Tests (Vitest)
Component tests for Next.js UI. Covers feature gating, settings forms, LLM config chip UX, audit log, billing banners, and API route handlers.
cd web # Run all tests once npx vitest run # Watch mode (dev) npx vitest # Single file npx vitest run __tests__/llm-provider-chips.test.tsx # Coverage report npx vitest run --coverage
Test files location
Tests live alongside their source files as *.test.tsx / *.test.ts, or in web/__tests__/.
Mocking gotchas
- Use
vi.clearAllMocks()inbeforeEach, notvi.resetAllMocks()— reset removes spy implementations. - When mocking
lucide-react, include every icon the component imports — a missing icon mock throws at render time. - Prisma client must be mocked with
vi.mock("@/lib/prisma")in route handler tests.
End-to-End Tests (Playwright)
Browser-level tests covering full user flows: login, repo setup, triage inbox, plan gating, and settings.
Prerequisites
cd web npx playwright install --with-deps chromium
Running
# The full stack must be running first (make dev-up from project root) # Run all E2E tests npx playwright test # Run with UI (headed) npx playwright test --headed # Single spec npx playwright test e2e/specs/01-auth.spec.ts # View test report npx playwright show-report
Dev login
E2E tests use the dev-login NextAuth provider (not credentials). The login email placeholder is [email protected].
Known pre-existing E2E failures: SPEC-RBAC-03, SPEC-SSO-01/02, SPEC-TEAM-02, SPEC-GAPE-01/02 fail due to missing infrastructure (Okta, multi-seat setup). 37/51 pass in a standard local environment.