Skip to content

tests: tighten coverage by retiring unreachable defensive code (wave 2)#2

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

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

Conversation

@TeoSlayer
Copy link
Copy Markdown
Contributor

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) == 0 after strings.Split — never empty.
  • ensureAllowListEntry / ensureEntryEnabled: parent == nil check — walkObject with create=true always materialises a non-nil parent.
  • removePluginAllowListEntry (uninstall.go): json.MarshalIndent of 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

  • Without the new helper tests, the original was ~88%; with the housekeeping deletes + helper tests applied, ~91%.

Disk I/O, exec, and ctx-timeout defenses are left intact.

Test plan

  • go test -race -count=1 -timeout 120s ./... passes
  • All deletions explained in code comments

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
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 4f9236b into main May 28, 2026
2 checks passed
@TeoSlayer TeoSlayer deleted the coverage-housekeeping-wave2 branch May 28, 2026 03:30
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