[test] Add tests for util.RandomBigInt zero-result normalization branch#10081
Conversation
Extract randomBigIntFromRandFunc internal helper to make the astronomically-rare zero-result defensive branch testable via dependency injection. Add TestRandomBigIntFromRandFunc covering: - zero bits error path - rand function error wrapping - normal positive result passthrough - zero result normalized to 1 (previously untestable branch) Coverage improvement: internal/util 97.8% → 99.3% RandomBigInt: 77.8% → 100% Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds deterministic coverage for RandomBigInt’s rare zero-result normalization branch.
Changes:
- Extracts an injectable internal helper while preserving the public API.
- Adds tests for validation, errors, positive results, and zero normalization.
Show a summary per file
| File | Description |
|---|---|
internal/util/random.go |
Adds the testable random-function helper. |
internal/util/random_test.go |
Adds comprehensive helper branch tests. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Medium
🔒 mcpg Read-Only Stress — gVisorSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Notes:
Overall: PASS References: §30166347790
|
🔒 mcpg Read-Only Stress — docker-sbxSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: PASS
References: §30166347755
|
🔒 mcpg Read-Only Stress — default AWFSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: PASS ✅ Run: §30166347774
|
Test Coverage Improvement:
util.RandomBigIntFunction Analyzed
internal/utilRandomBigInt/randomBigIntFromRandFuncWhy This Function?
RandomBigInthad a defensive branch (n.Sign() == 0 → set to 1) that was impossible to test directly because it depends oncrypto/rand.Intproducing zero — an astronomically rare event in production. The function had no injectable seam for testing, leaving 77.8% coverage and a gap in branch verification.Changes
internal/util/random.go: ExtractedrandomBigIntFromRandFunc— an internal helper that accepts arandFn func(io.Reader, *big.Int) (*big.Int, error)parameter.RandomBigIntnow delegates to this helper usingrand.Int. This follows the same testability pattern already used forrandomBytesFromReaderandrandomHexFromReaderin the same file.internal/util/random_test.go: AddedTestRandomBigIntFromRandFunccovering:Coverage Report
Test Execution
Generated by Test Coverage Improver
Warning
Firewall blocked 6 domains
The following domains were blocked by the firewall during workflow execution:
go.opentelemetry.iogo.yaml.ingolang.orggoogle.golang.orggopkg.inproxy.golang.orgSee Network Configuration for more information.