-
Notifications
You must be signed in to change notification settings - Fork 103
docs(#2810): add patch coverage verification guidance for agents #6138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| --- | ||
| name: check-patch-coverage | ||
| description: >- | ||
| Verify approximate Go patch coverage meets the repo's 80% Codecov threshold. | ||
| Use after writing or updating Go production code — before committing — to | ||
| catch coverage gaps that would fail the codecov/patch status check. | ||
| --- | ||
|
|
||
| # Check Patch Coverage | ||
|
|
||
| Verify that new or changed Go production code meets the **80% patch | ||
| coverage** threshold configured in [`.codecov.yml`](../../.codecov.yml) | ||
| before committing. This prevents `codecov/patch` failures on first push. | ||
|
|
||
| ## When to use | ||
|
|
||
| - After implementing or modifying Go production code under `cmd/` or | ||
| `internal/` (files that are **not** `_test.go`). | ||
| - After adding tests for new code — to confirm coverage is sufficient. | ||
| - When the fix agent is addressing a coverage-related failure. | ||
|
|
||
| ## When to skip | ||
|
|
||
| - Test-only changes (no production `.go` files modified). | ||
| - Documentation, config, or generated-code-only changes. | ||
| - Files listed in `.codecov.yml` `ignore:` — these are excluded from | ||
| coverage enforcement. | ||
|
|
||
| ## Procedure | ||
|
|
||
| ### 1. Identify changed production files | ||
|
|
||
| Determine which non-test Go files you changed relative to the target | ||
| branch. **Stage new files first** (`git add`) — `git diff --name-only` | ||
| only sees tracked or staged files, so an unstaged new file would be | ||
| invisible and the check would silently skip it. | ||
|
|
||
| ```bash | ||
| CHANGED_GO=$(git diff --name-only main -- '*.go' | grep -v '_test.go') | ||
| echo "$CHANGED_GO" | ||
| ``` | ||
|
|
||
| If the list is empty, patch coverage does not apply — stop here. | ||
|
|
||
| ### 2. Determine affected packages | ||
|
|
||
| ```bash | ||
| PKGS=$(echo "$CHANGED_GO" | xargs -I{} dirname {} | sort -u | sed 's|^|./|') | ||
| echo "$PKGS" | ||
| ``` | ||
|
|
||
| ### 3. Run tests with a cover profile | ||
|
|
||
| ```bash | ||
| go test -coverprofile=coverage.out -count=1 $PKGS | ||
| ``` | ||
|
|
||
| If tests fail, fix them first — coverage is meaningless on broken code. | ||
|
|
||
| ### 4. Check per-function coverage on changed files | ||
|
|
||
| For each changed file, inspect coverage: | ||
|
|
||
| ```bash | ||
| for f in $CHANGED_GO; do | ||
| echo "=== $f ===" | ||
| go tool cover -func=coverage.out | grep "$f" || echo "(no coverage data)" | ||
| done | ||
| ``` | ||
|
|
||
| Each output line shows `file:line: function coverage%`. | ||
|
|
||
| ### 5. Assess against the 80% threshold | ||
|
|
||
| Look at the functions you added or modified: | ||
|
|
||
| - **All functions ≥ 80%:** Coverage is sufficient. Proceed to commit. | ||
| - **Some functions below 80%:** Add or extend `_test.go` files to cover | ||
| the missing lines. Focus on: | ||
| - New functions you added (these must be tested) | ||
| - Modified functions where you added new branches or error paths | ||
| - Functions at 0% that contain logic (not just simple getters/setters) | ||
|
|
||
| After adding tests, re-run from step 3 and re-check. | ||
|
|
||
| ### 6. Visual inspection (optional, for complex cases) | ||
|
|
||
| If function-level coverage is borderline or the function has complex | ||
| branching: | ||
|
|
||
| ```bash | ||
| go tool cover -html=coverage.out | ||
| ``` | ||
|
|
||
| This opens an HTML view showing exactly which lines are covered (green) | ||
| and which are not (red). Use this to target your test additions. | ||
|
|
||
| ## Understanding the approximation | ||
|
|
||
| This procedure approximates Codecov's **line-level patch coverage** | ||
| using Go's **function-level coverage** (`go tool cover -func`). The | ||
| local check is coarser — Codecov counts individual lines in the diff, | ||
| while `go tool cover -func` reports per-function percentages. Aim for | ||
| **≥ 80%** on touched functions to stay above the threshold with margin. | ||
|
|
||
| The configured tolerance is **5%** (from `.codecov.yml`), so Codecov | ||
| will pass at 75% in practice. But targeting 80% locally accounts for | ||
| the approximation gap between function-level and line-level metrics. | ||
|
|
||
| ## Thresholds reference | ||
|
|
||
| From [`.codecov.yml`](../../.codecov.yml): | ||
|
|
||
| - **Patch coverage target:** 80% (5% tolerance) | ||
| - **Project coverage:** must not drop more than 1% below base branch | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.