-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Labels
automationbest-practicescode-qualitycookieIssue Monster Loves Cookies!Issue Monster Loves Cookies!lintingtask-miningtesting
Description
Description
Many test files use assert.NotNil(t, err) for error checking instead of the more idiomatic assert.Error(t, err). This should be updated for better test readability and consistency with Go testing best practices.
Current Pattern (Anti-pattern)
// ❌ BAD: Using NotNil for error checking
if err != nil {
assert.NotNil(t, err, "Expected error")
}
// or
assert.NotNil(t, err, "Expected error")Recommended Pattern
// ✅ GOOD: Using Error/NoError for error checking
assert.Error(t, err, "Expected error when...")
assert.NoError(t, err, "Should not error when...")Why This Matters
- Semantic clarity:
Error()explicitly checks for errors, not just non-nil values - Better error messages:
Error()includes the actual error message in test output - Linter compliance: Aligns with
testifylintbest practices - Consistency: Matches the pattern used in AGENTS.md guidelines (lines 90-95)
Affected Areas
Tests throughout the codebase that check for errors using:
assert.NotNil(t, err)assert.Nil(t, err)(should beassert.NoError(t, err))require.NotNil(t, err)(should berequire.Error(t, err))require.Nil(t, err)(should berequire.NoError(t, err))
Suggested Changes
Automated Refactoring
Use a script or manual find-replace to update:
# Find files with the anti-pattern
grep -r "assert\.NotNil(t, err" pkg/ cmd/ --include="*_test.go"
grep -r "assert\.Nil(t, err" pkg/ cmd/ --include="*_test.go"
grep -r "require\.NotNil(t, err" pkg/ cmd/ --include="*_test.go"
grep -r "require\.Nil(t, err" pkg/ cmd/ --include="*_test.go"Replacement Patterns
// Pattern 1: assert.NotNil(t, err, msg) → assert.Error(t, err, msg)
assert.NotNil(t, err, "Expected error")
// becomes:
assert.Error(t, err, "Expected error")
// Pattern 2: assert.Nil(t, err, msg) → assert.NoError(t, err, msg)
assert.Nil(t, err, "Should not error")
// becomes:
assert.NoError(t, err, "Should not error")
// Pattern 3: Same for require.*
require.NotNil(t, err, "Setup must fail")
// becomes:
require.Error(t, err, "Setup must fail")Success Criteria
- ✅ All error assertions use
Error()orNoError() - ✅ No usage of
NotNil()orNil()for error checking - ✅ All tests pass (
make test-unit) - ✅ Linter passes (
make lint) - ✅ Test error messages are descriptive
Benefits
- Better test output: Error messages show actual error content
- Code clarity: Intent is immediately clear
- Linter compliance: Eliminates
testifylintwarnings - Consistency: Aligns with project guidelines in AGENTS.md
- Best practices: Follows Go testing community standards
Implementation Strategy
- Phase 1: Update
pkg/constants/tests (smallest scope) - Phase 2: Update
pkg/cli/tests - Phase 3: Update
pkg/workflow/tests - Phase 4: Update remaining packages
Run make agent-finish after each phase to ensure no regressions.
Reference
- AGENTS.md lines 90-95: Testifylint assertion best practices
- Testify documentation
Source
Extracted from AGENTS.md testing guidelines and common linting patterns
Priority
Low-Medium - Code quality improvement that enhances test readability
AI generated by Discussion Task Miner - Code Quality Improvement Agent
- expires on Feb 10, 2026, 5:12 AM UTC
Copilot
Metadata
Metadata
Labels
automationbest-practicescode-qualitycookieIssue Monster Loves Cookies!Issue Monster Loves Cookies!lintingtask-miningtesting