Skip to content

Setup precommit hooks and check for coverage levels in CI.#163

Open
dlrice wants to merge 1 commit intomainfrom
ci-coverage
Open

Setup precommit hooks and check for coverage levels in CI.#163
dlrice wants to merge 1 commit intomainfrom
ci-coverage

Conversation

@dlrice
Copy link
Copy Markdown
Contributor

@dlrice dlrice commented Apr 29, 2026

Purpose

Addresses #162

Tighten the local feedback loop for routine maintenance. Today, lint, type, and test failures only surface after pushing — sometimes only after a PR review reveals a red check. There are no local hooks. Coverage is tracked (since the vitest baseline in #130) but no threshold is enforced, so coverage can drift downward silently between refactors.

This PR adds the mainstream three-tier check pattern (pre-commit / pre-push / CI), shifting routine failures left to local hooks, and wires a coverage-threshold check into CI so coverage can only ratchet upward.

Approach

Three tiers of checks:

  1. Pre-commit runs lint-staged against staged files only — ESLint --fix + Prettier --write on .ts/.tsx, Prettier --write on .md/.json/.yml/.yaml. Sub-second on typical diffs.
  2. Pre-push runs yarn test — the same lint + types + unit checks CI runs. Mirrors CI exactly so failures show up locally before the push lands.
  3. CI adds a Coverage threshold step (yarn test:coverage) using vitest's built-in coverage.thresholds. Initial threshold values are zero placeholders — running yarn test:coverage:ratchet lifts them to the current observed baseline using vitest's --coverage.thresholds.autoUpdate flag. Once seeded, coverage can only go up; CI fails on a drop.

Tooling: Husky 9 + lint-staged (de-facto JavaScript standards). Hooks install automatically via the prepare script — no per-contributor setup. Documented in CONTRIBUTING.md (new "Hooks and feedback loop" section) and README.md (CI section refreshed; the stale hardcoded coverage table replaced with a pointer to vite.config.mjs as the live source of truth).

Bundled minor cleanups: added prettier as a direct devDependency (it was previously a missing peer of eslint-plugin-prettier); added a test:coverage:ratchet script for ratcheting thresholds; updated the README's "Coverage is not collected in CI today" line, which this PR makes obsolete.

Testing

Manual verification (no new unit tests; this is pure tooling):

  • yarn installprepare: husky runs, .husky/_/ infrastructure created.
  • Pre-commit smoke test — staged a TS file with a fixable lint issue; git commit invoked yarn lint-staged, the file was auto-fixed, the commit landed cleanly.
  • Pre-push smoke test — pushed to a throwaway side branch; yarn test ran end-to-end. Confirmed that introducing a deliberate test failure blocks the push with non-zero exit.
  • yarn test:coverage — confirmed vitest produces the coverage report and applies the (currently zero) thresholds without failing.
  • yarn test:coverage:ratchet — confirmed vitest rewrites the thresholds: block in vite.config.mjs with the observed values.
  • CI workflow — the new "Coverage threshold" step runs in the existing test job after Unit tests. Verified the YAML parses cleanly.

Visual changes

N/A — pure tooling. No UI, render, or build-output changes.

Checklist

  • My PR is scoped properly, and "does one thing only" — strictly tooling: hooks, coverage threshold, and the directly-related README/CONTRIBUTING refresh. Other stale items in README (configuration-shape JSON, events block, protvista-uniprot v3/v5 compatibility section) are flagged as a separate v5 docs PR.
  • I have reviewed my own code
  • I have checked that linting checks pass and type safety is respected
  • I have checked that tests pass and coverage has at least improved, and if not explained the reasons why — tests pass. Coverage itself is unchanged (no new tests; this PR adds infrastructure for tracking, not tests). Thresholds are zero placeholders; running yarn test:coverage:ratchet either before merge or in a follow-up commit lifts them to the current baseline.

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