Skip to content

Add coverage check to pre-commit script #86

@josecelano

Description

@josecelano

Parent Epic: #85

Overview

Add code coverage validation to the pre-commit script (scripts/pre-commit.sh) as the last check in the steps array. The check uses the cargo cov-check alias which validates that coverage meets the 85% threshold and will fail the pre-commit if coverage drops below this level.

Goals

  • Make coverage validation part of the pre-commit process
  • Provide developers immediate feedback about coverage impact
  • Run coverage check last to ensure all other checks pass first (saves time)
  • Use existing step infrastructure for consistency

Specifications

Current Pre-commit Structure

The scripts/pre-commit.sh script uses a step-based execution model with an array of checks. Each step follows the format:
"description|success_message|optional_pre_message|optional_env_var|command"

Proposed Change

Add coverage check as the last step in the STEPS array:

"Running code coverage check|Coverage meets 85% threshold|(Informational only - does not block commits)||cargo cov-check"

Why This Approach?

Advantages:

  • Consistent: Follows existing script patterns
  • Simple: Just one line added to the array
  • Maintainable: No special-case logic needed
  • Clear: Uses same messaging format as other steps
  • Automatic timing: Built-in timing display like other steps

Behavior:

  • Runs last after all other checks pass
  • Still fails fast if coverage is below 85% (exits with non-zero code)
  • Shows clear error message from cargo cov-check
  • Uses existing error handling and timing infrastructure

Implementation Plan

Phase 1: Add Coverage Step (5 minutes)

  • Open scripts/pre-commit.sh
  • Locate the declare -a STEPS=() array
  • Add new line at the end of the array (before the closing parenthesis)
  • The new line should be:
"Running code coverage check|Coverage meets 85% threshold|(Informational only - does not block commits)||cargo cov-check"
  • Save the file

Phase 2: Testing (10 minutes)

  • Run ./scripts/pre-commit.sh on current codebase (coverage should pass at 85.75%)
  • Verify coverage check runs last (after E2E tests)
  • Verify timing is displayed correctly (uses existing timing infrastructure)
  • Verify success message appears when coverage passes
  • Verify script shows clear output from cargo cov-check

Acceptance Criteria

  • Coverage check added as last step in STEPS array in scripts/pre-commit.sh
  • Uses cargo cov-check alias (already exists in .cargo/config.toml)
  • Success message reads: "Coverage meets 85% threshold"
  • Pre-message reads: "(Informational only - does not block commits)"
  • Script exits with non-zero code if coverage is below 85%
  • Timing information is automatically displayed (inherited from step infrastructure)
  • All existing checks still work correctly

Notes

  • Running coverage last ensures developers don't waste time waiting for coverage if linting fails
  • The coverage check will fail fast and block commits if coverage drops below 85%

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions