Skip to content

tests: tighten coverage by retiring unreachable defensive code#2

Merged
TeoSlayer merged 1 commit into
mainfrom
coverage-housekeeping
May 28, 2026
Merged

tests: tighten coverage by retiring unreachable defensive code#2
TeoSlayer merged 1 commit into
mainfrom
coverage-housekeeping

Conversation

@TeoSlayer
Copy link
Copy Markdown
Contributor

Summary

Two unreachable branches dropped in the main package:

  • executePruneTrust: toRemove <= 0 guard cannot fire — total > minLinks is already enforced at line 504, toRemove is forced to >= 1 at line 509, and the subsequent total-minLinks rewrite stays > 0.
  • persistState: json.MarshalIndent cannot fail on policySnapshot (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

  • Main package: 99.6% -> 100.0%
  • policylang sub-package: unchanged at 99.1%

Test plan

  • go test -race -count=1 -timeout 120s ./... passes both packages

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
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@TeoSlayer TeoSlayer merged commit ed19df9 into main May 28, 2026
2 checks passed
@TeoSlayer TeoSlayer deleted the coverage-housekeeping branch May 28, 2026 02:22
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