Skip to content

feat(ci,scripts): add Go differential coverage tool and CI reporting - #1258

Merged
kyasbal merged 6 commits into
mainfrom
push-pnvpywzuyvzy
Nov 11, 2026
Merged

kyasbal merged 6 commits into
mainfrom
push-pnvpywzuyvzy

Conversation

@kyasbal

@kyasbal kyasbal commented Nov 11, 2026

Copy link
Copy Markdown
Member

Summary

Adds a standard-library Go differential coverage analyzer (scripts/coverage-diff), a local make coverage-diff target, and GitHub Actions reporting in pullrequest.yaml without relying on external coverage services.

  • scripts/coverage-diff:
    • Extracts added/modified executable lines from jj (fork_point(@ | trunk())..@) or git (merge-base / HEAD^1..HEAD) while excluding tests, pkg/generated/, zzz_*.go, pkg/testutil/, scripts/, and web/.
    • Uses go/scanner token inspection alongside Go coverprofile blocks so comments, blank lines, and closing braces are not miscounted, while single-line uncovered branches are still detected.
    • Prioritizes substantive uncovered blocks (--min-annotation-lines=4, sorted by uncovered executable line count descending) for GitHub Check Annotations (::warning) to avoid over-enforcing brittle mock tests on 1-3 line guards, and outputs a Markdown table + collapsible code snippets to $GITHUB_STEP_SUMMARY.
  • Local & CI Integration:
    • Adds make coverage-diff (COVERAGE_BASE, COVERAGE_FULL) running fast targeted go test on affected packages (plus companion ./<dir>/impl packages when present).
    • Updates backend-tests in .github/workflows/pullrequest.yaml to generate go-cover.output during the existing go test step and report differential coverage safely on all PRs (including fork PRs with read-only permissions).

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a Go differential coverage tool under scripts/coverage-diff/ to measure test coverage specifically on newly added or modified lines of code. It integrates this tool into the build system via a new make coverage-diff target, updates the development documentation in English and Japanese, and adds corresponding unit tests. Feedback on the implementation includes handling cases where no coverprofile is generated to prevent CI pipeline failures, and replacing a custom sorting algorithm with the standard library's slices.Sort utility.

Comment on lines +93 to +104
if profilePath != "" {
f, err := os.Open(profilePath)
if err != nil {
return fmt.Errorf("failed to open coverprofile %s: %w", profilePath, err)
}
defer f.Close()

blocksByFile, err = ParseCoverProfile(f, modulePath)
if err != nil {
return err
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

If a pull request only modifies packages that do not have any unit tests yet, go test will succeed but will not generate a coverprofile file. In this scenario, os.Open(profilePath) will fail with a path does not exist error, causing the tool (and the CI pipeline) to fail. We should handle os.IsNotExist(err) gracefully and proceed with an empty coverage map.

	if profilePath != "" {
		f, err := os.Open(profilePath)
		if err != nil {
			if !os.IsNotExist(err) {
				return fmt.Errorf("failed to open coverprofile %s: %w", profilePath, err)
			}
		} else {
			defer f.Close()
			blocksByFile, err = ParseCoverProfile(f, modulePath)
			if err != nil {
				return err
			}
		}
	}
Comment on lines +182 to +198
func sortedFileKeys(m map[string]map[int]struct{}) []string {
keys := make([]string, 0, len(m))
for k := range m {
keys = append(keys, k)
}
return sortedStrings(keys)
}

func sortedStrings(in []string) []string {
out := append([]string(nil), in...)
for i := 1; i < len(out); i++ {
for j := i; j > 0 && out[j] < out[j-1]; j-- {
out[j], out[j-1] = out[j-1], out[j]
}
}
return out
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Avoid implementing a custom insertion sort algorithm (sortedStrings) when the Go standard library provides highly optimized sorting utilities in the slices package. You can import slices and use slices.Sort directly on the keys slice.

Suggested change
func sortedFileKeys(m map[string]map[int]struct{}) []string {
keys := make([]string, 0, len(m))
for k := range m {
keys = append(keys, k)
}
return sortedStrings(keys)
}
func sortedStrings(in []string) []string {
out := append([]string(nil), in...)
for i := 1; i < len(out); i++ {
for j := i; j > 0 && out[j] < out[j-1]; j-- {
out[j], out[j-1] = out[j-1], out[j]
}
}
return out
}
func sortedFileKeys(m map[string]map[int]struct{}) []string {
keys := make([]string, 0, len(m))
for k := range m {
keys = append(keys, k)
}
slices.Sort(keys)
return keys
}
@kyasbal
kyasbal marked this pull request as ready for review November 11, 2026 08:12
@kyasbal
kyasbal added this pull request to the merge queue Nov 11, 2026
Merged via the queue into main with commit e4eccfd Nov 11, 2026
21 checks passed
@kyasbal
kyasbal deleted the push-pnvpywzuyvzy branch November 11, 2026 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant