[test-improver] Improve tests for guard Registry.HasNonNoopGuard#3158
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
[test-improver] Improve tests for guard Registry.HasNonNoopGuard#3158github-actions[bot] wants to merge 1 commit intomainfrom
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
Add TestGuardRegistry_HasNonNoopGuard covering all branches of the HasNonNoopGuard method which was used in server/unified.go but had no dedicated unit tests: - empty registry returns false - only noop guards returns false - one non-noop guard returns true - mix of noop and non-noop returns true - removing the non-noop guard reverts to false - replacing non-noop with noop reverts to false Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Test Improvements:
internal/guard/guard_test.goFile Analyzed
internal/guard/guard_test.gointernal/guardImprovements Made
1. Increased Coverage — Direct Tests for
Registry.HasNonNoopGuardProblem: The
HasNonNoopGuardmethod ininternal/guard/registry.gowas called frominternal/server/unified.goto determine whether DIFC should be auto-enabled:Despite being a meaningful predicate used in server startup logic,
HasNonNoopGuardhad no dedicated unit tests inguard_test.go. All otherRegistrymethods (Register,Get,Has,List,Remove,GetGuardInfo) had explicit subtests —HasNonNoopGuardwas the only gap.2. New Test:
TestGuardRegistry_HasNonNoopGuardAdded 6 subtests covering all branches of the
HasNonNoopGuardmethod:The tests reuse the existing
mockGuardhelper and follow the established subtest patterns throughout the file (consistent withTestGuardRegistry).3. Cleaner & More Stable Tests
NewRegistry()— fully isolated, no shared stateassert.True/assert.Falsefor clear, readable assertionsWhy These Changes?
HasNonNoopGuardis the sentinel used by the server to auto-activate DIFC when a non-trivial guard is registered. A regression in this predicate (e.g., always returningfalse) would silently disable DIFC enforcement at startup — a security-relevant failure. Despite the rest of the Registry API being well-tested, this method was the only gap.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests