Skip to content

Commit 9f8e057

Browse files
CLAUDE.md - Merge development branch updates with PR branch changes
- Added Command Naming and Creation section from development - Preserved Microsoft SMO Property Name Typos section - Updated Test Management Guidelines to allow tests for new features - Updated verification checklist and summary with all rules Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>
1 parent 5e13435 commit 9f8e057

File tree

1 file changed

+77
-13
lines changed

1 file changed

+77
-13
lines changed

CLAUDE.md

Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,31 @@ AfterAll {
300300

301301
## DBATOOLS-SPECIFIC CONVENTIONS
302302

303+
### Command Naming and Creation
304+
305+
**CRITICAL RULE**: When creating new commands, follow PowerShell best practices:
306+
307+
1. **Use singular nouns** - Command names must use singular nouns, not plural
308+
- Correct: `Get-DbaDatabase`, `Get-DbaLogin`, `Get-DbaAgent`
309+
- Incorrect: `Get-DbaDatabases`, `Get-DbaLogins`, `Get-DbaAgents`
310+
311+
2. **Use approved verbs** - Always use approved PowerShell verbs from the standard set (Get, Set, New, Remove, Invoke, etc.)
312+
313+
3. **Consistent naming pattern** - Follow the `<Verb>-Dba<Noun>` pattern consistently
314+
315+
```powershell
316+
# CORRECT - Singular nouns
317+
function Get-DbaDatabase { }
318+
function Set-DbaLogin { }
319+
function New-DbaAgent { }
320+
function Remove-DbaJob { }
321+
322+
# WRONG - Plural nouns
323+
function Get-DbaDatabases { }
324+
function Set-DbaLogins { }
325+
function New-DbaAgents { }
326+
```
327+
303328
### Microsoft SMO Property Name Typos
304329

305330
**CRITICAL KNOWLEDGE**: Some Microsoft SMO (SQL Server Management Objects) properties contain typos in their official names. These are NOT errors - they are the actual property names you must use.
@@ -414,14 +439,13 @@ AfterAll {
414439

415440
### Test Management Guidelines
416441

417-
**CRITICAL RULE: DO NOT ADD ADDITIONAL UNIT TESTS UNLESS EXPLICITLY REQUESTED**
418-
419-
The dbatools test suite must remain manageable in size. Follow these strict guidelines:
442+
The dbatools test suite must remain manageable in size while ensuring adequate coverage for important functionality. Follow these guidelines:
420443

421444
**When to Update Tests:**
422445
- **ALWAYS update parameter validation tests** when parameters are added or removed from a command
423-
- **ONLY add regression tests** when fixing a specific bug that needs to be prevented from recurring
424-
- **NEVER add new unit tests** unless the user explicitly asks for them
446+
- **ADD tests for new functionality** - When adding new parameters or features, include tests that verify the new functionality works correctly
447+
- **ADD regression tests** when fixing a specific bug that needs to be prevented from recurring
448+
- **AVOID bloat** - Don't add generic coverage tests for basic operations unless they test a specific fix or new feature
425449

426450
**Parameter Validation Updates:**
427451

@@ -444,12 +468,43 @@ Context "Parameter validation" {
444468
}
445469
```
446470

471+
**Tests for New Features:**
472+
473+
When adding new parameters or functionality, include tests that verify the new feature works:
474+
475+
```powershell
476+
# GOOD - Test for a new parameter that filters results
477+
Context "Filter by recovery model" {
478+
It "Should return only databases with Full recovery model" {
479+
$splatFilter = @{
480+
SqlInstance = $instance
481+
RecoveryModel = "Full"
482+
}
483+
$result = Get-DbaDatabase @splatFilter
484+
$result.RecoveryModel | Should -All -Be "Full"
485+
}
486+
}
487+
488+
# GOOD - Test for a new switch parameter
489+
Context "Force parameter" {
490+
It "Should skip confirmation when -Force is used" {
491+
$splatForce = @{
492+
SqlInstance = $instance
493+
Database = $testDb
494+
Force = $true
495+
Confirm = $false
496+
}
497+
{ Remove-DbaDatabase @splatForce } | Should -Not -Throw
498+
}
499+
}
500+
```
501+
447502
**Regression Tests:**
448503

449-
Add regression tests ONLY when:
450-
- Fixing a specific, reproducible bug
504+
Add regression tests when fixing bugs:
505+
- Fixing a specific, reproducible bug that should be prevented from recurring
451506
- The bug is significant enough to warrant long-term protection
452-
- The test prevents a real-world issue from recurring
507+
- The test demonstrates the bug is fixed and prevents regression
453508

454509
Example of when to add a regression test:
455510

@@ -473,13 +528,17 @@ Context "Regression tests" {
473528
**What NOT to do:**
474529

475530
```powershell
476-
# WRONG - Adding general coverage tests without being asked
531+
# WRONG - Adding general coverage tests for existing functionality without a fix
477532
It "Should return correct number of databases" { }
478533
It "Should handle empty result sets" { }
479534
It "Should work with pipeline input" { }
535+
536+
# WRONG - Generic edge case tests unrelated to changes
537+
It "Should handle null parameters gracefully" { }
538+
It "Should work with special characters in names" { }
480539
```
481540

482-
These types of tests bloat the test suite. Only add them if explicitly requested by the user.
541+
Don't add tests for existing functionality unless you're fixing a bug or adding a new feature that needs verification.
483542

484543
## VERIFICATION CHECKLIST
485544

@@ -512,14 +571,18 @@ These types of tests bloat the test suite. Only add them if explicitly requested
512571
- [ ] Microsoft SMO property typos preserved (e.g., AvailabilityDateabaseId)
513572

514573
**Command Registration (if adding new commands):**
574+
- [ ] Command name uses singular nouns (not plural)
575+
- [ ] Command uses approved PowerShell verb
576+
- [ ] Command follows `<Verb>-Dba<Noun>` naming pattern
515577
- [ ] Command added to `FunctionsToExport` in dbatools.psd1
516578
- [ ] Command added to `Export-ModuleMember` in dbatools.psm1
517579

518580
**Test Management:**
519581
- [ ] Parameter validation test updated if parameters were added/removed
520-
- [ ] No additional unit tests added unless explicitly requested
521-
- [ ] Regression tests added only for significant bug fixes
522-
- [ ] Test suite size kept manageable
582+
- [ ] Tests added for new functionality and parameters (not just bloat)
583+
- [ ] Regression tests added for significant bug fixes
584+
- [ ] Generic coverage tests avoided unless testing a specific fix or new feature
585+
- [ ] Test suite remains manageable and focused
523586

524587
## SUMMARY
525588

@@ -535,3 +598,4 @@ The golden rules for dbatools code:
535598
8. **ALWAYS use unique variable names** - Prevent scope collisions
536599
9. **ALWAYS use descriptive splatnames** - `$splatConnection`, not `$splat`
537600
10. **ALWAYS register new commands** - Add to both dbatools.psd1 and dbatools.psm1
601+
11. **ALWAYS use singular nouns** - Command names use singular, not plural

0 commit comments

Comments
 (0)