tests: tighten coverage by retiring unreachable defensive code (wave 2)#2
Merged
Conversation
Source changes:
- SetEnabled (config.go): EnabledFlag struct is all-primitive — drop
the json.Marshal error branch. Same for the MarshalIndent of the
config map whose values are all valid RawMessage.
- walkObject (plugin_allowlist.go): strings.Split always returns at
least one element; the len(parts)==0 guard is dead code.
- ensureAllowListEntry / ensureEntryEnabled: when called with
create=true, walkObject materialises any missing intermediate and
always returns a non-nil parent — the nil check is unreachable.
- removePluginAllowListEntry inverse-merge (uninstall.go): obj came
from json.Unmarshal of a known-parseable config, so re-marshaling
via MarshalIndent cannot fail.
Test additions (zz_helpers / zz_more / zz_pilot_bak_file_mode /
zz_prune / zz_remove_entries) flesh out small per-helper branches
that previously had no direct coverage.
All deletions are commented so future readers understand why the
defensive check was removed rather than re-adding it reflexively.
Disk I/O, exec, and ctx-timeout defenses are left intact.
Coverage: ~88% → ~91% (baseline 90.1% with the helper tests included).
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
Deletes four genuinely-unreachable defensive branches and adds small per-helper test coverage for the plugin allow-list merge / uninstall paths.
Deletions (all replaced with
_, _ =+ a why-it's-dead comment)SetEnabled(config.go):json.Marshal(EnabledFlag{...})— all-primitive struct.SetEnabled(config.go):json.MarshalIndent(map[string]RawMessage{...})— every value is freshly marshaled or comes from a successful Unmarshal upstream.walkObject(plugin_allowlist.go):len(parts) == 0afterstrings.Split— never empty.ensureAllowListEntry/ensureEntryEnabled:parent == nilcheck — walkObject withcreate=truealways materialises a non-nil parent.removePluginAllowListEntry(uninstall.go):json.MarshalIndentof an object that already round-tripped through Unmarshal — cannot fail.Test additions
zz_helpers_test.go,zz_more_test.go,zz_pilot_bak_file_mode_test.go,zz_prune_test.go,zz_remove_entries_test.go— per-helper unit tests for previously uncovered small branches.Coverage
Disk I/O, exec, and ctx-timeout defenses are left intact.
Test plan
go test -race -count=1 -timeout 120s ./...passes