Skip to content

test: fail the test run when coverage of src/ drops - #91

Merged
johnf merged 1 commit into
mainfrom
test/coverage-threshold
Nov 17, 2026
Merged

johnf merged 1 commit into
mainfrom
test/coverage-threshold

Conversation

@johnf

@johnf johnf commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

pnpm test now measures coverage of src/ and fails when it drops below the thresholds in vitest.config.ts. Vitest raises the thresholds itself whenever a run beats them; the aim is 100%. Decided in "Test strategy for the indexer" (#89).

 pnpm test
-  vitest run
+  vitest run --coverage
+    measure src/**  (not generated code, tests, or src/index.ts)
+    if below thresholds  -> fail
+    if above thresholds  -> rewrite them in vitest.config.ts (commit that)

Entry points run as their own node process, which coverage can't see. They are left out, on the rule (now in CLAUDE.md) that they only parse arguments and call code in src/. Import was the one script holding logic, so it moves:

 scripts/
-└── crates-import.ts        # 44 lines: walks the directory, imports each crate
+└── crates-import.ts        # wrapper: open the repository, call importCrates
 src/
+├── crates-import.ts        # importCrates(repository, source)
+├── crates-import.test.ts   # was test/crates-import.test.ts; now calls it in-process
 └── ocfl-repository.ts      # openOrCreateRepository takes an optional root

The real crates:import command is still run as a command by test/bootstrap.test.ts and by the ocflStorage test helper.

Evidence

  • Before: no coverage measured. Measured once on main (ec91b82) over src/ and scripts/: 89.11% lines, 85.65% branches, 92.6% functions.
    After: 27 files, 229 tests pass; the starting thresholds, written by the first run:
lines 93.52   branches 87.44   functions 95.33   statements 93.84

pnpm lint (biome, knip, tsc) passes.

Merge Danger

Door: two-way

Revert the commit, or lower the numbers in vitest.config.ts.

Blast Radius: contributors

  • Any open branch that lowers coverage of src/ fails pnpm test after rebasing onto this.
  • A run that beats the thresholds edits vitest.config.ts locally; that change needs committing.
  • If CI ever measures a fraction lower than a local run, the test job fails with no code change. This pull request's own CI run is the first check of that.
  • The indexer redesign deletes and replaces src/indexer/; its new folders are to be held at 100% from their first commit (per Test strategy for the indexer #89), which is not part of this change.

Coverage is measured on every pnpm test run. The thresholds start at
today's numbers and vitest raises them whenever a run beats them; the
aim is 100%.

Entry points (scripts/, src/index.ts) run as their own process, which
coverage can't see, so they are left out. The Import logic moves from
scripts/crates-import.ts into src/ so that it is measured, and its test
calls it in-process.
@johnf
johnf marked this pull request as ready for review November 17, 2026 03:41
@johnf
johnf merged commit 63860bd into main Nov 17, 2026
5 checks passed
@johnf
johnf deleted the test/coverage-threshold branch November 17, 2026 03:42
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