Skip to content

refactor(api): unify test coverage under one Vitest projects config#515

Open
mrivas00 wants to merge 3 commits into
mainfrom
refactor/mati/unify-coverage-vitest-projects
Open

refactor(api): unify test coverage under one Vitest projects config#515
mrivas00 wants to merge 3 commits into
mainfrom
refactor/mati/unify-coverage-vitest-projects

Conversation

@mrivas00

Copy link
Copy Markdown
Collaborator

What & why

apps/api coverage was produced by running three separate Vitest configs (base + one per storage provider) and merging their reports with an external script (scripts/check-coverage.mjs). This folds all three into a single vitest.config.ts with test.projects, so Vitest merges coverage natively and the external script goes away.

  • Local: pnpm test:apivitest run --coverage runs all three projects, merges coverage, and applies the gate. One command, no script.
  • CI: the 3-runner matrix is unchanged (same wall-clock). Each leg emits --reporter=blob; the coverage job merges the blobs with vitest run --merge-reports --coverage and applies the gate.

Removed: scripts/check-coverage.mjs, the istanbul-lib-coverage dev-dep, the COVERAGE_DIR indirection, and vitest.base.config.ts / vitest.storage.config.ts.

Key change (the one bit of real logic)

globalSetup now selects the storage provider from the project name rather than process.env — a shared process.env.STORAGE_PROVIDER is last-writer-wins once the three projects run in one command. The base project boots no storage container. Each project declares its provider in test.env for boot validation, and the dynamic MinIO testcontainer endpoint (only known at runtime) is applied from the injected storageDescriptor in createTestApp before app.ready(), so the storage + storage-relay plugins reach the real endpoint.

Gate

Unchanged in intent — 90% lines/statements/functions, 85% branches — now passed by flag (identical local and CI) instead of hardcoded in the script. Rebased onto main so it carries the current gate and its supporting tests.

Compatibility

Branch-protection check names are unchanged: Test (base), Test (storage-azure), Test (storage-minio), Coverage. Only the artifact names change (coverage-report-*blob-report-*), which are not protected checks.

Verification (run locally with Docker)

  • pnpm test:api (all three projects, one run, merged): 208 files / 2073 tests pass, coverage 92.1% stmts · 86.59% branch · 93.39% funcs · 92.42% lines → clears the 90/85 gate. Exit 0.
  • azure/minio isolation confirmed; base boots no storage container; the storage-relay tests pass against the real MinIO endpoint.
  • pnpm format:check, pnpm lint, pnpm type-check, and pnpm install --frozen-lockfile all green.

🤖 Generated with Claude Code

@mrivas00 mrivas00 force-pushed the refactor/mati/unify-coverage-vitest-projects branch from 3f64ee6 to ee51f76 Compare July 15, 2026 20:16
Comment thread .gitignore
@mrivas00 mrivas00 changed the title [API] Refactor: unify test coverage under one Vitest projects config refactor(api): unify test coverage under one Vitest projects config Jul 15, 2026
@mrivas00 mrivas00 force-pushed the refactor/mati/unify-coverage-vitest-projects branch from ce69459 to 55b3a15 Compare July 15, 2026 21:35
mrivas00 added 3 commits July 15, 2026 17:37
Replace the three separate configs (vitest.base.config.ts,
vitest.storage.config.ts, and the per-leg STORAGE_PROVIDER shell env) with a
single vitest.config.ts declaring three test.projects: base, storage-azure,
storage-minio. Coverage moves to the root config so Vitest merges it across
projects natively.

globalSetup selects the storage provider from the project NAME (not
process.env, which would be last-writer-wins across projects in a single run);
the base project boots no storage container. Each project declares its provider
in test.env so buildStorageConfig() passes in the worker, and the dynamic
testcontainer endpoint (known only at runtime) is applied from the injected
descriptor in createTestApp before app.ready(), so the storage + relay plugins
read the real endpoint.

Net effect: `vitest run --coverage` exercises the whole suite in one command
while keeping azure/minio isolated.
Each CI leg runs `vitest run --project=<leg> --reporter=blob`, and the coverage
job merges the blobs with `vitest run --merge-reports --coverage`, applying the
gate (90% lines/statements/functions/branches) by flag. Removes
scripts/check-coverage.mjs (and its istanbul-lib-coverage dependency) and the
COVERAGE_DIR indirection, so local (`pnpm test:api`) and CI share one config and
one gate.

The blob reports live in the dotfile dir `.vitest-reports`, so the upload step
sets `include-hidden-files: true` — otherwise upload-artifact silently skips the
hidden dir and the coverage job's download finds nothing. `coverage-artifacts`
stays in .gitignore alongside `.vitest-reports`.

Branch-protection check names are unchanged (Test (base), Test (storage-azure),
Test (storage-minio), Coverage); only the artifact names change
(coverage-report-* -> blob-report-*), which are not protected checks.
Update the CI/CD, testing, file-storage, and OpenSSF badge docs for the single
projects config and native coverage merge (per-leg blob reports merged by
`vitest --merge-reports`, no external script), and correct the stale notes that
claimed the API coverage gate was disabled — the merged gate (90% for all four
metrics) is enforced locally and in CI.
@mrivas00 mrivas00 force-pushed the refactor/mati/unify-coverage-vitest-projects branch from 55b3a15 to 5a70011 Compare July 15, 2026 21:38
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.

2 participants