diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3f0fb1e..6fd27f0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -36,8 +36,8 @@ repos: - repo: local hooks: - id: run-tests - name: Run pytest tests - entry: bash -c 'if command -v uv > /dev/null 2>&1; then uv run pytest tests/ || exit 1; else echo "WARNING - uv not found, skipping tests"; fi' + name: Run pytest with branch-coverage gate + entry: bash -c 'if ! command -v uv > /dev/null 2>&1; then echo "WARNING - uv not found, skipping tests and coverage gate"; exit 0; fi; if ! git rev-parse --verify --quiet origin/main > /dev/null 2>&1; then echo "ERROR - origin/main not resolvable locally; fetch origin main and retry"; exit 1; fi; uvx --with torch --with pytest-cov --with diff-cover pytest --cov=NRS --cov-branch --cov-report=xml --cov-report=term-missing tests/; status=$?; if [ $status -ne 0 ]; then rm -f coverage.xml .coverage; exit $status; fi; uvx --with diff-cover diff-cover coverage.xml --compare-branch=origin/main --branch-coverage --fail-under=90; cov_status=$?; rm -f coverage.xml .coverage; exit $cov_status' language: system stages: [pre-push] always_run: true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cec4207..139410e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -54,6 +54,12 @@ Thank you for your interest in contributing! This document provides guidelines f pre-commit install --hook-type pre-push ``` + The pre-push hook runs the full test suite with branch coverage and blocks + the push if changed code drops below 90% branch coverage (via pytest-cov + + diff-cover, mirroring CI). It needs `uv` installed — if `uv` isn't found, + the check is skipped with a warning — and `origin/main` fetched locally so + there's something to diff against. + 6. **Verify setup**: ```bash