一键导入
coverage-readme-workflow-skill
Ensure test coverage percentage is displayed in README.md for Next.js and Python projects following industry standards
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Ensure test coverage percentage is displayed in README.md for Next.js and Python projects following industry standards
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Deploy and troubleshoot Next.js 16+ applications on AWS Amplify Hosting — build spec (amplify.yml), SSR Lambda env-var injection, CloudFront OAC, Route53 DNS, GitHub Actions deploy triggers, post-deploy verification, and rollback strategy
Design and document APIs — REST conventions, OpenAPI/Swagger spec generation, GraphQL schema patterns, API versioning, pagination, rate limiting, error response formats, and HATEOAS
Implement authentication and authorization patterns — OAuth2/OIDC flows, JWT best practices, session management, RBAC/ABAC, NextAuth/Auth.js, Passport.js, password hashing, and CSRF protection
Apply clean architecture principles with vertical slicing, dependency rule, clear layer boundaries, and feature-first organization - language-agnostic
Write clean, human-readable code with proper naming, small functions, self-documenting patterns, and object calisthenics - language-agnostic
Detect and fix code smells including long methods, large classes, feature envy, primitive obsession, and more with refactoring guidance - language-agnostic
| name | coverage-readme-workflow-skill |
| description | Ensure test coverage percentage is displayed in README.md for Next.js and Python projects following industry standards |
| license | Apache-2.0 |
| compatibility | opencode |
| metadata | {"audience":"developers","workflow":"test-coverage-documentation","protocol":"autoresearch-opt-in"} |
I implement a complete test coverage documentation workflow that ensures coverage percentages are displayed in README.md files:
Use this workflow when:
Integration: This skill is typically used alongside:
test-generator-framework: After generating testsnextjs-unit-test-creator: After generating Next.js testspython-pytest-creator: After generating Python testsnextjs-pr-workflow: Before creating a PRpr-creation-workflow: Before creating a PRpackage.json OR Python project with pyproject.toml/requirements.txtNote: If coverage tools are not installed, this skill will guide you through installation.
Determine project type by checking configuration files:
# Check for Next.js project
if [ -f "package.json" ]; then
if grep -q '"next"' package.json; then
PROJECT_TYPE="nextjs"
else
PROJECT_TYPE="nodejs"
fi
fi
# Check for Python project
if [ -f "pyproject.toml" ] || [ -f "requirements.txt" ]; then
PROJECT_TYPE="python"
fi
echo "Detected project type: $PROJECT_TYPE"
Project Types:
nextjs: Next.js application (React framework)nodejs: JavaScript/TypeScript project without Next.jspython: Python project# Check package.json for test dependencies
if grep -q '"vitest"' package.json; then
TEST_FRAMEWORK="vitest"
COVERAGE_CMD="npm run test -- --coverage"
elif grep -q '"jest"' package.json; then
TEST_FRAMEWORK="jest"
COVERAGE_CMD="npm run test -- --coverage"
else
# Check for test scripts
if grep -q '"test:coverage"' package.json; then
COVERAGE_CMD="npm run test:coverage"
else
echo "⚠️ No coverage command found in package.json"
echo "Please add coverage script to package.json"
fi
fi
# Check if pytest-cov is installed
if grep -q '"pytest-cov"' pyproject.toml 2>/dev/null || grep -q "pytest-cov" requirements.txt 2>/dev/null; then
TEST_FRAMEWORK="pytest"
COVERAGE_CMD="poetry run pytest --cov=. --cov-report=term 2>/dev/null || pytest --cov=. --cov-report=term"
else
echo "⚠️ pytest-cov not installed"
echo "Install with: pip install pytest-cov"
echo "Or with Poetry: poetry add --group dev pytest-cov"
fi
# Run coverage
echo "Running coverage for Next.js project..."
$COVERAGE_CMD 2>&1 | tee /tmp/coverage_output.txt
# Parse coverage output
COVERAGE_PERCENT=$(grep -oP '\d+(?=%)' /tmp/coverage_output.txt | head -1)
LINES_COV=$(grep -oP 'Lines\s*:\s*\K\d+(?=%)' /tmp/coverage_output.txt | head -1)
STATEMENTS_COV=$(grep -oP 'Statements\s*:\s*\K\d+(?=%)' /tmp/coverage_output.txt | head -1)
BRANCHES_COV=$(grep -oP 'Branches\s*:\s*\K\d+(?=%)' /tmp/coverage_output.txt | head -1)
FUNCTIONS_COV=$(grep -oP 'Functions\s*:\s*\K\d+(?=%)' /tmp/coverage_output.txt | head -1)
echo "Coverage Results:"
echo " Total: ${COVERAGE_PERCENT}%"
echo " Lines: ${LINES_COV}%"
echo " Statements: ${STATEMENTS_COV}%"
echo " Branches: ${BRANCHES_COV}%"
echo " Functions: ${FUNCTIONS_COV}%"
# Run coverage
echo "Running coverage for Python project..."
$COVERAGE_CMD 2>&1 | tee /tmp/coverage_output.txt
# Parse coverage output
COVERAGE_PERCENT=$(grep -oP '\d+(?=%)' /tmp/coverage_output.txt | head -1)
LINES_COV=$(grep -oP 'Lines\s*:\s*\K\d+(?=%)' /tmp/coverage_output.txt | head -1)
BRANCHES_COV=$(grep -oP 'Branches\s*:\s*\K\d+(?=%)' /tmp/coverage_output.txt | head -1)
echo "Coverage Results:"
echo " Total: ${COVERAGE_PERCENT}%"
echo " Lines: ${LINES_COV}%"
echo " Branches: ${BRANCHES_COV}%"
Create coverage badge in industry-standard Shields.io format:
# Badge URL format
BADGE_URL="https://img.shields.io/badge/coverage-${COVERAGE_PERCENT}%25-${BADGE_COLOR}.svg"
# Determine badge color based on coverage percentage
if [ "${COVERAGE_PERCENT}" -ge 80 ]; then
BADGE_COLOR="brightgreen"
elif [ "${COVERAGE_PERCENT}" -ge 60 ]; then
BADGE_COLOR="yellow"
elif [ "${COVERAGE_PERCENT}" -ge 40 ]; then
BADGE_COLOR="orange"
else
BADGE_COLOR="red"
fi
# Generate badge markdown
COVERAGE_BADGE=""
echo "Coverage badge: ${COVERAGE_BADGE}"
Badge Color Scheme (Industry Standard):
if grep -q "coverage" README.md; then
EXISTING_COVERAGE=true
echo "Found existing coverage badge in README.md"
else
EXISTING_COVERAGE=false
echo "No existing coverage badge found"
fi
For Next.js Projects:
if [ "$EXISTING_COVERAGE" = "true" ]; then
# Update existing coverage badge
sed -i "s|!\[Coverage\](.*)|${COVERAGE_BADGE}|" README.md
else
# Add new coverage badge section
# Find the badges line or project title
if grep -q "^\[!\[" README.md; then
# Insert after existing badges
sed -i "/^\[!\[.*\](.*)\]/a ${COVERAGE_BADGE}" README.md
else
# Insert after project title
sed -i "1,/^# /s|^# \(.*\)|# \1\n\n${COVERAGE_BADGE}|" README.md
fi
fi
For Python Projects:
if [ "$EXISTING_COVERAGE" = "true" ]; then
# Update existing coverage badge
sed -i "s|!\[Coverage\](.*)|${COVERAGE_BADGE}|" README.md
else
# Add new coverage badge section
if grep -q "^\[!\[" README.md; then
# Insert after existing badges
sed -i "/^\[!\[.*\](.*)\]/a ${COVERAGE_BADGE}" README.md
else
# Insert after project title
sed -i "1,/^# /s|^# \(.*\)|# \1\n\n${COVERAGE_BADGE}|" README.md
fi
fi
# Add detailed coverage section to README
# NOTE: Use unquoted heredoc (EOF not 'EOF') so variables expand
if ! grep -q "## Test Coverage" README.md; then
cat >> README.md <<EOF
## Test Coverage
[]
| Metric | Coverage |
|--------|----------|
| Lines | ${LINES_COV}% |
| Statements | ${STATEMENTS_COV}% |
| Branches | ${BRANCHES_COV}% |
| Functions | ${FUNCTIONS_COV}% |
**Total Coverage:** ${COVERAGE_PERCENT}%
To run tests with coverage:
\`\`\`bash
${COVERAGE_CMD}
\`\`\`
EOF
fi
echo "✅ README.md updated successfully!"
echo ""
echo "Coverage badge added:"
grep -o '\[!\[Coverage\].*svg\)' README.md
echo ""
echo "To view README.md:"
echo " cat README.md"
echo ""
echo "To commit changes:"
echo " git add README.md"
echo " git commit -m 'docs: update coverage badge to ${COVERAGE_PERCENT}%'"
echo "==================================================================="
echo "Coverage Documentation Complete!"
echo "==================================================================="
echo ""
echo "Project Type: $PROJECT_TYPE"
echo "Test Framework: $TEST_FRAMEWORK"
echo ""
echo "Coverage Results:"
echo " Overall: ${COVERAGE_PERCENT}%"
echo " Lines: ${LINES_COV}%"
if [ -n "${STATEMENTS_COV}" ]; then
echo " Statements: ${STATEMENTS_COV}%"
fi
if [ -n "${BRANCHES_COV}" ]; then
echo " Branches: ${BRANCHES_COV}%"
fi
if [ -n "${FUNCTIONS_COV}" ]; then
echo " Functions: ${FUNCTIONS_COV}%"
fi
echo ""
echo "Badge Color: ${BADGE_COLOR}"
echo "Badge URL: ${BADGE_URL}"
echo ""
echo "README.md has been updated with coverage badge."
echo "==================================================================="

## Badges
[](https://github.com/username/repo/actions/workflows/test.yml)
[](https://github.com/username/repo/actions/workflows/test.yml)
## Test Coverage
| Metric | Coverage | Badge |
|--------|----------|--------|
| Overall | 85% |  |
| Lines | 87% |  |
| Branches | 82% |  |
| Functions | 88% |  |
**To run tests with coverage:**
```bash
npm run test -- --coverage
## Coverage Thresholds (Industry Standards)
| Coverage Range | Quality Level | Badge Color | Action Required |
|----------------|--------------|-------------|----------------|
| 90-100% | Excellent | brightgreen | Maintain |
| 80-89% | Good | brightgreen | Monitor |
| 70-79% | Acceptable | yellow | Improve |
| 60-69% | Fair | orange | Improve |
| 0-59% | Poor | red | Improve immediately |
## Best Practices
- **Minimum Coverage**: Aim for at least 80% coverage for production code
- **Badge Placement**: Place coverage badge prominently at the top of README.md
- **Automatic Updates**: Set up CI/CD pipeline to update badge automatically
- **Multiple Metrics**: Display overall coverage and breakdown (lines, branches, functions)
- **Trend Tracking**: Consider showing coverage trends over time
- **Threshold Enforcement**: Configure coverage thresholds in test configuration
- **False Positives**: Exclude test files and non-critical code from coverage
- **Documentation**: Explain how to run tests with coverage in README.md
## Next.js-Specific Best Practices
### Jest Configuration:
```javascript
// jest.config.js
module.exports = {
collectCoverageFrom: [
'components/**/*.{js,jsx,ts,tsx}',
'app/**/*.{js,jsx,ts,tsx}',
'lib/**/*.{js,jsx,ts,tsx}',
'!**/*.d.ts',
'!**/node_modules/**',
'!**/.next/**',
],
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
},
}
// vitest.config.ts
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
exclude: [
'node_modules/',
'.next/',
'**/*.d.ts',
'**/*.config.*',
],
threshold: {
lines: 80,
functions: 80,
branches: 80,
statements: 80,
},
},
},
})
# .coveragerc
[run]
omit =
tests/*
*/tests/*
*/__init__.py
*/migrations/*
venv/*
.venv/*
[report]
exclude_lines =
pragma: no cover
def __repr__
raise AssertionError
raise NotImplementedError
if __name__ == .__main__.:
if TYPE_CHECKING:
# pytest.ini
[pytest]
addopts = --cov=. --cov-report=term-missing --cov-fail-under=80
# pyproject.toml
[tool.pytest.ini_options]
addopts = "--cov=. --cov-report=term-missing --cov-fail-under=80"
[tool.coverage.run]
omit = [
"tests/*",
"*/tests/*",
"*/__init__.py",
]
[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"raise AssertionError",
"raise NotImplementedError",
"if __name__ == .__main__.:",
]
Issue: Coverage percentage not extracted from test output
Solution:
# Check coverage output manually
npm run test -- --coverage
# or
pytest --cov=. --cov-report=term
# Verify coverage output format
# Jest/Vitest: "Coverage summary: 85%"
# pytest: "TOTAL 85%"
Issue: README.md badge shows old coverage percentage
Solution:
# Remove existing coverage badge
sed -i '/!\[Coverage\]/d' README.md
# Re-run coverage workflow
# This will re-add the badge with updated percentage
Issue: npm run test -- --coverage fails
Solution:
For Next.js with Jest:
# Add coverage script to package.json
jq '.scripts["test:coverage"] = "jest --coverage"' package.json > tmp.json && mv tmp.json package.json
# Or add flag to existing test script
jq '.scripts.test += " --coverage"' package.json > tmp.json && mv tmp.json package.json
For Next.js with Vitest:
{
"scripts": {
"test:coverage": "vitest --coverage"
}
}
For Python with pytest:
# Install pytest-cov
pip install pytest-cov
# Or with Poetry
poetry add --group dev pytest-cov
Issue: README.md file doesn't exist
Solution:
# Create README.md
cat > README.md << 'EOF'
# Project Name
Brief description of the project.
EOF
# Now run coverage workflow to add badge
Issue: Coverage badge shows red color (below 40%)
Solution:
npm run test -- --coverage --coverageReporters=jsoncoverage/coverage-final.jsonIssue: Test files or non-critical code included in coverage
Solution:
For Jest/Vitest:
// Update jest.config.js or vitest.config.ts
collectCoverageFrom: [
'src/**/*.{js,jsx,ts,tsx}',
'!src/**/*.test.{js,jsx,ts,tsx}',
'!src/**/*.spec.{js,jsx,ts,tsx}',
'!src/types/**',
]
For pytest:
# Update .coveragerc or pyproject.toml
[run]
omit =
tests/*
*/tests/*
test_*.py
*_test.py
Before running coverage workflow:
After running coverage workflow:
DO NOT execute any of the following unless AUTORESEARCH_PROTOCOL=1 is set in your environment. When unset, this skill behaves exactly as documented in all sections above; the Iteration Protocol block is descriptive only.
When AUTORESEARCH_PROTOCOL=1:
autoresearch-core-skill/SKILL.md.{"pass":bool,"score":N} JSON from a mechanical evaluator. Pass determines keep/revert; score logged to coverage-results.tsv. See autoresearch-core-skill/references/evaluator-contract.md.autoresearch-core-skill/references/stuck-detection.md.coverage-results.tsv (8-column: iteration, commit, metric, delta, status, description, timestamp, evaluator_output). See autoresearch-core-skill/references/audit-trail.md.autoresearch-core-skill/references/crash-recovery.md.git reset --hard HEAD~1) on pass:false.Iterations: 25); safety blocks .env, node_modules/, rm -rf, git push --force. See autoresearch-core-skill/references/iteration-safety.md.Full iteration loop. Converts the one-shot coverage display into an iterative loop targeting a coverage percentage goal. Metric = coverage %; direction = maximize; target = user-specified (default 80%). Emits coverage-results.tsv. Pass = coverage ≥ target.
Iterations: unlimited overrides)