Skip to content

fix(ci): gate changed-line coverage with diff-cover#27

Open
bladehan1 wants to merge 2 commits intodevelopfrom
fix/ci_coverage_gate
Open

fix(ci): gate changed-line coverage with diff-cover#27
bladehan1 wants to merge 2 commits intodevelopfrom
fix/ci_coverage_gate

Conversation

@bladehan1
Copy link
Copy Markdown
Owner

@bladehan1 bladehan1 commented Apr 24, 2026

Summary

Replace the coverage-changed-files gate (whole-file INSTRUCTION coverage) with a true changed-line LINE coverage gate powered by diff-cover, and make the gate robust against non-Java PRs and tool failures.

Reference: tronprotocol/java-tron#6705 — same change set, prepared as a single squashed commit.

Commit included

Subject Purpose
ci(coverage): gate changed-line coverage Squash of the three-step rollout below: introduce diff-cover as the changed-code gate, handle non-Java PRs via an NA sentinel, and polish the step (guard empty SRC_ROOTS, verify diff-cover.json, clarify LINE vs INSTRUCTION semantics in the metrics panel).

Net change vs tronprotocol/develop base: 1 file, +90 / -27.

Why

  1. Patch coverage semantics. The previous gate used madrapps/jacoco-report's coverage-changed-files output, which is the whole-file INSTRUCTION coverage of each changed file — not the coverage of the lines the PR actually changed. diff-cover provides the industry-standard "changed-line" measurement.
  2. Drop the 403 noise. jacoco-report's default PR comment needs pull-requests: write, which fork PRs do not get. Job logs kept filling up with 403 errors.
  3. Stop wrongly failing non-Java PRs. With just diff-cover, a PR that only touches workflows / docs / proto / test code produces total_num_lines=0, and the original jq call exited with 1. The NA sentinel now maps that state to SKIPPED in the enforce step.

Design notes for reviewers

  • CI wall-clock impact is ~0. The new coverage-base job runs independently of docker-build-debian11 (they share no needs:). Since docker-build-debian11 is already the slowest build (~16 min with testWithRocksDb), adding a parallel coverage-base of similar length does not extend the critical path. The gate job waits for both, so total PR wall-clock is unchanged.
  • Metric mix is intentional and footnoted. Changed-line Coverage uses LINE coverage (diff-cover), while PR Overall Coverage / Base Overall Coverage / Delta use INSTRUCTION coverage. madrapps/jacoco-report v1.7.2 is the latest release and hard-codes the coverage-overall output to INSTRUCTION; there is no coverage-type input yet — see the open madrapps/jacoco-report#82 on milestone 1.8. The METRICS panel and step summary now print an explicit note so readers do not accidentally compare the two counters.
  • SKIPPED scope. diff-cover --src-roots is limited to */src/main/java. PRs touching only src/test/java, build/generated (proto output), docs, or CI will be reported as SKIPPED. In practice proto-only PRs with non-trivial generated-code coverage shifts are rare in this repository; we accept the gap.
  • Gate thresholds preserved. MIN_CHANGED=60 (for Changed-line LINE) and MAX_DROP=-0.1% (for Overall INSTRUCTION delta) are unchanged from the existing workflow.
  • Failure modes. The new exit 1 branches only fire in genuine error states: SRC_ROOTS is empty (unexpected workspace shape) or diff-cover.json is missing (tool crash). Neither can be triggered by ordinary PR content.
  • Base-branch note. bladehan1/java-tron:develop already contains the first two steps of this rollout via prior in-fork merges (PRs test: validate changed-line coverage gate #23 and ci(coverage): harden diff-cover step and handle non-Java PRs #25). The diff visible on this PR (+12/-2) is therefore only the polish subset; the commit message and Summary describe the full scope so the single squashed commit stands alone on upstream.

Follow-ups (not in this PR)

  • Migrate Overall to LINE once madrapps/jacoco-report 1.8 ships coverage-type, or by self-parsing the JaCoCo XML. Unifies the metrics panel on one counter.
  • Add proper shell unit tests (e.g. via bats) for the enforce step, so the three-state logic (NA / numeric / error) is covered without needing a real CI run.
  • Revisit comment-type: summary if reviewers prefer on-PR comment visibility; restoring comments requires granting pull-requests: write on the coverage-gate job.

Test plan

  • Workflow-only / non-Java PR → Changed-line Coverage: NA, Changed-line Gate: SKIPPED, gate passes. Verified end-to-end on a prior fork PR carrying the same commits.
  • Java PR with changed lines → Changed-line Coverage: X%, Changed-line Gate: PASS at X > 60. Verified end-to-end on a prior fork PR (25 changed lines @ 100%).
  • Java PR with changed lines at X <= 60FAIL. Logic reviewed; path not force-exercised.
  • First natural Java PR after merge → regress PASS / FAIL / mixed-change paths.

Summary by cubic

Replaced the whole-file changed-files coverage gate with true changed-line LINE coverage using diff-cover, keeping the overall INSTRUCTION delta gate unchanged. Also consolidated and stabilized CredentialsTest with deterministic fixtures.

  • New Features

    • Gate changed-line coverage with diff-cover; thresholds unchanged (MIN_CHANGED=60, MAX_DROP=-0.1%).
    • Skip the changed-line gate when no Java lines changed (NA) so docs/workflow/proto-only PRs don’t fail.
    • Hardened step: ensure src/main/java roots exist, fetch base ref, verify diff-cover.json; note LINE vs INSTRUCTION semantics in the step summary.
    • Use madrapps/jacoco-report@v1.7.2 with comment-type: summary to avoid 403s on fork PRs; set up Python 3.11 and pin diff-cover==9.2.0.
  • Refactors

    • Merge the duplicate/misspelled org.tron.keystroe.CredentialsTest into org.tron.keystore.CredentialsTest.
    • Replace random key generation with mocked SignInterface fixtures; assert Base58Check address and equals/hashCode behavior; normalize to JUnit Assert.

Written for commit 141d786. Summary will update on new commits.

…col#6614)

* test(framework): merge duplicate CredentialsTest coverage

Consolidate the misplaced keystroe CredentialsTest into org.tron.keystore.CredentialsTest.

- remove the duplicate test under the misspelled keystroe package
- add explicit equals behavior coverage for address and cryptoEngine
- normalize assertions to JUnit Assert and remove legacy TestCase usage

* test(framework): stabilize CredentialsTest fixtures

Replace random Credentials test setup with deterministic SignInterface mocks
so the suite no longer depends on platform-specific SecureRandom providers or
probabilistic retries.

- remove NativePRNG usage from CredentialsTest
- replace random key generation with fixed address fixtures via mocked SignInterface
- assert create(SignInterface) returns the expected base58check address
- keep equals/hashCode contract coverage with deterministic inputs
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 24, 2026

Warning

Rate limit exceeded

@bladehan1 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 34 minutes and 46 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 34 minutes and 46 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3334497a-af3d-4985-aa2a-5b8f0f5e98e2

📥 Commits

Reviewing files that changed from the base of the PR and between 8a330e2 and b63295a.

📒 Files selected for processing (1)
  • .github/workflows/pr-build.yml
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ci_coverage_gate

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot requested a review from halibobo1205 April 24, 2026 09:47
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

- Use diff-cover changed-line coverage as the changed-code gate; keep
  the overall coverage delta gate at -0.1% and JaCoCo reports as
  summary-only snapshots.
- Handle non-Java PRs: when diff-cover reports no changed Java lines
  (workflow-only, docs-only, proto-only), emit NA and treat it as
  SKIPPED in the enforcement step so the gate does not wrongly fail.
- Harden the diff-cover step: guard against empty SRC_ROOTS before
  invoking diff-cover, verify diff-cover.json was written, and surface
  exit codes in failure messages.
- Clarify metric semantics in the step summary: Changed-line is LINE
  coverage (diff-cover) while Overall / Delta are INSTRUCTION coverage
  (jacoco-report).
@bladehan1 bladehan1 force-pushed the fix/ci_coverage_gate branch from b63295a to 141d786 Compare April 24, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants