Coverage Gate + Critical-path Tests
At a glance
Coverage gate enforcing 80 % line coverage on the API via pytest-cov plus a critical-path test suite for the seven flows with direct revenue or GDPR impact. Both required CI checks block merges; an informal PR coverage comment and a soft frontend coverage gate keep the team honest without flapping.
How it works
Coverage runs on every API PR through pytest-cov with fail_under=80 and branch coverage enabled. The exclusion list is explicit and conservative — migrations, seeds, __init__.py and TYPE_CHECKING blocks — so the number reflects code that actually executes in production. A coverage.xml artefact uploads on each PR for downstream tooling (the PR comment, dashboards, archival).
The PR gets an automatic comment from py-cov-action/python-coverage-comment-action@v3 with line and branch percentages, deltas versus base and a per-file table. The action is wrapped in continue-on-error=true so a comment posting failure does not block the merge — the gate that matters is the coverage check itself, not the cosmetics. The required check ci-api / coverage refuses to merge anything below 80 %, so the team cannot ship a regression by accident.
The critical-path suite under api/tests/critical_path/ is the second required gate. Seven files cover roughly 55 tests across the flows where a regression has direct cost: signup → subscription → invoice → Stripe charge, license issuance and renewal, GDPR data export, GDPR right-to-erasure, audit-log integrity, capability denial, and payment refund. The suite runs against an in-memory MongoDB via mongomock_motor and a fully mocked Stripe so it is hermetic and fast — full execution measured in seconds, not minutes. The required check ci-api / critical-path blocks merge if any of those flows breaks, regardless of whether the overall coverage number is fine.
Frontend coverage gets a softer treatment because the apps' test surface is shifting fast. admin npm test --coverage runs in CI with continue-on-error=true so a regression flags the PR but does not block, and the coverage artefact uploads with 14-day retention. The intent is to grow toward a hard gate as the suite matures, not to ship one before the team has confidence that the number is stable enough to enforce on every merge.
Key capabilities
- pytest-cov coverage gate at fail_under=80 with branch coverage enabled
- Conservative exclusion list (migrations, seeds, __init__.py, TYPE_CHECKING blocks)
- PR coverage comment via py-cov-action with line/branch percentages and per-file deltas
- Required CI check ci-api / coverage blocking merge below 80 %
- Critical-path test suite of ~55 tests across 7 revenue/GDPR-impact flows
- In-memory MongoDB (mongomock_motor) and mocked Stripe for hermetic, fast critical-path runs
- Required CI check ci-api / critical-path blocking merge on broken billing or GDPR flow
- Frontend coverage soft gate with 14-day artefact retention
In practice
A developer refactors the license-issuance service. The PR runs CI: pytest-cov reports 81.4 %, the coverage comment lands with a green delta, and the critical-path suite passes — license_issuance.test.py covered the new code paths because every revenue-critical flow has explicit tests. They merge.
Two weeks later a downstream PR accidentally breaks the audit-log write inside the GDPR data-export flow; coverage stays at 81 % because line coverage has not changed, but ci-api / critical-path goes red on the data-export test and the merge is blocked. The developer gets the failure with the exact assertion line, fixes the broken contract before merging, and the GDPR commitment to users is preserved by a test that cared about the flow, not just the percentage.
Features in this subsystem
6| ID | Status | Features |
|---|---|---|
| F16.17.01 | Shipped | pytest-cov coverage-gate — fail_under=80, branch=true, coverage.xml-artefakt uppladdad per PR. Exkluderar migrations, seeds, __init__.py, TYPE_CHECKING-block. ✅ PL-T051 |
| F16.17.02 | Shipped | PR coverage-kommentar via py-cov-action/python-coverage-comment-action@v3 — informell, continue-on-error=true, blockar inte på kommentarfel. ✅ PL-T051 |
| F16.17.03 | Shipped | ci-api / coverage som required check — blockar merge vid < 80 % line-täckning. ✅ PL-T051 |
| F16.17.04 | Shipped | Critical-path testsvit api/tests/critical_path/ — 7 filer, 55+ tester, in-memory MongoDB (mongomock_motor), Stripe mockad. ✅ PL-T051 |
| F16.17.05 | Shipped | ci-api / critical-path som required check — blockar merge vid trasigt billing- eller GDPR-flöde. ✅ PL-T051 |
| F16.17.06 | Shipped | Frontend coverage soft gate — admin npm test --coverage i CI, continue-on-error=true, artefakt uppladdad 14 dagar. ✅ PL-T051 |