COVERAGE SYSTEM - nself-org/cli GitHub Wiki
Complete documentation of nself's test coverage infrastructure for achieving and maintaining 100% coverage.
nself has implemented a comprehensive test coverage system to track, report, and enforce 100% test coverage across the entire codebase.
Current Status: โ 100% Coverage Achieved
Coverage System
โโโ Collection (collect-coverage.sh)
โ โโโ Runs all test suites
โ โโโ Uses kcov for bash coverage
โ โโโ Aggregates coverage data
โ
โโโ Reporting (generate-coverage-report.sh)
โ โโโ Text reports
โ โโโ HTML reports
โ โโโ JSON data
โ โโโ SVG badges
โ
โโโ Verification (verify-coverage.sh)
โ โโโ Enforces requirements
โ โโโ Fails CI if below threshold
โ โโโ Shows gap analysis
โ
โโโ History Tracking (track-coverage-history.sh)
โ โโโ Stores coverage per commit
โ โโโ Generates trend charts
โ โโโ Tracks progress over time
โ
โโโ Diff Analysis (coverage-diff.sh)
โโโ Compares branches
โโโ Shows PR impact
โโโ Identifies coverage changes
nself/
โโโ src/scripts/coverage/ # Coverage scripts
โ โโโ collect-coverage.sh # Main collection script
โ โโโ generate-coverage-report.sh # Report generator
โ โโโ verify-coverage.sh # Requirement enforcer
โ โโโ track-coverage-history.sh # History tracker
โ โโโ coverage-diff.sh # Diff analyzer
โ โโโ install-coverage-tools.sh # Tool installer
โ โโโ pre-commit-hook.sh # Git hook template
โ โโโ README.md # Script documentation
โ โโโ QUICK-REFERENCE.md # Quick commands
โ
โโโ coverage/ # Generated coverage data
โ โโโ data/ # Raw coverage from tests
โ โ โโโ unit/ # Unit test coverage
โ โ โโโ integration/ # Integration coverage
โ โ โโโ security/ # Security coverage
โ โ โโโ e2e/ # E2E coverage
โ โโโ reports/ # Generated reports
โ โ โโโ coverage.txt # Text report
โ โ โโโ coverage.json # JSON data
โ โ โโโ badge.svg # Badge
โ โ โโโ summary.txt # Quick summary
โ โ โโโ trend.txt # Trend report
โ โ โโโ html/ # HTML reports
โ โ โโโ index.html # Main HTML report
โ โโโ .coverage-history.json # Historical data
โ
โโโ docs/development/ # Coverage documentation
โ โโโ COVERAGE-GUIDE.md # Complete guide
โ โโโ COVERAGE-DASHBOARD.md # Live dashboard
โ โโโ COVERAGE-SYSTEM.md # This file
โ
โโโ .github/workflows/
โโโ coverage.yml # CI/CD workflow
- Line Coverage: Percentage of code lines executed by tests
- Branch Coverage: Percentage of decision branches taken
- Function Coverage: Percentage of functions called
- Test Count: Total number of tests
- Pass Rate: Percentage of tests passing
- Execution Time: Test suite duration
| Metric | Required | Warning | Action |
|---|---|---|---|
| Line Coverage | 100.0% | - | CI fails โ |
| Branch Coverage | 95.0% | < 95% | Warning only |
| Function Coverage | 100.0% | < 100% | Warning only |
# 1. Collect coverage from all test suites
./src/scripts/coverage/collect-coverage.sh
# 2. Generate reports in multiple formats
./src/scripts/coverage/generate-coverage-report.sh
# 3. Track in history for trend analysis
./src/scripts/coverage/track-coverage-history.sh track
# 4. Verify requirements (fails if < 100%)
./src/scripts/coverage/verify-coverage.sh# Make code changes
vim src/lib/auth/oauth.sh
# Run relevant tests
./src/tests/run-init-tests.sh
# Check coverage
./src/scripts/coverage/collect-coverage.sh
./src/scripts/coverage/verify-coverage.sh
# If coverage < 100%, add tests
vim src/tests/unit/test-oauth.sh
# Verify again
./src/scripts/coverage/collect-coverage.sh
./src/scripts/coverage/verify-coverage.sh
# Commit when coverage is good
git commit -am "feat: add oauth feature with tests"- On Push/PR: Coverage workflow runs automatically
- Collection: All test suites run with coverage tracking
- Reporting: Reports generated and uploaded as artifacts
- Verification: CI fails if coverage < 100%
- PR Comment: Coverage summary posted to PR
- Badge Update: Coverage badge updated on main branch
- History: Coverage entry added to history
Terminal-friendly summary with:
- Overall coverage percentage
- Line/branch/function breakdown
- Progress bar visualization
- Test statistics
- Coverage by module
- Gap analysis
Location: coverage/reports/coverage.txt
Usage:
cat coverage/reports/coverage.txtInteractive browser-based report with:
- File browser with coverage percentages
- Line-by-line coverage highlighting
- Branch coverage visualization
- Test execution counts
- Uncovered code identification
Location: coverage/reports/html/index.html
Usage:
open coverage/reports/html/index.htmlMachine-readable data for:
- Automation
- Integration with other tools
- Custom reporting
- API consumption
Location: coverage/reports/coverage.json
Usage:
jq '.overall' coverage/reports/coverage.jsonSVG badge showing:
- Current coverage percentage
- Color-coded (green = 100%, yellow = 80-99%, red < 80%)
Location: coverage/reports/badge.svg
Usage:
Workflow: .github/workflows/coverage.yml
Triggers:
- Push to
mainordevelop - Pull requests
- Manual workflow dispatch
Jobs:
-
coverage - Main coverage job
- Install coverage tools
- Run tests with coverage
- Generate reports
- Verify requirements
- Upload to Codecov
- Upload artifacts
- Comment on PR
- Update badge
-
coverage-summary - Summary job
- Download artifacts
- Display summary
- Report final status
Pull requests automatically receive:
-
Coverage Comment:
## ๐ Coverage Report **Overall Coverage:** 100.0% **Target:** 100% **Gap:** 0.0% ๐ **100% Coverage Achieved!**
-
Coverage Diff:
- Shows coverage change vs base branch
- Identifies new uncovered code
- Prevents coverage decreases
-
Status Check:
- โ Pass if coverage >= 100%
- โ Fail if coverage < 100%
Optional git hook to verify coverage before commit.
Installation:
cp src/scripts/coverage/pre-commit-hook.sh .git/hooks/pre-commit
chmod +x .git/hooks/pre-commitBehavior:
- Runs coverage verification
- Blocks commit if coverage < 100%
- Can be bypassed with
SKIP_COVERAGE_CHECK=true
Coverage data is tracked over time in .coverage-history.json:
{
"version": "1.0",
"created": "2026-01-31T21:45:00Z",
"commits": [
{
"sha": "af3ad41",
"date": "2026-01-31",
"coverage": 100.0,
"tests": 700
},
{
"sha": "5184aa5",
"date": "2026-01-30",
"coverage": 65.0,
"tests": 445
}
]
}View coverage trends:
# Show trend chart
./src/scripts/coverage/track-coverage-history.sh show
# Generate trend report
./src/scripts/coverage/track-coverage-history.sh reportOutput:
Coverage Trend:
Commit Date Coverage Change
--------------------------------------------------
af3ad41 2026-01-31 100.0% +35.0%
5184aa5 2026-01-30 65.0% +5.0%
b0af0e0 2026-01-29 60.0% +0.0%
- Bash 3.2+ - Shell execution (built-in)
- bc - Mathematical calculations (built-in on most systems)
-
kcov - Bash code coverage collection
# Ubuntu/Debian sudo apt-get install kcov # macOS brew install kcov
-
lcov - Coverage data merging
sudo apt-get install lcov # Linux brew install lcov # macOS
-
jq - JSON processing
sudo apt-get install jq # Linux brew install jq # macOS
Quick install all tools:
./src/scripts/coverage/install-coverage-tools.shIf coverage tools aren't available:
- Scripts use manual instrumentation
- Coverage still works (slower)
- Reduced accuracy but functional
# Always verify coverage before committing
./src/scripts/coverage/verify-coverage.sh# Generate HTML report to see what's uncovered
./src/scripts/coverage/generate-coverage-report.sh
open coverage/reports/html/index.html
# Red lines = uncovered code
# Write tests for red lines# Coverage should never decrease
# Add tests when adding code
# Review coverage diff in PRs
./src/scripts/coverage/coverage-diff.sh diff main HEAD# Install hook to catch coverage issues early
cp src/scripts/coverage/pre-commit-hook.sh .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit# Regularly check dashboard for gaps
cat docs/development/COVERAGE-DASHBOARD.md| Issue | Cause | Solution |
|---|---|---|
| kcov not found | Tool not installed | Run install-coverage-tools.sh
|
| No coverage data | Collection not run | Run collect-coverage.sh first |
| Coverage < 100% | Missing tests | View HTML report, add tests |
| Test failures | Code errors | Fix tests before collecting coverage |
| Wrong permissions | File mode issues | Check script permissions (755) |
Run scripts with debug output:
bash -x ./src/scripts/coverage/collect-coverage.shEmergency bypass (NOT recommended):
SKIP_COVERAGE_CHECK=true git commit- Weekly: Review coverage dashboard
- Per PR: Check coverage diff
- Per Release: Verify 100% coverage
- Monthly: Review trend history
When modifying coverage scripts:
- Test on Ubuntu and macOS
- Ensure backward compatibility
- Update documentation
- Test CI/CD integration
- Update quick reference
- Coverage Guide - Complete usage guide
- Coverage Dashboard - Live status dashboard
- Script README - Script documentation
- Quick Reference - Quick commands
-
collect-coverage.sh- Collection -
generate-coverage-report.sh- Reporting -
verify-coverage.sh- Verification -
track-coverage-history.sh- History -
coverage-diff.sh- Diff analysis
- Mutation testing integration
- Performance benchmarking coverage
- Load testing coverage
- Chaos engineering coverage
- Coverage heat maps
- Interactive trend visualization
- Coverage prediction models
- Automated coverage improvement suggestions
nself's coverage system provides:
โ Comprehensive tracking across all test suites โ Multiple report formats (text, HTML, JSON, badge) โ CI/CD integration with automatic verification โ Historical tracking for trend analysis โ PR integration with coverage diffs โ Developer tools for local verification โ 100% coverage achieved and maintained
Goal: Maintain 100% test coverage to ensure reliability and quality.
Status: ๐ 100% Coverage Achieved! โ