Testing Strategy & CI/CD
Relevant source files
The following files were used as context for generating this wiki page:
Polar employs a multi-layered testing strategy designed to ensure the reliability of its payment infrastructure. The strategy encompasses backend unit and integration tests, frontend component and E2E testing, and specialized load testing for performance verification. This approach is tightly integrated with a CI/CD pipeline that automates linting, type checking, and internationalization workflows.
Sources: AGENTS.md:129-141, CONTRIBUTING.md:46-55, DEVELOPMENT.md:445-452
Backend Testing Framework
The backend testing environment is built on pytest and follows a modular structure that mirrors the application code. Tests are categorized into unit tests for business logic and integration tests for API endpoints and background tasks.
Test Structure and Organization
Backend tests are located in the server/tests/ directory. The structure is designed so that a source file at server/polar/foo/endpoints.py has a corresponding test file at tests/foo/test_endpoints.py. Polar utilizes class-based tests where each class typically focuses on a single method, covering various scenarios as individual test cases.
Sources: AGENTS.md:129-138, server/CLAUDE.md:195-199
Key Testing Components
| Component | Description | Tools/Markers |
|---|---|---|
| Unit Tests | Tests service-layer business logic in isolation. | pytest.mark.asyncio, mocker |
| Endpoint Tests | Integration tests for FastAPI routes; verifies status codes and responses. | pytest.mark.auth, AsyncClient |
| Task Tests | E2E tests for background workers (Dramatiq) without extensive mocking. | test_task |
| External Mocking | Simulated interactions with external services like Stripe. | MagicMock |
Sources: AGENTS.md:139-143, server/CLAUDE.md:213-239
Database and Fixtures
Tests leverage pytest fixtures to manage database state. Common fixtures include AsyncSession for database interactions and SaveFixture for persisting test data. Developers are instructed to avoid redundant setup, such as manually setting fields that fixtures already provide (e.g., Stripe IDs for customer fixtures).
Sources: AGENTS.md:141-145, server/CLAUDE.md:216-220
Frontend and E2E Testing
The frontend testing strategy combines local testing of Next.js components with comprehensive End-to-End (E2E) testing to validate critical user flows, particularly the checkout process.
E2E Flow and Automated Healing
E2E tests target the web dashboard and checkout links. Polar utilizes an "E2E Flakiness Analysis" system that categorizes failures into flakiness, regressions, or environment issues. This system uses Chrome DevTools MCP to reproduce steps and can automatically suggest or apply fixes to flaky tests.
The diagram shows the logic flow for analyzing and resolving E2E test failures.
Sources: clients/apps/web/e2e/healing/prompts/e2e-checkout-healing.md:16-55
Development and CI Constraints
- Scope: Automated healing agents are restricted to modifying files within
clients/apps/web/e2e/and cannot change application source code. - Tools: The environment uses
pnpm testfor running frontend tests.
Sources: clients/apps/web/e2e/healing/prompts/e2e-checkout-healing.md:128-132, CLAUDE.md:15
Load Testing Infrastructure
Polar maintains a comprehensive load testing suite located in server/load_tests/ to stress-test payment infrastructure, webhook processing, and background job performance.
Performance Scenarios
The infrastructure uses Locust to simulate user behavior. Key scenarios include:
- Checkout Flow: Simulates creating checkouts, updating customer details, and confirmation.
- Event Ingestion: Simulates high-volume event patterns (e.g., 7 events per batch).
Load Scaling Guide
| Target Events/Min | Users | HTTP RPS (Requests Per Sec) |
|---|---|---|
| ~420 | 1 | ~1 |
| ~1680 | 4 | ~4 |
| ~2940 | 7 | ~7 |
Sources: server/load_tests/README.md:1-55
Architecture of the load testing components interacting with the API.
Sources: server/load_tests/README.md:33-50
CI/CD and Contribution Workflow
The CI/CD pipeline enforces code quality and automates repetitive tasks like internationalization.
Quality Enforcement
All contributions must pass a set of automated checks before manual review:
- Linting:
uv run task lintfor Python; automated formatting checks for TypeScript. - Type Checking:
uv run task lint_types(mypy) for backend. - Subquery Linting: A custom script
scripts/lint_subquery.pyflags SQLAlchemy.subquery()calls that do not explicitly narrow columns.
Sources: CONTRIBUTING.md:46-55, server/pyproject.toml:91-94, server/CLAUDE.md:43-46
Internationalization (i18n) Pipeline
Polar uses an automated CI job for translations. Developers only modify the English locale file (en.ts).
The sequence of automated translation during the CI process.
Sources: AGENTS.md:154-159
CI Configuration Summary
| Task | Command | Purpose |
|---|---|---|
| API Lint | ruff check . | Python style and logic errors |
| Type Check | mypy polar scripts tests | Backend static type verification |
| DB Migration Check | alembic upgrade head | Verifies migration integrity |
| Tech Notes | ./tech-notes --check | Validates tech note listings in the handbook |
Sources: server/pyproject.toml:88-95, handbook/README.md:18-20
Summary
The testing strategy at Polar is a robust combination of traditional automated testing and modern AI-assisted flakiness healing. By integrating load testing directly into the development cycle and automating complex workflows like i18n and SQL subquery linting, the project maintains high standards for its payment-critical infrastructure. Developers are expected to run the full suite of uv run task test and uv run task lint locally before submission to align with these CI standards.
Sources: CONTRIBUTING.md:32-40, AGENTS.md:58-62