Skip to content

test(common): verify coverage gate fails on uncovered change#28

Open
hzj-edu-nju wants to merge 1 commit intobladehan1:developfrom
hzj-edu-nju:test/coverage-gate-below-60
Open

test(common): verify coverage gate fails on uncovered change#28
hzj-edu-nju wants to merge 1 commit intobladehan1:developfrom
hzj-edu-nju:test/coverage-gate-below-60

Conversation

@hzj-edu-nju
Copy link
Copy Markdown

@hzj-edu-nju hzj-edu-nju commented Apr 24, 2026

Summary

Intentional test PR to exercise Acceptance Gate G1.3 of the coverage gate: a Java PR whose changed-line coverage is <= 60% should fail the gate.

The PR adds a new public utility method DecodeUtil.hexLengthForAddress(int) with ~10 executable lines. No unit test is added on purpose, so diff-cover will report 0% changed-line coverage and the Coverage Gate job should exit non-zero with Changed-line Gate: FAIL (<= 60%).

Expected CI signals

  • Coverage Gate step summary shows:
    • Changed-line Coverage: 0%
    • Changed-line Gate: FAIL (<= 60%)
    • Overall Delta Gate: PASS (>= -0.1%) (no regression in overall INSTRUCTION delta)
  • Coverage Gate job ends with Coverage gate failed: changed-line coverage must be > 60% and exit code 1.
  • All other build / lint / test jobs pass (the new method is valid Java and will not break build).

Not for merge

This PR is a sandbox test and must not be merged. Revert / close after observing the expected gate FAIL.


Summary by cubic

Adds an uncovered public helper DecodeUtil.hexLengthForAddress(int) to intentionally verify Coverage Gate Acceptance G1.3 (changed-line coverage <= 60% should fail).
CI should report 0% changed-line coverage and fail the changed-line gate; this is a sandbox test and must not be merged.

Written for commit dbe162b. Summary will update on new commits.

Summary by CodeRabbit

  • Chores
    • Added a utility method to support internal address processing operations.

Intentional test: add a public utility method to DecodeUtil without
any unit test so `diff-cover` reports changed-line coverage below
60% and the Coverage Gate exercises its FAIL path (Acceptance Gate
G1.3 — Java PR with coverage below threshold should FAIL).

The new method has ~10 executable lines and is not called from
production code or tests, so the new lines appear as 0% covered.

Revert before merging.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 24, 2026

📝 Walkthrough

Walkthrough

A new public utility method hexLengthForAddress is added to the DecodeUtil class. The method validates non-negative byteLength input, returns 0 for zero values, and computes hex string length as twice the byte length for positive inputs.

Changes

Cohort / File(s) Summary
Utility Method Addition
common/src/main/java/org/tron/common/utils/DecodeUtil.java
Add new public method hexLengthForAddress(int byteLength) with parameter validation that throws IllegalArgumentException for negative values and returns calculated hex string length.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • 317787106
  • halibobo1205

Poem

🐰 A helper hopped in with hex calculation,
Converting bytes to string representation,
With validation to guard against the wrong,
This utility method's nice and strong!
✨ Multiply by two, the magic's done!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title describes a test to verify coverage gate behavior, but the actual changeset adds a new utility method without tests—not a coverage gate verification. Revise title to accurately reflect the change: e.g., 'test(common): add hexLengthForAddress utility method' or note this is an intentional test PR if that is the primary purpose.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
common/src/main/java/org/tron/common/utils/DecodeUtil.java (1)

44-47: Redundant zero-branch.

byteLength == 0 already yields 0 via byteLength * 2, so the explicit branch is unnecessary. Not a functional issue — only relevant if this method is ever kept beyond the sandbox PR.

♻️ Proposed simplification
-    if (byteLength < 0) {
-      throw new IllegalArgumentException("byteLength must be non-negative");
-    }
-    if (byteLength == 0) {
-      return 0;
-    }
-    return byteLength * 2;
+    if (byteLength < 0) {
+      throw new IllegalArgumentException("byteLength must be non-negative");
+    }
+    return byteLength * 2;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@common/src/main/java/org/tron/common/utils/DecodeUtil.java` around lines 44 -
47, In DecodeUtil (the method containing the shown snippet), remove the
redundant if (byteLength == 0) branch and simply return byteLength * 2; so
replace the conditional block with a single return statement to simplify the
code while preserving behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@common/src/main/java/org/tron/common/utils/DecodeUtil.java`:
- Around line 35-48: Remove the sandbox-only helper method hexLengthForAddress
from DecodeUtil to avoid introducing dead public API; revert the added method
(public static int hexLengthForAddress(int byteLength)) from
org.tron.common.utils.DecodeUtil so callers continue to use existing
ADDRESS_SIZE/ADDRESS_SIZE/2 logic and ensure no tests or usages reference
hexLengthForAddress before merging.

---

Nitpick comments:
In `@common/src/main/java/org/tron/common/utils/DecodeUtil.java`:
- Around line 44-47: In DecodeUtil (the method containing the shown snippet),
remove the redundant if (byteLength == 0) branch and simply return byteLength *
2; so replace the conditional block with a single return statement to simplify
the code while preserving behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8a022337-d54f-4fc3-a88b-84c0180b2653

📥 Commits

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

📒 Files selected for processing (1)
  • common/src/main/java/org/tron/common/utils/DecodeUtil.java

Comment on lines +35 to +48
/**
* Intentional uncovered helper used to exercise the Coverage Gate FAIL path
* (changed-line coverage below 60%). No unit test is added on purpose.
* Revert before merging.
*/
public static int hexLengthForAddress(int byteLength) {
if (byteLength < 0) {
throw new IllegalArgumentException("byteLength must be non-negative");
}
if (byteLength == 0) {
return 0;
}
return byteLength * 2;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Sandbox-only change — ensure this is reverted before merge.

Per the PR description, this method is intentionally added to exercise the Coverage Gate FAIL path and must not be merged. The Javadoc correctly flags this, but it's worth double-checking that once the gate behavior is observed, this PR is closed/reverted and hexLengthForAddress is not left behind as unused public API in common. Since the method has no callers in the tree (existing address-length checks use ADDRESS_SIZE / ADDRESS_SIZE / 2 directly in JsonRpcApiUtil, ValidateAddressServlet, etc.), landing it would just add dead public surface.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@common/src/main/java/org/tron/common/utils/DecodeUtil.java` around lines 35 -
48, Remove the sandbox-only helper method hexLengthForAddress from DecodeUtil to
avoid introducing dead public API; revert the added method (public static int
hexLengthForAddress(int byteLength)) from org.tron.common.utils.DecodeUtil so
callers continue to use existing ADDRESS_SIZE/ADDRESS_SIZE/2 logic and ensure no
tests or usages reference hexLengthForAddress before merging.

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.

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="common/src/main/java/org/tron/common/utils/DecodeUtil.java">

<violation number="1" location="common/src/main/java/org/tron/common/utils/DecodeUtil.java:40">
P3: Temporary coverage-gate helper was added as a public production API; remove it or move it to test-only code before merge.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

* (changed-line coverage below 60%). No unit test is added on purpose.
* Revert before merging.
*/
public static int hexLengthForAddress(int byteLength) {
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot Apr 24, 2026

Choose a reason for hiding this comment

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

P3: Temporary coverage-gate helper was added as a public production API; remove it or move it to test-only code before merge.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At common/src/main/java/org/tron/common/utils/DecodeUtil.java, line 40:

<comment>Temporary coverage-gate helper was added as a public production API; remove it or move it to test-only code before merge.</comment>

<file context>
@@ -32,4 +32,19 @@ public static boolean addressValid(byte[] address) {
+   * (changed-line coverage below 60%). No unit test is added on purpose.
+   * Revert before merging.
+   */
+  public static int hexLengthForAddress(int byteLength) {
+    if (byteLength < 0) {
+      throw new IllegalArgumentException("byteLength must be non-negative");
</file context>
Fix with Cubic

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