✨ Enable coverage reporting in CI, add badge, gate new code at 80%#4064
✨ Enable coverage reporting in CI, add badge, gate new code at 80%#4064clubanderson merged 1 commit intomainfrom
Conversation
- Add coverage-gate.yml workflow that runs on PRs touching web/src - Checks line coverage of modified files against 80% threshold - Posts coverage report as a PR comment (warning only, not blocking) - Add json-summary reporter to vitest coverage config - Install @vitest/coverage-v8 for CI coverage collection - Add coverage badge to README Signed-off-by: Andrew Anderson <andy@clubanderson.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
✅ Deploy Preview for kubestellarconsole ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
👋 Hey @clubanderson — thanks for opening this PR!
This is an automated message. |
|
Thank you for your contribution! Your PR has been merged. Check out what's new:
Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey |
There was a problem hiding this comment.
Pull request overview
Adds a CI workflow that runs Vitest coverage on PRs touching web/src/** and posts a per-modified-file coverage report to the PR, along with wiring up Vitest to emit a JSON summary and adding a README coverage badge.
Changes:
- Add
.github/workflows/coverage-gate.ymlto runvitest --coverage, compute coverage for modified files, and comment a markdown report on the PR. - Update
web/vite.config.tsto enable thejson-summarycoverage reporter and add@vitest/coverage-v8to dev dependencies. - Add a static coverage badge to
README.md.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
web/vite.config.ts |
Adds json-summary to coverage reporters so CI can parse per-file coverage. |
web/package.json |
Adds @vitest/coverage-v8 needed for V8-based coverage in Vitest. |
web/package-lock.json |
Locks the new coverage dependency and transitive packages. |
README.md |
Displays a coverage badge on the project README. |
.github/workflows/coverage-gate.yml |
New workflow to run coverage on PRs and post/update a coverage report comment. |
Files not reviewed (1)
- web/package-lock.json: Language not supported
| paths: | ||
| - 'web/src/**' | ||
| - 'web/vite.config.ts' | ||
| - 'web/package.json' |
There was a problem hiding this comment.
The workflow triggers on changes to web/package.json but not web/package-lock.json. Lockfile-only dependency updates can change coverage behavior and should also trigger this workflow; consider adding web/package-lock.json to the on.pull_request.paths list.
| - 'web/package.json' | |
| - 'web/package.json' | |
| - 'web/package-lock.json' |
| ' "$SUMMARY_FILE") | ||
|
|
||
| if [ "$LINE_PCT" = "null" ] || [ -z "$LINE_PCT" ]; then | ||
| REPORT_LINES="${REPORT_LINES}| \`${file}\` | — | No coverage data | :grey_question: |\n" |
There was a problem hiding this comment.
When a modified file has no entry in coverage-summary.json, the script adds a “No coverage data” row but does not flip ALL_PASS to false. That can incorrectly report “All modified files meet the threshold” even though coverage for some modified files is unknown/missing. Treat missing coverage data as below-threshold (or as 0%) so the overall status becomes warn/fail accordingly.
| REPORT_LINES="${REPORT_LINES}| \`${file}\` | — | No coverage data | :grey_question: |\n" | |
| REPORT_LINES="${REPORT_LINES}| \`${file}\` | 0% | ${THRESHOLD}% | :warning: No coverage data |\n" | |
| BELOW_THRESHOLD="${BELOW_THRESHOLD}${file} (no coverage data)\n" | |
| ALL_PASS=false |
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| concurrency: | ||
| group: coverage-gate-${{ github.event.pull_request.number }} | ||
| cancel-in-progress: true |
There was a problem hiding this comment.
This job requests pull-requests: write and runs on pull_request, which includes fork PRs. On fork PRs, GITHUB_TOKEN is read-only, so the “Comment on PR” step will 403 and fail the job. Consider gating write/commenting behavior behind a same-repo check (e.g., github.event.pull_request.head.repo.id == github.repository_id as used in .github/workflows/handle-complications.lock.yml:53) or making the comment step non-fatal for forks.
| const { data: comments } = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.issue.number, | ||
| }); | ||
|
|
||
| const existing = comments.find(c => c.body.includes(marker)); |
There was a problem hiding this comment.
github.rest.issues.listComments is not paginated here (defaults to 30). If a PR has many comments, the existing marker comment may not be returned and the workflow can create duplicate coverage comments. Use github.paginate(...) (or request a higher per_page and paginate) when searching for the marker.
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| }); | |
| const existing = comments.find(c => c.body.includes(marker)); | |
| const comments = await github.paginate( | |
| github.rest.issues.listComments, | |
| { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| per_page: 100, | |
| }, | |
| ); | |
| const existing = comments.find(c => c.body && c.body.includes(marker)); |
🔄 Auto-Applying Copilot Code ReviewCopilot code review found 3 code suggestion(s) and 1 general comment(s). @copilot Please apply all of the following code review suggestions:
Also address these general comments:
Push all fixes in a single commit. Run Auto-generated by copilot-review-apply workflow. |
Summary
.github/workflows/coverage-gate.ymlruns on PRs that touchweb/src/**. It runsvitest --coverage, then parses the JSON summary to check line coverage of only the files modified in the PR against an 80% threshold.README.md(currently shows 25% — will be updated as coverage improves).json-summaryreporter so the gate script can parse per-file coverage. Installed@vitest/coverage-v8as a devDependency.How it works
mainthat modifyweb/src/**,web/vite.config.ts, orweb/package.jsonnpx vitest run --coveragein theweb/directory.ts/.tsxfiles (excluding tests) viagit diffcoverage/coverage-summary.jsonTest plan
python3 -c "import yaml; yaml.safe_load(...)")npm run buildpasses