Skip to content

ci(api): fix coverage collection and enforce a ratchet coverage gate - #135

Merged
EmeditWeb merged 1 commit into
mainfrom
ci/api-coverage-gate
Sep 28, 2026
Merged

EmeditWeb merged 1 commit into
mainfrom
ci/api-coverage-gate

Conversation

@EmeditWeb

Copy link
Copy Markdown
Member

🔖 Title

ci(api): fix coverage collection and enforce a ratchet coverage gate


📝 Description

Coverage was reporting 0% on every run because the Jest config rooted both test discovery and coverage collection under test/, while the application sources live in src/. As a result no source file was ever instrumented, and a spec that lived under src/ was never discovered at all.

This PR fixes coverage collection and adds a non-regression coverage gate so quality can only ratchet up from here.


🔄 Changes Made

  • Move Jest rootDir to the project root; discover specs under both test/ and src/ via roots; collect coverage from src/** into coverage/.
  • Fix src/modules/vendors/vendors.service.spec.ts — provide the missing VendorsRepository and CACHE_MANAGER providers so the Nest testing module can construct VendorsService (it previously failed DI and every case errored). This orphaned spec now runs: 40 suites / 473 tests, up from 39 / 460.
  • Add a global coverageThreshold (statements 45 / branches 30 / functions 35 / lines 45) — a ratchet set a few points below the measured baseline (51.63 / 37.82 / 43.34 / 52.23) so it enforces non-regression without turning main red.
  • CI: run npm run test:cov instead of npm test so the gate is enforced on every PR.

🗒️ Additional Notes

Verified locally — npm run lint:ci, npm run build, and npm run test:cov all exit 0. The threshold buffer (~6–8 points below measured) leaves room for the existing suite to fluctuate while still blocking real regressions; raise it in a later pass as coverage improves.

Coverage was reporting 0% because the jest config rooted discovery and
collection under `test/` while sources live in `src/`, so no source
files were ever instrumented and the in-`src` spec was never discovered.

- Move jest `rootDir` to the project root; discover specs under both
  `test/` and `src/` via `roots`; collect coverage from `src/**` and
  write to `coverage/`. This surfaces the previously-orphaned
  vendors.service.spec.ts (40 suites / 473 tests now run, up from 39/460).
- Fix vendors.service.spec.ts: provide the missing `VendorsRepository`
  and `CACHE_MANAGER` so the Nest testing module can construct
  VendorsService (it previously failed DI and every case errored).
- Add a global `coverageThreshold` (statements 45 / branches 30 /
  functions 35 / lines 45), a ratchet set a few points below the
  measured baseline (51.63 / 37.82 / 43.34 / 52.23) so it enforces
  non-regression without turning main red.
- CI: run `npm run test:cov` instead of `npm test` so the gate is
  enforced on every PR.

Verified locally: `npm run lint:ci`, `npm run build`, and
`npm run test:cov` all exit 0.
@EmeditWeb
EmeditWeb merged commit 0c149cd into main Sep 28, 2026
2 checks passed
@EmeditWeb
EmeditWeb deleted the ci/api-coverage-gate branch September 29, 2026 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant