tests: tighten coverage by retiring unreachable defensive code#2
Merged
Conversation
Two unreachable branches dropped: 1. executePruneTrust: the toRemove <= 0 guard cannot fire. By the time we reach it, total > minLinks (line 504 returns otherwise), and toRemove was forced to >= 1 at line 509. After the (total-toRemove < minLinks) clamp toRemove becomes total-minLinks, which is > 0. 2. persistState: the json.MarshalIndent error branch cannot fire on policySnapshot — it contains only uint16, string, int, []string, map[uint32]*managedPeer, and time.Time fields, all of which have safe MarshalJSON paths. Switched to '_' discard with an explanatory comment. The policylang panic-recovery and timeout branches in engine.go are left in place — those are load-bearing daemon-safety code with user-facing error messages, even though tests can't easily exercise them. Main-package coverage 99.6% -> 100.0%.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Two unreachable branches dropped in the main package:
executePruneTrust:toRemove <= 0guard cannot fire —total > minLinksis already enforced at line 504,toRemoveis forced to >= 1 at line 509, and the subsequenttotal-minLinksrewrite stays > 0.persistState:json.MarshalIndentcannot fail onpolicySnapshot(all primitives +time.Time). Switched to_discard with a comment.Left untouched: the panic-recovery and 100ms-timeout branches in
policylang/engine.go— those are load-bearing daemon-safety code with user-facing error messages.Coverage
policylangsub-package: unchanged at 99.1%Test plan
go test -race -count=1 -timeout 120s ./...passes both packages