[test-improver] Improve tests for config/rules package#1136
Merged
Conversation
- Replace require.NotNil(t, err) with require.Error(t, err) for idiomatic testify error assertions in TestPortRange, TestTimeoutPositive, TestMountFormat - Replace raw t.Errorf in success paths with assert.Nil(t, err) in TestNonEmptyString and TestAbsolutePath - Fix fragile hardcoded expectedPath in TestMountFormat to use fmt.Sprintf so it correctly handles any index value (not just 0 and 1) - Add 'fmt' import for the fmt.Sprintf fix - Expand single-case tables to improve coverage: - TestUnsupportedType: add websocket and empty type test cases - TestUndefinedVariable: add PAT token and config dir variable test cases - TestUnsupportedField: add args field and empty suggestion test cases - TestNonEmptyString: add whitespace-only string edge case (not treated as empty) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the test quality and coverage for the internal/config/rules package, focusing on better testing patterns, increased test coverage, and fixing a latent bug in the JSONPath assertion logic. The changes align with the codebase's established testify assertion patterns and add meaningful test cases that exercise edge cases and different code paths.
Changes:
- Replaced
require.NotNilwithrequire.Errorand rawt.Errorfwithassert.Nilfor consistent testify usage - Fixed a bug in
TestMountFormatwhere the expected JSONPath computation was hardcoded and would fail for indices > 1 - Added 9 new test cases across 4 test functions to improve coverage of edge cases and different scenarios
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Feb 19, 2026
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.
File Analyzed
internal/config/rules/rules_test.gointernal/config/rulesImprovements Made
1. Better Testing Patterns
require.NotNil→require.Error: Replacedrequire.NotNil(t, err)withrequire.Error(t, err)inTestPortRange,TestTimeoutPositive, andTestMountFormat— more idiomatic testify for error-path assertionst.Errorf→assert.Nil: Replaced manualif err != nil { t.Errorf(...) }patterns inTestNonEmptyStringandTestAbsolutePathsuccess paths withassert.Nil(t, err)— consistent use of testify throughout"unsupported server type"→"unsupported server type grpc"for clarity in failure outputfmtimport needed for thefmt.Sprintfpath fix2. Increased Coverage
TestUnsupportedType: Added"unsupported server type websocket"and"unsupported empty type"test cases (1 → 3 cases)TestUndefinedVariable: Added PAT token (GITHUB_PERSONAL_ACCESS_TOKEN) and config dir (GITHUB_CONFIG_DIR) variable test cases (1 → 3 cases)TestUnsupportedField: Added"unsupported args field"and"unsupported field with empty suggestion"test cases (1 → 3 cases)TestNonEmptyString: Added"valid whitespace-only string is not empty"edge case — documents and verifies thatNonEmptyStringonly rejects"", not" "(4 → 5 cases)3. Cleaner & More Stable Tests
expectedPathcomputation inTestMountFormat: The original code had:[1]instead of the actual index). Replaced with:tt.jsonPathrather than hardcoded"mcpServers.github".Why These Changes?
internal/config/rules/rules_test.gowas selected because it had a mix of testify patterns and inconsistent assertion styles. The file had rawt.Errorfpatterns in success branches where testify assertions should be used,require.NotNilwhererequire.Erroris more descriptive for error values, and multiple single-case table tests that provided poor coverage signal. The fragileexpectedPathcomputation was a latent bug — any test case withindex > 1would produce incorrect assertions.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests