Skip to content

Conversation

@johlju
Copy link
Member

@johlju johlju commented Aug 23, 2025

Pull Request (PR) description

This Pull Request (PR) fixes the following issues

Task list

  • Added an entry to the change log under the Unreleased section of the
    file CHANGELOG.md. Entry should say what was changed and how that
    affects users (if applicable), and reference the issue being resolved
    (if applicable).
  • Resource documentation updated in the resource's README.md.
  • Resource parameter descriptions updated in schema.mof.
  • Comment-based help updated, including parameter descriptions.
  • Localization strings updated.
  • Examples updated.
  • Unit tests updated. See DSC Community Testing Guidelines.
  • Integration tests updated (where possible). See DSC Community Testing Guidelines.
  • Code changes adheres to DSC Community Style Guidelines.

This change is Reviewable

@johlju johlju requested a review from a team as a code owner August 23, 2025 10:37
@coderabbitai
Copy link

coderabbitai bot commented Aug 23, 2025

Walkthrough

Adds SQL Agent Alert support: private resolver and five public cmdlets (Get/New/Set/Test/Remove), localization strings, expanded SMO test stubs, comprehensive unit and integration Pester tests, CI pipeline test entries, CHANGELOG updates, and multiple documentation/guideline edits. No breaking changes to existing public APIs.

Changes

Cohort / File(s) Summary
Agent Alert public cmdlets
source/Public/Get-SqlDscAgentAlert.ps1, source/Public/New-SqlDscAgentAlert.ps1, source/Public/Set-SqlDscAgentAlert.ps1, source/Public/Test-SqlDscAgentAlert.ps1, source/Public/Remove-SqlDscAgentAlert.ps1
Add CRUD/Test cmdlets for SQL Agent alerts with parameter sets, validation (ValidateRange, mutual exclusivity), pipeline input, ShouldProcess/Force/WhatIf patterns, PassThru options, localized messages, ScriptAnalyzer suppressions, and help.
Private helper
source/Private/Get-AgentAlertObject.ps1
Add helper to resolve an Agent Alert by name from ServerObject.JobServer.Alerts, returning the matching Alert or $null.
Localization
source/en-US/SqlServerDsc.strings.psd1
Add en‑US localization keys for agent-alert operations and ShouldProcess prompts; duplicated block present (risk of key collisions).
SMO test stubs
tests/Unit/Stubs/SMO.cs
Extend SMO stubs with Agent namespace types (JobServer, AlertCollection, Alert), enums, factories, and wire Server.JobServer to support unit tests.
Unit tests (public & private)
tests/Unit/Public/*SqlDscAgentAlert*.Tests.ps1, tests/Unit/Private/Get-AgentAlertObject.Tests.ps1, tests/Unit/Stubs/SMO.cs
Add comprehensive Pester unit tests covering parameter metadata, behavior paths (create/update/remove/test), WhatIf/Force/PassThru semantics, error cases, pipeline handling, and SMO stub usage; include module and PSDefaultParameterValues setup/teardown.
Integration tests
tests/Integration/Commands/*SqlDscAgentAlert*.Integration.Tests.ps1
Add integration Pester tests for Get/New/Set/Test/Remove against DSCSQLTEST with dependency guards, service start/stop, Connect/Disconnect usage, SQL message setup, test-alert creation/removal, and cleanup.
Pipeline
azure-pipelines.yml
Insert new Agent Alert integration test scripts into the SQL Server integration test sequence.
CHANGELOG
CHANGELOG.md
Document new Agent Alert public cmdlets and minor textual corrections.
Guidelines & instructions
.github/instructions/*.instructions.md
Multiple docs edits: private function naming, class-resource constructor/semantics, ShouldProcess/Force patterns, Pester rules and test organization, markdown escaping, localization key pattern, integration-test error handling, unit-test SMO stubbing guidance.
Editor settings
.vscode/settings.json
Broaden cSpell ignoreRegExpList from /sqlcmd\\.exe/g to /\b[A-Za-z]{2,}\d{4}\b/g.
Minor test edit
tests/Integration/Commands/Get-SqlDscRole.Integration.Tests.ps1
Remove assignment of $script:mockComputerName from the integration test setup.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant GetCmd as Get-SqlDscAgentAlert
  participant NewCmd as New-SqlDscAgentAlert
  participant SetCmd as Set-SqlDscAgentAlert
  participant RemoveCmd as Remove-SqlDscAgentAlert
  participant TestCmd as Test-SqlDscAgentAlert
  participant Helper as Get-AgentAlertObject
  participant JobServer as SMO JobServer
  participant Alerts as Alerts Collection
  participant Alert as Alert

  rect rgba(245,248,255,1)
    User->>GetCmd: Invoke(All | ByName)
    alt ByName
      GetCmd->>Helper: Resolve(ServerObject, Name)
      Helper->>JobServer: Access Alerts
      JobServer->>Alerts: Find by Name
      Alerts-->>Helper: Alert or null
      Helper-->>GetCmd: Alert or null
    else All
      GetCmd->>JobServer: Return Alerts collection
      Alerts-->>GetCmd: Alert[]
    end
    GetCmd-->>User: Return result
  end

  rect rgba(255,248,245,1)
    User->>NewCmd: Invoke(Name, Severity|MessageId, -PassThru?)
    NewCmd->>Helper: Ensure not exists
    alt not exists
      NewCmd->>User: ShouldProcess?
      opt confirmed
        NewCmd->>JobServer: Create Alert; Alert->>Alert: Create()
        NewCmd-->>User: (optional) created Alert
      end
    else exists
      NewCmd-->>User: Error (exists)
    end

    User->>SetCmd: Invoke(ServerObject|AlertObject, Severity|MessageId, -PassThru?)
    SetCmd->>Helper: Resolve if needed
    alt found
      SetCmd->>User: ShouldProcess?
      opt confirmed
        SetCmd->>Alert: Update properties; Alert->>Alert: Alter()
        SetCmd-->>User: (optional) updated Alert
      end
    else not found
      SetCmd-->>User: Error (not found)
    end

    User->>RemoveCmd: Invoke(ServerObject|AlertObject, -Force?)
    RemoveCmd->>Helper: Resolve if needed
    alt found
      RemoveCmd->>User: ShouldProcess? (Force may bypass)
      opt confirmed
        RemoveCmd->>Alert: Drop()
        RemoveCmd-->>User: Success
      end
    else not found
      RemoveCmd-->>User: Verbose no-op
    end
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • Jira integration is disabled
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bc7871f and d82b5f8.

📒 Files selected for processing (1)
  • tests/Unit/Public/Set-SqlDscAgentAlert.Tests.ps1 (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/Unit/Public/Set-SqlDscAgentAlert.Tests.ps1
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
  • GitHub Check: PSScriptAnalyzer
  • GitHub Check: PSScriptAnalyzer
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 58

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

💡 Knowledge Base configuration:

  • Jira integration is disabled
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between cba192e and 0fd3ee4.

📒 Files selected for processing (22)
  • .github/instructions/SqlServerDsc-guidelines.instructions.md (1 hunks)
  • .github/instructions/dsc-community-style-guidelines-class-resource.instructions.md (1 hunks)
  • .github/instructions/dsc-community-style-guidelines-markdown.instructions.md (1 hunks)
  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md (1 hunks)
  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md (2 hunks)
  • .vscode/settings.json (1 hunks)
  • CHANGELOG.md (2 hunks)
  • source/Private/Get-SqlDscAgentAlertObject.ps1 (1 hunks)
  • source/Public/Get-SqlDscAgentAlert.ps1 (1 hunks)
  • source/Public/New-SqlDscAgentAlert.ps1 (1 hunks)
  • source/Public/Remove-SqlDscAgentAlert.ps1 (1 hunks)
  • source/Public/Set-SqlDscAgentAlert.ps1 (1 hunks)
  • source/Public/Test-SqlDscAgentAlert.ps1 (1 hunks)
  • source/en-US/SqlServerDsc.strings.psd1 (1 hunks)
  • tests/Integration/Commands/SqlDscAgentAlert.Integration.Tests.ps1 (1 hunks)
  • tests/Unit/Private/Get-SqlDscAgentAlertObject.Tests.ps1 (1 hunks)
  • tests/Unit/Public/Get-SqlDscAgentAlert.Tests.ps1 (1 hunks)
  • tests/Unit/Public/New-SqlDscAgentAlert.Tests.ps1 (1 hunks)
  • tests/Unit/Public/Remove-SqlDscAgentAlert.Tests.ps1 (1 hunks)
  • tests/Unit/Public/Set-SqlDscAgentAlert.Tests.ps1 (1 hunks)
  • tests/Unit/Public/Test-SqlDscAgentAlert.Tests.ps1 (1 hunks)
  • tests/Unit/Stubs/SMO.cs (3 hunks)
🧰 Additional context used
📓 Path-based instructions (20)
source/Public/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

source/Public/*.ps1: Each public PowerShell command must be in its own script file named exactly as the command and located in source/Public
Public commands must localize Write-Debug/Verbose/Error/Warning and other messages using keys from source/en-US/SqlServerDsc.strings.psd1; keys prefixed with function name using underscores; data available as $script:localizedData

Files:

  • source/Public/Test-SqlDscAgentAlert.ps1
  • source/Public/Get-SqlDscAgentAlert.ps1
  • source/Public/Remove-SqlDscAgentAlert.ps1
  • source/Public/New-SqlDscAgentAlert.ps1
  • source/Public/Set-SqlDscAgentAlert.ps1
source/Public/*-SqlDsc*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

All public command names must have the noun prefixed with 'SqlDsc' (Verb-SqlDscNoun)

Files:

  • source/Public/Test-SqlDscAgentAlert.ps1
  • source/Public/Get-SqlDscAgentAlert.ps1
  • source/Public/Remove-SqlDscAgentAlert.ps1
  • source/Public/New-SqlDscAgentAlert.ps1
  • source/Public/Set-SqlDscAgentAlert.ps1
source/{Public,Private,Classes}/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

source/{Public,Private,Classes}/*.ps1: Comment-based help must precede each function/class with a comment block using at least .SYNOPSIS, .DESCRIPTION, .PARAMETER, .EXAMPLE, .NOTES
In comment-based help, each keyword must be indented 4 spaces and its text indented 8 spaces
Comment-based help .DESCRIPTION text must be descriptive and > 40 characters; .SYNOPSIS should be short; include at least one example
Use PascalCase for function names and parameters in public commands, private functions, and class-based resources

Files:

  • source/Public/Test-SqlDscAgentAlert.ps1
  • source/Private/Get-SqlDscAgentAlertObject.ps1
  • source/Public/Get-SqlDscAgentAlert.ps1
  • source/Public/Remove-SqlDscAgentAlert.ps1
  • source/Public/New-SqlDscAgentAlert.ps1
  • source/Public/Set-SqlDscAgentAlert.ps1
source/**/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Prefer SQL Server Management Objects (SMO) over T-SQL for interacting with SQL Server; only use T-SQL when SMO cannot achieve the functionality

Files:

  • source/Public/Test-SqlDscAgentAlert.ps1
  • source/Private/Get-SqlDscAgentAlertObject.ps1
  • source/Public/Get-SqlDscAgentAlert.ps1
  • source/Public/Remove-SqlDscAgentAlert.ps1
  • source/Public/New-SqlDscAgentAlert.ps1
  • source/Public/Set-SqlDscAgentAlert.ps1

⚙️ CodeRabbit configuration file

source/**/*.ps1: # Localization Guidelines

Requirements

  • Localize all Write-Debug, Write-Verbose, Write-Error, Write-Warning and $PSCmdlet.ThrowTerminatingError() messages
  • Use localized string keys, not hardcoded strings
  • Assume $script:localizedData is available

String Files

  • Commands/functions: source/en-US/SqlServerDsc.strings.psd1
  • Class resources: source/en-US/{ResourceClassName}.strings.psd1

Key Naming

  • Format: FunctionName_Description (underscore separators)
  • Example: Get_SqlDscDatabase_ConnectingToDatabase

String Format

ConvertFrom-StringData @'
    KeyName = Message with {0} placeholder. (PREFIX0001)
'@

String IDs

  • Format: (PREFIX####)
  • PREFIX: First letter of each word in class or function name (SqlSetup → SS, Get-SqlDscDatabase → GSDD)
  • Number: Sequential from 0001

Usage

Write-Verbose -Message ($script:localizedData.KeyName -f $value1)

Files:

  • source/Public/Test-SqlDscAgentAlert.ps1
  • source/Private/Get-SqlDscAgentAlertObject.ps1
  • source/Public/Get-SqlDscAgentAlert.ps1
  • source/Public/Remove-SqlDscAgentAlert.ps1
  • source/Public/New-SqlDscAgentAlert.ps1
  • source/Public/Set-SqlDscAgentAlert.ps1
**/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.ps1: PowerShell files must be UTF-8 without BOM and end with a newline
Try to limit lines to 120 characters
Use 4 spaces for indentation; never use tabs
Use '#' for single-line comments
Use <# ... #> for multiline comments; indent the multiline text 4 spaces
Use descriptive, clear, full names for variables, parameters, and function names; names must be more than 2 characters; no abbreviations
Use camelCase for local variable names
Never use Write-Host
Never use backtick (`) for line continuation
Use splatting to reduce line length
PowerShell reserved keywords should be lowercase
Use single quotes for string literals whenever possible; use double quotes only when interpolation is needed
Hashtable properties should be PascalCase and each on a separate line
When comparing to $null, place $null on the left side of the comparison

Files:

  • source/Public/Test-SqlDscAgentAlert.ps1
  • tests/Unit/Public/New-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Get-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Remove-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Set-SqlDscAgentAlert.Tests.ps1
  • source/Private/Get-SqlDscAgentAlertObject.ps1
  • source/Public/Get-SqlDscAgentAlert.ps1
  • tests/Unit/Private/Get-SqlDscAgentAlertObject.Tests.ps1
  • source/Public/Remove-SqlDscAgentAlert.ps1
  • tests/Integration/Commands/SqlDscAgentAlert.Integration.Tests.ps1
  • source/Public/New-SqlDscAgentAlert.ps1
  • source/Public/Set-SqlDscAgentAlert.ps1
  • tests/Unit/Public/Test-SqlDscAgentAlert.Tests.ps1
source/{Public,Private}/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

source/{Public,Private}/*.ps1: Public command and private function names must follow Verb-Noun format and use PowerShell approved verbs
Public commands and private functions must be advanced functions and include [CmdletBinding()]
Even with no parameters, public commands and private functions must include an empty parameter block: param ()
Every parameter in public commands and private functions must include a [Parameter()] attribute
Only mandatory parameters should have [Parameter(Mandatory = $true)]; non-mandatory parameters must not set Mandatory
For parameters, place attributes, datatype, and name on separate lines; separate parameters by a single blank line
Use Write-Verbose for action messages; Write-Debug for internal decision messages; Write-Error for errors; Write-Warning for warnings; Write-Information for informational messages

Files:

  • source/Public/Test-SqlDscAgentAlert.ps1
  • source/Private/Get-SqlDscAgentAlertObject.ps1
  • source/Public/Get-SqlDscAgentAlert.ps1
  • source/Public/Remove-SqlDscAgentAlert.ps1
  • source/Public/New-SqlDscAgentAlert.ps1
  • source/Public/Set-SqlDscAgentAlert.ps1
**

⚙️ CodeRabbit configuration file

**: # DSC Community Guidelines

Terminology

  • Command: Public command
  • Function: Private function
  • Resource: DSC class-based resource

Build & Test Workflow

  • Run project scripts in PowerShell from repository root
  • Build after source changes: .\build.ps1 -Tasks build
  • Test workflow: Build → Invoke-Pester -Path @('<test paths>') -Output Detailed
  • New session required after class changes

File Organization

  • Public commands: source/Public/{CommandName}.ps1
  • Private functions: source/Private/{FunctionName}.ps1
  • Unit tests: tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1
  • Integration tests: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Requirements

  • Always update CHANGELOG.md Unreleased section
  • Localize all strings using string keys
  • Check DscResource.Common before creating private functions
  • Separate reusable logic into private functions
  • Add unit tests for all commands/functions/resources
  • Add integration tests for all public commands and resources

Files:

  • source/Public/Test-SqlDscAgentAlert.ps1
  • tests/Unit/Public/New-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Get-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Remove-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Set-SqlDscAgentAlert.Tests.ps1
  • source/Private/Get-SqlDscAgentAlertObject.ps1
  • source/Public/Get-SqlDscAgentAlert.ps1
  • tests/Unit/Private/Get-SqlDscAgentAlertObject.Tests.ps1
  • source/Public/Remove-SqlDscAgentAlert.ps1
  • tests/Integration/Commands/SqlDscAgentAlert.Integration.Tests.ps1
  • source/en-US/SqlServerDsc.strings.psd1
  • source/Public/New-SqlDscAgentAlert.ps1
  • CHANGELOG.md
  • source/Public/Set-SqlDscAgentAlert.ps1
  • tests/Unit/Stubs/SMO.cs
  • tests/Unit/Public/Test-SqlDscAgentAlert.Tests.ps1
**/*.ps?(m|d)1

⚙️ CodeRabbit configuration file

**/*.ps?(m|d)1: # PowerShell Guidelines

Naming

  • Use descriptive names (3+ characters, no abbreviations)
  • Functions: PascalCase with Verb-Noun format using approved verbs
  • Parameters: PascalCase
  • Variables: camelCase
  • Keywords: lower-case
  • Classes: PascalCase
  • Include scope for script/global/environment variables: $script:, $global:, $env:

Formatting

Indentation & Spacing

  • Use 4 spaces (no tabs)
  • One space around operators: $a = 1 + 2
  • One space between type and variable: [String] $name
  • One space between keyword and parenthesis: if ($condition)
  • No spaces on empty lines
  • Try to limit lines to 120 characters

Braces

  • Newline before opening brace (except variable assignments)
  • One newline after opening brace
  • Two newlines after closing brace (one if followed by another brace or continuation)

Quotes

  • Use single quotes unless variable expansion is needed: 'text' vs "text $variable"

Arrays

  • Single line: @('one', 'two', 'three')
  • Multi-line: each element on separate line with proper indentation
  • Do not use the unary comma operator (,) in return statements to force
    an array

Hashtables

  • Empty: @{}
  • Multi-line: each property on separate line with proper indentation
  • Properties: Use PascalCase

Comments

  • Single line: # Comment (capitalized, on own line)
  • Multi-line: <# Comment #> format (opening and closing brackets on own line), and indent text
  • No commented-out code

Comment-based help

  • Always add comment-based help to all functions and scripts
  • Comment-based help: SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, EXAMPLE sections before function/class
  • Comment-based help indentation: keywords 4 spaces, text 8 spaces
  • Include examples for all parameter sets and combinations
  • INPUTS: List each pipeline‑accepted type (one per line) with a 1‑line description.
  • OUTPUTS: List each return type (one per line) with a 1‑line description. Must match both [OutputType()] and actual ...

Files:

  • source/Public/Test-SqlDscAgentAlert.ps1
  • tests/Unit/Public/New-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Get-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Remove-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Set-SqlDscAgentAlert.Tests.ps1
  • source/Private/Get-SqlDscAgentAlertObject.ps1
  • source/Public/Get-SqlDscAgentAlert.ps1
  • tests/Unit/Private/Get-SqlDscAgentAlertObject.Tests.ps1
  • source/Public/Remove-SqlDscAgentAlert.ps1
  • tests/Integration/Commands/SqlDscAgentAlert.Integration.Tests.ps1
  • source/en-US/SqlServerDsc.strings.psd1
  • source/Public/New-SqlDscAgentAlert.ps1
  • source/Public/Set-SqlDscAgentAlert.ps1
  • tests/Unit/Public/Test-SqlDscAgentAlert.Tests.ps1
tests/**/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

tests/**/*.ps1: All tests must use Pester and Pester v5.0 syntax
Do not test parameter validation
Test code must not exist outside of a Describe block
Each test file must contain exactly one Describe block named after the subject (public command, private function, or resource)
Each scenario/path should be in Context blocks starting with 'When'; It block descriptions should start with 'Should' and must call the subject; results and assertions stay within the same It; BeforeAll/BeforeEach must not call the subject
Use BeforeAll/BeforeEach/AfterAll/AfterEach inside Context, placed near the It blocks using them; duplication across contexts is acceptable; AfterAll can clean up; use BeforeEach/AfterEach sparingly
Use localized strings in tests only when necessary, retrieving values from $script:localizedData inside InModuleScope
Files that need to be mocked in tests must be created in Pester's $TestDrive

Files:

  • tests/Unit/Public/New-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Get-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Remove-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Set-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Private/Get-SqlDscAgentAlertObject.Tests.ps1
  • tests/Integration/Commands/SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Unit/Public/Test-SqlDscAgentAlert.Tests.ps1
tests/Unit/**/*.Tests.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

tests/Unit/**/*.Tests.ps1: Never test, mock, or use Should -Invoke for Write-Verbose or Write-Debug in unit tests
Do not use Should -Not -Throw; invoke the command directly
Include the standard unit test setup block (BeforeDiscovery/BeforeAll/AfterAll with module loading and PSDefaultParameterValues) before the Describe block

Files:

  • tests/Unit/Public/New-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Get-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Remove-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Set-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Private/Get-SqlDscAgentAlertObject.Tests.ps1
  • tests/Unit/Public/Test-SqlDscAgentAlert.Tests.ps1
tests/Unit/Public/*.Tests.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

tests/Unit/Public/*.Tests.ps1: Unit tests for public commands must be placed in tests/Unit/Public and named .Tests.ps1
Public command unit tests must include parameter set validation using the provided template/pattern
Public command unit tests must include tests to validate parameter properties (e.g., Mandatory, ValueFromPipeline)

Files:

  • tests/Unit/Public/New-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Get-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Remove-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Set-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Test-SqlDscAgentAlert.Tests.ps1
**/*.[Tt]ests.ps1

⚙️ CodeRabbit configuration file

**/*.[Tt]ests.ps1: # Tests Guidelines

Core Requirements

  • All public commands, private functions and classes must have unit tests
  • All public commands and class-based resources must have integration tests
  • Use Pester v5 syntax only
  • One Describe block per file matching the tested entity name
  • Test code only inside Describe blocks
  • Assertions only in It blocks
  • Never test Write-Verbose, Write-Debug, or parameter binding behavior
  • Pass all mandatory parameters to avoid prompts

Structure & Scope

  • Public commands: Never use InModuleScope (unless retrieving localized strings)
  • Private functions/class resources: Always use InModuleScope
  • Each scenario = separate Context block
  • Use nested Context blocks for complex scenarios
  • Mocking in BeforeAll (BeforeEach only when required)
  • Setup/teardown in BeforeAll,BeforeEach/AfterAll,AfterEach close to usage

Syntax Rules

  • PascalCase: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
  • It descriptions start with 'Should'
  • Context descriptions start with 'When'
  • Mock variables prefix: 'mock'
  • Prefer -BeTrue/-BeFalse over -Be $true/-Be $false
  • No Should -Not -Throw - invoke commands directly

File Organization

  • Class resources: tests/Unit/Classes/{Name}.Tests.ps1
  • Public commands: tests/Unit/Public/{Name}.Tests.ps1
  • Private functions: tests/Unit/Private/{Name}.Tests.ps1

Data-Driven Tests

  • Define variables in separate BeforeDiscovery for -ForEach (close to usage)
  • -ForEach allowed on Context and It blocks
  • Keep scope close to usage context

Best Practices

  • Assign unused return objects to $null
  • Tested entity must be called from within the It blocks
  • Keep results and assertions in same It block
  • Cover all scenarios and code paths
  • Use BeforeEach and AfterEach sparingly
  • Avoid try-catch-finally for cleanup, use AfterAll or AfterEach
  • Avoid unnecessary remove/recreate cyc...

Files:

  • tests/Unit/Public/New-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Get-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Remove-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Set-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Private/Get-SqlDscAgentAlertObject.Tests.ps1
  • tests/Integration/Commands/SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Unit/Public/Test-SqlDscAgentAlert.Tests.ps1
source/Private/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

source/Private/*.ps1: Each private function must be in its own script file named exactly as the function and located in source/Private (even if used by a single public command)
Private functions must localize Write-Debug/Verbose/Error/Warning and other messages using keys from source/en-US/SqlServerDsc.strings.psd1; keys prefixed with function name using underscores; data available as $script:localizedData

Files:

  • source/Private/Get-SqlDscAgentAlertObject.ps1
tests/Unit/Private/*.Tests.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Unit tests for private functions must be placed in tests/Unit/Private and named .Tests.ps1

Files:

  • tests/Unit/Private/Get-SqlDscAgentAlertObject.Tests.ps1
tests/Integration/Commands/*.Integration.Tests.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

tests/Integration/Commands/*.Integration.Tests.ps1: Integration tests must exist for all public commands, not mock any commands, be placed at tests/Integration/Commands, and be named .Integration.Tests.ps1
In CI, integration tests must use Get-ComputerName when the computer name is needed
Include the standard integration test setup block (BeforeDiscovery/BeforeAll with module loading) before the first Describe block

Files:

  • tests/Integration/Commands/SqlDscAgentAlert.Integration.Tests.ps1
tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1

⚙️ CodeRabbit configuration file

tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1: # Integration Tests Guidelines

Requirements

  • Location Commands: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1
  • Location Resources: tests/Integration/Resources/{ResourceName}.Integration.Tests.ps1
  • No mocking - real environment only
  • Cover all scenarios and code paths
  • Use Get-ComputerName for computer names in CI
  • Avoid ExpectedMessage for Should -Throw assertions
  • Only run integration tests in CI unless explicitly instructed.
  • Call commands with -Force parameter where applicable (avoids prompting).

Required Setup Block

[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
param ()

BeforeDiscovery {
    try
    {
        if (-not (Get-Module -Name 'DscResource.Test'))
        {
            # Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
            if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
            {
                # Redirect all streams to $null, except the error stream (stream 2)
                & "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
            }

            # If the dependencies have not been resolved, this will throw an error.
            Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
        }
    }
    catch [System.IO.FileNotFoundException]
    {
        throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.'
    }
}

BeforeAll {
    $script:dscModuleName = 'SqlServerDsc'

    Import-Module -Name $script:dscModuleName -Force -ErrorAction 'Stop'
}

Files:

  • tests/Integration/Commands/SqlDscAgentAlert.Integration.Tests.ps1
source/en-US/SqlServerDsc.strings.psd1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

All localized strings for public commands and private functions must be added to source/en-US/SqlServerDsc.strings.psd1 following existing key patterns

Files:

  • source/en-US/SqlServerDsc.strings.psd1
source/en-US/*.strings.psd1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Each class-based resource must have a strings file in source/en-US named exactly .strings.psd1; keys use underscores as word separator

Files:

  • source/en-US/SqlServerDsc.strings.psd1
CHANGELOG.md

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Always update the Unreleased section in CHANGELOG.md using Keep a Changelog format with concrete release notes for changes (new/modified commands, functions, resources)

Files:

  • CHANGELOG.md

⚙️ CodeRabbit configuration file

CHANGELOG.md: # Changelog Guidelines

  • Always update the Unreleased section in CHANGELOG.md
  • Use Keep a Changelog format
  • Describe notable changes briefly, ≤2 items per change type
  • Reference issues using format #<issue_number>
  • No empty lines between list items in same section
  • Do not add item if there are already an existing item for the same change

Files:

  • CHANGELOG.md
**/*.md

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Markdown: wrap lines at word boundaries when exceeding 80 characters; use 2 spaces for indentation

Files:

  • CHANGELOG.md

⚙️ CodeRabbit configuration file

**/*.md: # Markdown Style Guidelines

  • Wrap lines at word boundaries when over 80 characters (except tables/code blocks)
  • Use 2 spaces for indentation
  • Use '1.' for all items in ordered lists (1/1/1 numbering style)
  • Disable MD013 rule by adding a comment for tables/code blocks exceeding 80 characters
  • Empty lines required before/after code blocks and headings (except before line 1)
  • Code blocks must specify language identifiers

Text Formatting

  • Parameters: bold
  • Values/literals: inline code
  • Resource/module/product names: italic
  • Commands/files/paths: inline code

Files:

  • CHANGELOG.md
🧠 Learnings (41)
📚 Learning: 2025-08-18T13:50:53.789Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2132
File: tests/Unit/Public/New-SqlDscLogin.Tests.ps1:0-0
Timestamp: 2025-08-18T13:50:53.789Z
Learning: In SqlServerDsc unit tests, SMO stub objects can be used to verify method calls like Create() on Login objects by adding mock verifications with Should -Invoke, providing more robust testing than just checking for no exceptions.

Applied to files:

  • tests/Unit/Public/New-SqlDscAgentAlert.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Unit/Public/*.Tests.ps1 : Public command unit tests must include parameter set validation using the provided template/pattern

Applied to files:

  • tests/Unit/Public/New-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Get-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Remove-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Set-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Test-SqlDscAgentAlert.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Unit/Public/*.Tests.ps1 : Public command unit tests must include tests to validate parameter properties (e.g., Mandatory, ValueFromPipeline)

Applied to files:

  • tests/Unit/Public/Get-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Remove-SqlDscAgentAlert.Tests.ps1
  • tests/Unit/Public/Set-SqlDscAgentAlert.Tests.ps1
  • .github/instructions/SqlServerDsc-guidelines.instructions.md
  • tests/Unit/Public/Test-SqlDscAgentAlert.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Each test file must contain exactly one Describe block named after the subject (public command, private function, or resource)

Applied to files:

  • tests/Unit/Public/Get-SqlDscAgentAlert.Tests.ps1
  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
  • tests/Unit/Public/Test-SqlDscAgentAlert.Tests.ps1
📚 Learning: 2025-08-17T10:15:48.194Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: tests/Unit/Public/Remove-SqlDscLogin.Tests.ps1:36-39
Timestamp: 2025-08-17T10:15:48.194Z
Learning: Public command unit tests guideline: Never use InModuleScope unless accessing localized strings from $script:localizedData. PSDefaultParameterValues for InModuleScope should be kept in public command tests to support localized string retrieval when necessary.

Applied to files:

  • tests/Unit/Public/Remove-SqlDscAgentAlert.Tests.ps1
  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private}/*.ps1 : Use Write-Verbose for action messages; Write-Debug for internal decision messages; Write-Error for errors; Write-Warning for warnings; Write-Information for informational messages

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Unit/**/*.Tests.ps1 : Never test, mock, or use Should -Invoke for Write-Verbose or Write-Debug in unit tests

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Private/*.ps1 : Private functions must localize Write-Debug/Verbose/Error/Warning and other messages using keys from source/en-US/SqlServerDsc.strings.psd1; keys prefixed with function name using underscores; data available as $script:localizedData

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
  • source/Private/Get-SqlDscAgentAlertObject.ps1
  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
  • source/en-US/SqlServerDsc.strings.psd1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Public/*.ps1 : Public commands must localize Write-Debug/Verbose/Error/Warning and other messages using keys from source/en-US/SqlServerDsc.strings.psd1; keys prefixed with function name using underscores; data available as $script:localizedData

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
  • source/en-US/SqlServerDsc.strings.psd1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Test code must not exist outside of a Describe block

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Each scenario/path should be in Context blocks starting with 'When'; It block descriptions should start with 'Should' and must call the subject; results and assertions stay within the same It; BeforeAll/BeforeEach must not call the subject

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
  • .github/instructions/SqlServerDsc-guidelines.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Use BeforeAll/BeforeEach/AfterAll/AfterEach inside Context, placed near the It blocks using them; duplication across contexts is acceptable; AfterAll can clean up; use BeforeEach/AfterEach sparingly

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
  • .github/instructions/SqlServerDsc-guidelines.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Include the standard integration test setup block (BeforeDiscovery/BeforeAll with module loading) before the first Describe block

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
  • .github/instructions/SqlServerDsc-guidelines.instructions.md
  • tests/Integration/Commands/SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Unit/**/*.Tests.ps1 : Include the standard unit test setup block (BeforeDiscovery/BeforeAll/AfterAll with module loading and PSDefaultParameterValues) before the Describe block

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Unit/Private/*.Tests.ps1 : Unit tests for private functions must be placed in tests/Unit/Private and named <Function>.Tests.ps1

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
  • .github/instructions/SqlServerDsc-guidelines.instructions.md
  • tests/Unit/Private/Get-SqlDscAgentAlertObject.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : All tests must use Pester and Pester v5.0 syntax

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-18T10:44:38.990Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2132
File: source/Public/New-SqlDscLogin.ps1:254-257
Timestamp: 2025-08-18T10:44:38.990Z
Learning: When implementing Force and Confirm parameter interaction in PowerShell functions with SupportsShouldProcess, use the pattern `if ($Force.IsPresent -and -not $Confirm)` to suppress confirmations. This ensures that explicit `-Confirm:$true` is respected even when `-Force` is present, preserving user intent when they explicitly request confirmation alongside Force.

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T10:03:59.993Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/Public/Remove-SqlDscLogin.ps1:83-86
Timestamp: 2025-08-17T10:03:59.993Z
Learning: In PowerShell functions with SupportsShouldProcess, the $Confirm automatic variable defaults to $false when no -Confirm parameter is passed, and only becomes $true when -Confirm or -Confirm:$true is explicitly passed. The logic `if ($Force.IsPresent -and -not $Confirm)` correctly handles both cases where no -Confirm is passed and where -Confirm:$false is explicitly passed.

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private}/*.ps1 : Public command and private function names must follow Verb-Noun format and use PowerShell approved verbs

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private}/*.ps1 : Public commands and private functions must be advanced functions and include [CmdletBinding()]

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private,Classes}/*.ps1 : Use PascalCase for function names and parameters in public commands, private functions, and class-based resources

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
  • .github/instructions/dsc-community-style-guidelines-class-resource.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Private/*.ps1 : Each private function must be in its own script file named exactly as the function and located in source/Private (even if used by a single public command)

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to **/*.ps1 : Use descriptive, clear, full names for variables, parameters, and function names; names must be more than 2 characters; no abbreviations

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private}/*.ps1 : For parameters, place attributes, datatype, and name on separate lines; separate parameters by a single blank line

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T10:13:30.079Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/Public/Remove-SqlDscLogin.ps1:104-108
Timestamp: 2025-08-17T10:13:30.079Z
Learning: In SqlServerDsc unit tests, SMO object stubs (like Login objects) should have properly mocked Parent properties with correct Server stub types and valid InstanceName values, rather than handling null Parent scenarios in production code.

Applied to files:

  • .github/instructions/SqlServerDsc-guidelines.instructions.md
  • tests/Unit/Stubs/SMO.cs
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to azure-pipelines.yml : Add each public command integration test script to a group within the Integration_Test_Commands_SqlServer stage in ./azure-pipelines.yml, choosing the appropriate group

Applied to files:

  • .github/instructions/SqlServerDsc-guidelines.instructions.md
  • tests/Integration/Commands/SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Integration tests must exist for all public commands, not mock any commands, be placed at tests/Integration/Commands, and be named <Command>.Integration.Tests.ps1

Applied to files:

  • .github/instructions/SqlServerDsc-guidelines.instructions.md
  • tests/Integration/Commands/SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Files that need to be mocked in tests must be created in Pester's $TestDrive

Applied to files:

  • .github/instructions/SqlServerDsc-guidelines.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Unit/Public/*.Tests.ps1 : Unit tests for public commands must be placed in tests/Unit/Public and named <Command>.Tests.ps1

Applied to files:

  • .github/instructions/SqlServerDsc-guidelines.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Unit/Classes/*.Tests.ps1 : Unit tests for class-based resources must be placed in tests/Unit/Classes and named <Resource>.Tests.ps1

Applied to files:

  • .github/instructions/SqlServerDsc-guidelines.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to **/*.ps1 : Use <# ... #> for multiline comments; indent the multiline text 4 spaces

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-markdown.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to **/*.md : Markdown: wrap lines at word boundaries when exceeding 80 characters; use 2 spaces for indentation

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-markdown.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/en-US/SqlServerDsc.strings.psd1 : All localized strings for public commands and private functions must be added to source/en-US/SqlServerDsc.strings.psd1 following existing key patterns

Applied to files:

  • source/en-US/SqlServerDsc.strings.psd1
  • CHANGELOG.md
📚 Learning: 2025-08-17T10:48:15.384Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/suffix.ps1:24-24
Timestamp: 2025-08-17T10:48:15.384Z
Learning: In source/suffix.ps1, the Write-Verbose message in the catch block for Import-SqlDscPreferredModule does not need localization because the exception message from Import-SqlDscPreferredModule is already localized by that command, making it an edge case exception to the localization guidelines.

Applied to files:

  • source/en-US/SqlServerDsc.strings.psd1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Classes/*.ps1 : Derived DSC resource classes must override Get, Test, Set, GetCurrentState, Modify, AssertProperties, NormalizeProperties following the provided pattern

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-class-resource.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Classes/*.ps1 : Each DSC class-based resource must be in its own script file named exactly as the resource class and located in source/Classes

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-class-resource.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Classes/*.ps1 : Derived DSC resource classes must inherit from a parent class

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-class-resource.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Classes/*.ps1 : A DSC resource should inherit ResourceBase only when it cannot inherit SqlResourceBase or when not related to SQL Server Database Engine

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-class-resource.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Classes/*.ps1 : Derived DSC resource classes must use [DscResource(RunAsCredential = 'Optional')]

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-class-resource.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Classes/*.ps1 : Class-based resources must use localized strings available via $this.localizedData

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-class-resource.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Classes/*.ps1 : A DSC resource should inherit SqlResourceBase if it needs to connect to a SQL Server Database Engine

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-class-resource.instructions.md
🪛 LanguageTool
.github/instructions/dsc-community-style-guidelines-pester.instructions.md

[grammar] ~15-~15: Use commas correctly
Context: ...s - Never test verbose or debug messages, or parameter binding behavior - Pass al...

(QB_NEW_EN_OTHER_ERROR_IDS_33)


[grammar] ~15-~15: There might be a mistake here.
Context: ... messages, or parameter binding behavior - Pass all mandatory parameters to avoid p...

(QB_NEW_EN_OTHER)

.github/instructions/dsc-community-style-guidelines-powershell.instructions.md

[grammar] ~74-~74: There might be a problem here.
Context: ... a Force parameter for functions that uses $PSCmdlet.ShouldContinue or `$PSCmdlet.ShouldPro...

(QB_NEW_EN_MERGED_MATCH)


[grammar] ~74-~74: There might be a mistake here.
Context: ... that uses $PSCmdlet.ShouldContinue or $PSCmdlet.ShouldProcess - For state-changing functions, use `Supports...

(QB_NEW_EN_OTHER)


[grammar] ~75-~75: Use correct spacing
Context: ...ss- For state-changing functions, useSupportsShouldProcess` - Place ShouldProcess check immediately be...

(QB_NEW_EN_OTHER_ERROR_IDS_5)


[grammar] ~76-~76: Use hyphens correctly
Context: ...cess check immediately before each state-change - $PSCmdlet.ShouldProcess m...

(QB_NEW_EN_OTHER_ERROR_IDS_29)


[grammar] ~76-~76: Use hyphens correctly
Context: ...eck immediately before each state-change - $PSCmdlet.ShouldProcess must use required pattern - Use `$PSCmdlet.T...

(QB_NEW_EN_OTHER_ERROR_IDS_29)


[grammar] ~77-~77: There might be a mistake here.
Context: ...ShouldProcessmust use required pattern - Use$PSCmdlet.ThrowTerminatingError()` ...

(QB_NEW_EN_OTHER)


[grammar] ~86-~86: Use correct spacing
Context: ...code. ## ShouldProcess Required Pattern - Ensure VerboseDescription explains what ...

(QB_NEW_EN_OTHER_ERROR_IDS_5)


[grammar] ~88-~88: There might be a mistake here.
Context: ...oseDescription explains what will happen - Ensure VerboseWarning asks for confirmat...

(QB_NEW_EN_OTHER)


[grammar] ~90-~90: Use prepositions correctly
Context: ... Caption short and descriptive (without ending .) ```powershell $verboseDescription...

(QB_NEW_EN_OTHER_ERROR_IDS_7)


[grammar] ~90-~90: There might be a mistake here.
Context: ...ort and descriptive (without ending .) powershell $verboseDescriptionMessage = $script:localizedData.FunctionName_Action_ShouldProcessVerboseDescription -f $param1, $param2 $verboseWarningMessage = $script:localizedData.FunctionName_Action_ShouldProcessVerboseWarning -f $param1 $captionMessage = $script:localizedData.FunctionName_Action_ShouldProcessCaption if ($PSCmdlet.ShouldProcess($verboseDescriptionMessage, $verboseWarningMessage, $captionMessage)) { # state changing code } ## Force Parameter Pattern ```powershell i...

(QB_NEW_EN_OTHER)


[grammar] ~103-~103: Use correct spacing
Context: ...g code } ## Force Parameter Pattern powershell if ($Force.IsPresent -and -not $Confirm) { $ConfirmPreference = 'None' } ### Structure powershell <# .SYNOPSI...

(QB_NEW_EN_OTHER_ERROR_IDS_5)

.github/instructions/SqlServerDsc-guidelines.instructions.md

[grammar] ~33-~33: There might be a mistake here.
Context: ...the required dependencies ## Unit tests - When unit test uses SMO types, ensure th...

(QB_NEW_EN)


[grammar] ~34-~34: There might be a mistake here.
Context: ...sure they are properly stubbed in SMO.cs - Load stub types from SMO.cs in unit test...

(QB_NEW_EN_OTHER)


[grammar] ~35-~35: There might be a mistake here.
Context: ...pes from SMO.cs in unit test files, e.g. Add-Type -Path "$PSScriptRoot/../Stubs/SMO.cs" - After changing SMO stub types, run tests...

(QB_NEW_EN_OTHER)


[grammar] ~36-~36: There might be a mistake here.
Context: ...hell session for changes to take effect.

(QB_NEW_EN)

.github/instructions/dsc-community-style-guidelines-markdown.instructions.md

[grammar] ~13-~13: There might be a mistake here.
Context: ... in file paths only (not in code blocks) - Code blocks must specify language identi...

(QB_NEW_EN_OTHER)

.github/instructions/dsc-community-style-guidelines-class-resource.instructions.md

[grammar] ~11-~11: There might be a mistake here.
Context: ...coration only. ## Requirements - File: source/Classes/020_{ResourceName}.ps1 - Decoration: `[DscResource(RunAsCredentia...

(QB_NEW_EN)


[grammar] ~12-~12: There might be a mistake here.
Context: ...(replace with 'Mandatory' if required) - Inheritance: Must inherit ResourceBase...

(QB_NEW_EN)


[grammar] ~13-~13: There might be a mistake here.
Context: ... inherit ResourceBase (part of module DscResource.Base) - $this.localizedData hashtable...

(QB_NEW_EN_OTHER)


[grammar] ~13-~13: Use correct spacing
Context: ...eBase(part of module DscResource.Base) -$this.localizedDatahashtable auto-populated byResourceBas...

(QB_NEW_EN_OTHER_ERROR_IDS_5)


[grammar] ~14-~14: Use correct spacing
Context: ...by ResourceBase from localization file ## Required constructor ```powershell MyRe...

(QB_NEW_EN_OTHER_ERROR_IDS_5)


[grammar] ~16-~16: Use correct spacing
Context: ...calization file ## Required constructor powershell MyResourceName () : base ($PSScriptRoot) { # Property names where state cannot be enforced, e.g Ensure $this.ExcludeDscProperties = @() } ## Required Method Pattern ```powershell [...

(QB_NEW_EN_OTHER_ERROR_IDS_5)


[grammar] ~26-~26: Use correct spacing
Context: ... = @() } ## Required Method Pattern powershell [MyResourceName] Get() { # Call base implementation to get current state $currentState = ([ResourceBase] $this).Get() # If needed, post-processing on current state that can not be handled by GetCurrentState() return $currentState } [System.Boolean] Test() { # Call base implementation to test current state $inDesiredState = ([ResourceBase] $this).Test() # If needed, post-processing on test result that can not be handled by base Test() return $inDesiredState } [void] Set() { # Call base implementation to set desired state ([ResourceBase] $this).Set() # If needed, additional state changes that can not be handled by Modify() } hidden [System.Collections.Hashtable] GetCurrentState([System.Collections.Hashtable] $properties) { # Always return current state as hashtable, $properties contains key properties } hidden [void] Modify([System.Collections.Hashtable] $properties) { # Always set desired state, $properties contain those that must change state } ## Optional Method Pattern powershell h...

(QB_NEW_EN_OTHER_ERROR_IDS_5)


[grammar] ~68-~68: Use correct spacing
Context: ... state } ## Optional Method Pattern powershell hidden [void] AssertProperties([System.Collections.Hashtable] $properties) { # Validate user-provided properties, $properties contains user assigned values } hidden [void] NormalizeProperties([System.Collections.Hashtable] $properties) { # Normalize user-provided properties, $properties contains user assigned values } ```

(QB_NEW_EN_OTHER_ERROR_IDS_5)

🪛 markdownlint-cli2 (0.17.2)
.github/instructions/dsc-community-style-guidelines-powershell.instructions.md

74-74: Line length
Expected: 80; Actual: 109

(MD013, line-length)


76-76: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


77-77: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


93-93: Line length
Expected: 80; Actual: 122

(MD013, line-length)


94-94: Line length
Expected: 80; Actual: 105

(MD013, line-length)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
  • GitHub Check: PSScriptAnalyzer
  • GitHub Check: PSScriptAnalyzer

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review continued from previous batch...

@codecov
Copy link

codecov bot commented Aug 23, 2025

Codecov Report

❌ Patch coverage is 95.57522% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 94%. Comparing base (8eaf645) to head (d82b5f8).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
source/Public/Set-SqlDscAgentAlert.ps1 92% 3 Missing ⚠️
source/Public/New-SqlDscAgentAlert.ps1 91% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##           main   #2149    +/-   ##
=====================================
  Coverage    94%     94%            
=====================================
  Files       116     122     +6     
  Lines      8269    8382   +113     
=====================================
+ Hits       7830    7939   +109     
- Misses      439     443     +4     
Flag Coverage Δ
unit 94% <95%> (+<1%) ⬆️
Files with missing lines Coverage Δ
source/Private/Get-AgentAlertObject.ps1 100% <100%> (ø)
source/Public/Get-SqlDscAgentAlert.ps1 100% <100%> (ø)
source/Public/Remove-SqlDscAgentAlert.ps1 100% <100%> (ø)
source/Public/Test-SqlDscAgentAlert.ps1 100% <100%> (ø)
source/Public/New-SqlDscAgentAlert.ps1 91% <91%> (ø)
source/Public/Set-SqlDscAgentAlert.ps1 92% <92%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

♻️ Duplicate comments (2)
.github/instructions/dsc-community-style-guidelines-powershell.instructions.md (2)

74-74: Grammar: “functions that use” (subject–verb agreement)

Same issue previously reported; still applicable here.

- - Include a `Force` parameter for functions that uses `$PSCmdlet.ShouldContinue` or `$PSCmdlet.ShouldProcess`
+ - Include a `Force` parameter for functions that use `$PSCmdlet.ShouldContinue` or `$PSCmdlet.ShouldProcess`

76-77: Nested list indentation under “For state-changing functions…”

Same indentation nit previously reported; align nested bullets by 2 spaces to render correctly.

-    - Place ShouldProcess check immediately before each state-change
-    - `$PSCmdlet.ShouldProcess` must use required pattern
+  - Place ShouldProcess check immediately before each state-change
+  - `$PSCmdlet.ShouldProcess` must use required pattern
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

💡 Knowledge Base configuration:

  • Jira integration is disabled
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e021916 and 38e8096.

📒 Files selected for processing (2)
  • .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md (1 hunks)
  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md (4 hunks)
🧰 Additional context used
🧠 Learnings (30)
📚 Learning: 2025-08-18T10:44:38.990Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2132
File: source/Public/New-SqlDscLogin.ps1:254-257
Timestamp: 2025-08-18T10:44:38.990Z
Learning: When implementing Force and Confirm parameter interaction in PowerShell functions with SupportsShouldProcess, use the pattern `if ($Force.IsPresent -and -not $Confirm)` to suppress confirmations. This ensures that explicit `-Confirm:$true` is respected even when `-Force` is present, preserving user intent when they explicitly request confirmation alongside Force.

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T10:03:59.993Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/Public/Remove-SqlDscLogin.ps1:83-86
Timestamp: 2025-08-17T10:03:59.993Z
Learning: In PowerShell functions with SupportsShouldProcess, the $Confirm automatic variable defaults to $false when no -Confirm parameter is passed, and only becomes $true when -Confirm or -Confirm:$true is explicitly passed. The logic `if ($Force.IsPresent -and -not $Confirm)` correctly handles both cases where no -Confirm is passed and where -Confirm:$false is explicitly passed.

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private,Classes}/*.ps1 : In comment-based help, each keyword must be indented 4 spaces and its text indented 8 spaces

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to **/*.ps1 : Use 4 spaces for indentation; never use tabs

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to **/*.ps1 : Use <# ... #> for multiline comments; indent the multiline text 4 spaces

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private}/*.ps1 : Public command and private function names must follow Verb-Noun format and use PowerShell approved verbs

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private}/*.ps1 : Public commands and private functions must be advanced functions and include [CmdletBinding()]

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Private/*.ps1 : Private functions must localize Write-Debug/Verbose/Error/Warning and other messages using keys from source/en-US/SqlServerDsc.strings.psd1; keys prefixed with function name using underscores; data available as $script:localizedData

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private,Classes}/*.ps1 : Use PascalCase for function names and parameters in public commands, private functions, and class-based resources

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private}/*.ps1 : Use Write-Verbose for action messages; Write-Debug for internal decision messages; Write-Error for errors; Write-Warning for warnings; Write-Information for informational messages

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Private/*.ps1 : Each private function must be in its own script file named exactly as the function and located in source/Private (even if used by a single public command)

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to **/*.ps1 : Use descriptive, clear, full names for variables, parameters, and function names; names must be more than 2 characters; no abbreviations

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private}/*.ps1 : For parameters, place attributes, datatype, and name on separate lines; separate parameters by a single blank line

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Public/*.ps1 : Public commands must localize Write-Debug/Verbose/Error/Warning and other messages using keys from source/en-US/SqlServerDsc.strings.psd1; keys prefixed with function name using underscores; data available as $script:localizedData

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private}/*.ps1 : Every parameter in public commands and private functions must include a [Parameter()] attribute

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private}/*.ps1 : Even with no parameters, public commands and private functions must include an empty parameter block: param ()

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private,Classes}/*.ps1 : Comment-based help must precede each function/class with a comment block using at least .SYNOPSIS, .DESCRIPTION, .PARAMETER, .EXAMPLE, .NOTES

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-16T13:15:17.108Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2134
File: source/Public/Get-SqlDscLogin.ps1:27-38
Timestamp: 2025-08-16T13:15:17.108Z
Learning: For PowerShell comment-based help .OUTPUTS sections: Each distinct return type should have its own .OUTPUTS entry with a description of when that type is returned, even if the underlying implementation uses array casting. This follows official PowerShell documentation standards where you list each return type on its own line under .OUTPUTS with clear descriptions of the conditions for each type.

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to **/*.ps1 : Hashtable properties should be PascalCase and each on a separate line

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T10:59:03.955Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/Public/Remove-SqlDscLogin.ps1:59-77
Timestamp: 2025-08-17T10:59:03.955Z
Learning: In PowerShell, mandatory parameters with [Parameter(Mandatory = $true)] automatically guard against $null values and don't require additional [ValidateNotNull()] or [ValidateNotNullOrEmpty()] attributes, as these validations are redundant with the mandatory parameter behavior.

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Integration tests must exist for all public commands, not mock any commands, be placed at tests/Integration/Commands, and be named <Command>.Integration.Tests.ps1

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Include the standard integration test setup block (BeforeDiscovery/BeforeAll with module loading) before the first Describe block

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Unit/**/*.Tests.ps1 : Do not use Should -Not -Throw; invoke the command directly

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Each scenario/path should be in Context blocks starting with 'When'; It block descriptions should start with 'Should' and must call the subject; results and assertions stay within the same It; BeforeAll/BeforeEach must not call the subject

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : In CI, integration tests must use Get-ComputerName when the computer name is needed

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : All tests must use Pester and Pester v5.0 syntax

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Use BeforeAll/BeforeEach/AfterAll/AfterEach inside Context, placed near the It blocks using them; duplication across contexts is acceptable; AfterAll can clean up; use BeforeEach/AfterEach sparingly

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Unit/**/*.Tests.ps1 : Include the standard unit test setup block (BeforeDiscovery/BeforeAll/AfterAll with module loading and PSDefaultParameterValues) before the Describe block

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Test code must not exist outside of a Describe block

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Each test file must contain exactly one Describe block named after the subject (public command, private function, or resource)

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md
🪛 LanguageTool
.github/instructions/dsc-community-style-guidelines-powershell.instructions.md

[grammar] ~74-~74: There might be a problem here.
Context: ... a Force parameter for functions that uses $PSCmdlet.ShouldContinue or `$PSCmdlet.ShouldPro...

(QB_NEW_EN_MERGED_MATCH)


[grammar] ~74-~74: There might be a mistake here.
Context: ... that uses $PSCmdlet.ShouldContinue or $PSCmdlet.ShouldProcess - For state-changing functions, use `Supports...

(QB_NEW_EN_OTHER)


[grammar] ~75-~75: Use correct spacing
Context: ...ss- For state-changing functions, useSupportsShouldProcess` - Place ShouldProcess check immediately be...

(QB_NEW_EN_OTHER_ERROR_IDS_5)


[grammar] ~76-~76: Use hyphens correctly
Context: ...cess check immediately before each state-change - $PSCmdlet.ShouldProcess m...

(QB_NEW_EN_OTHER_ERROR_IDS_29)


[grammar] ~76-~76: Use hyphens correctly
Context: ...eck immediately before each state-change - $PSCmdlet.ShouldProcess must use required pattern - Use `$PSCmdlet.T...

(QB_NEW_EN_OTHER_ERROR_IDS_29)


[grammar] ~77-~77: There might be a mistake here.
Context: ...ShouldProcessmust use required pattern - Use$PSCmdlet.ThrowTerminatingError()` ...

(QB_NEW_EN_OTHER)


[grammar] ~86-~86: Use correct spacing
Context: ...code. ## ShouldProcess Required Pattern - Ensure VerboseDescription explains what ...

(QB_NEW_EN_OTHER_ERROR_IDS_5)


[grammar] ~88-~88: There might be a mistake here.
Context: ...oseDescription explains what will happen - Ensure VerboseWarning asks for confirmat...

(QB_NEW_EN_OTHER)


[grammar] ~90-~90: Use prepositions correctly
Context: ... Caption short and descriptive (without ending .) ```powershell $verboseDescription...

(QB_NEW_EN_OTHER_ERROR_IDS_7)


[grammar] ~90-~90: There might be a mistake here.
Context: ...ort and descriptive (without ending .) powershell $verboseDescriptionMessage = $script:localizedData.FunctionName_Action_ShouldProcessVerboseDescription -f $param1, $param2 $verboseWarningMessage = $script:localizedData.FunctionName_Action_ShouldProcessVerboseWarning -f $param1 $captionMessage = $script:localizedData.FunctionName_Action_ShouldProcessCaption if ($PSCmdlet.ShouldProcess($verboseDescriptionMessage, $verboseWarningMessage, $captionMessage)) { # state changing code } ## Force Parameter Pattern ```powershell i...

(QB_NEW_EN_OTHER)


[grammar] ~103-~103: Use correct spacing
Context: ...g code } ## Force Parameter Pattern powershell if ($Force.IsPresent -and -not $Confirm) { $ConfirmPreference = 'None' } ### Structure powershell <# .SYNOPSI...

(QB_NEW_EN_OTHER_ERROR_IDS_5)

.github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md

[grammar] ~17-~17: There might be a mistake here.
Context: ...commands so failures surface immediately ## Required Setup Block ```powershell [Sys...

(QB_NEW_EN_OTHER)

🪛 markdownlint-cli2 (0.17.2)
.github/instructions/dsc-community-style-guidelines-powershell.instructions.md

74-74: Line length
Expected: 80; Actual: 109

(MD013, line-length)


76-76: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


77-77: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


93-93: Line length
Expected: 80; Actual: 122

(MD013, line-length)


94-94: Line length
Expected: 80; Actual: 105

(MD013, line-length)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
  • GitHub Check: PSScriptAnalyzer
  • GitHub Check: PSScriptAnalyzer
🔇 Additional comments (1)
.github/instructions/dsc-community-style-guidelines-powershell.instructions.md (1)

138-138: Consistent use of fully-qualified types in OutputType

Using [System.String] aligns with the “full type name” guidance above. Looks good.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (5)
.github/instructions/dsc-community-style-guidelines-powershell.instructions.md (5)

76-77: Fix nested list indentation to 2 spaces (MD007)

Adjust sub‑bullets under “SupportsShouldProcess” to 2‑space indent.

-    - Place ShouldProcess check immediately before each state-change
-    - `$PSCmdlet.ShouldProcess` must use required pattern
+  - Place ShouldProcess check immediately before each state-change
+  - `$PSCmdlet.ShouldProcess` must use required pattern

86-91: Tighten wording and clarify ShouldProcess argument mapping

Make the bullets precise and add a one‑line mapping so contributors don’t confuse messages.

 ## ShouldProcess Required Pattern
@@
-- Ensure VerboseDescription explains what will happen
-- Ensure VerboseWarning asks for confirmation
-- Keep Caption short and descriptive (without ending `.`)
+- Ensure VerboseDescription explains what will happen
+- Ensure VerboseWarning describes the action succinctly (used as the “action”)
+- Keep Caption short and descriptive (no trailing `.`)
+
+Mapping:
+- `$PSCmdlet.ShouldProcess(<VerboseDescription>, <VerboseWarning>, <Caption>)`

92-101: Align variable names with ShouldProcess semantics; silence MD013 for long sample lines

Rename variables to mirror target/action/caption to reduce confusion. Wrap the code block with markdownlint MD013 disable/enable so we don’t force artificial line breaks in realistic samples.

+<!-- markdownlint-disable MD013 -->
 ```powershell
-$verboseDescriptionMessage = $script:localizedData.FunctionName_Action_ShouldProcessVerboseDescription -f $param1, $param2
-$verboseWarningMessage = $script:localizedData.FunctionName_Action_ShouldProcessVerboseWarning -f $param1
-$captionMessage = $script:localizedData.FunctionName_Action_ShouldProcessCaption
+$targetMessage  = $script:localizedData.FunctionName_Action_ShouldProcessVerboseDescription -f $param1, $param2
+$actionMessage  = $script:localizedData.FunctionName_Action_ShouldProcessVerboseWarning -f $param1
+$captionMessage = $script:localizedData.FunctionName_Action_ShouldProcessCaption
 
-if ($PSCmdlet.ShouldProcess($verboseDescriptionMessage, $verboseWarningMessage, $captionMessage))
+if ($PSCmdlet.ShouldProcess($targetMessage, $actionMessage, $captionMessage))
 {
     # state changing code
 }

+


---

`103-110`: **Add scope-safety note for Force pattern and tie to SupportsShouldProcess**

Great: pattern matches the preferred `if ($Force.IsPresent -and -not $Confirm)`. Add a concise note to keep `$ConfirmPreference` scoped and require `SupportsShouldProcess` on functions using this.



```diff
 ```powershell
 if ($Force.IsPresent -and -not $Confirm)
 {
     $ConfirmPreference = 'None'
 }

+Note:
+- Use this pattern only inside functions that declare

  • [CmdletBinding(SupportsShouldProcess = $true)].
    +- Keep $ConfirmPreference changes scoped to the function (PowerShell does this
  • by default for preference variables); avoid leaking to callers.

---

`159-159`: **Clarify OutputType guidance for no-output functions**

Explicitly state that `[OutputType([System.Void])]` is optional for truly no‑output functions, but when used must match `.OUTPUTS`.



```diff
-- `[OutputType({return type})]` for functions with output, no output use `[OutputType()]`
+- `[OutputType({return type})]` for functions with output. For no output,
+  `[OutputType([System.Void])]` is optional but, when used, must match `.OUTPUTS`.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

💡 Knowledge Base configuration:

  • Jira integration is disabled
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 38e8096 and a11721c.

📒 Files selected for processing (1)
  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md (4 hunks)
🧰 Additional context used
🧠 Learnings (23)
📚 Learning: 2025-08-18T10:44:38.990Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2132
File: source/Public/New-SqlDscLogin.ps1:254-257
Timestamp: 2025-08-18T10:44:38.990Z
Learning: When implementing Force and Confirm parameter interaction in PowerShell functions with SupportsShouldProcess, use the pattern `if ($Force.IsPresent -and -not $Confirm)` to suppress confirmations. This ensures that explicit `-Confirm:$true` is respected even when `-Force` is present, preserving user intent when they explicitly request confirmation alongside Force.

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T10:03:59.993Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/Public/Remove-SqlDscLogin.ps1:83-86
Timestamp: 2025-08-17T10:03:59.993Z
Learning: In PowerShell functions with SupportsShouldProcess, the $Confirm automatic variable defaults to $false when no -Confirm parameter is passed, and only becomes $true when -Confirm or -Confirm:$true is explicitly passed. The logic `if ($Force.IsPresent -and -not $Confirm)` correctly handles both cases where no -Confirm is passed and where -Confirm:$false is explicitly passed.

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private,Classes}/*.ps1 : In comment-based help, each keyword must be indented 4 spaces and its text indented 8 spaces

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to **/*.ps1 : Use 4 spaces for indentation; never use tabs

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to **/*.ps1 : Use <# ... #> for multiline comments; indent the multiline text 4 spaces

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Private/*.ps1 : Private functions must localize Write-Debug/Verbose/Error/Warning and other messages using keys from source/en-US/SqlServerDsc.strings.psd1; keys prefixed with function name using underscores; data available as $script:localizedData

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Public/*.ps1 : Public commands must localize Write-Debug/Verbose/Error/Warning and other messages using keys from source/en-US/SqlServerDsc.strings.psd1; keys prefixed with function name using underscores; data available as $script:localizedData

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T10:48:15.384Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/suffix.ps1:24-24
Timestamp: 2025-08-17T10:48:15.384Z
Learning: In source/suffix.ps1, the Write-Verbose message in the catch block for Import-SqlDscPreferredModule does not need localization because the exception message from Import-SqlDscPreferredModule is already localized by that command, making it an edge case exception to the localization guidelines.

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to **/*.ps1 : Use descriptive, clear, full names for variables, parameters, and function names; names must be more than 2 characters; no abbreviations

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T10:15:48.194Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: tests/Unit/Public/Remove-SqlDscLogin.Tests.ps1:36-39
Timestamp: 2025-08-17T10:15:48.194Z
Learning: Public command unit tests guideline: Never use InModuleScope unless accessing localized strings from $script:localizedData. PSDefaultParameterValues for InModuleScope should be kept in public command tests to support localized string retrieval when necessary.

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private}/*.ps1 : Use Write-Verbose for action messages; Write-Debug for internal decision messages; Write-Error for errors; Write-Warning for warnings; Write-Information for informational messages

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-16T13:15:17.108Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2134
File: source/Public/Get-SqlDscLogin.ps1:27-38
Timestamp: 2025-08-16T13:15:17.108Z
Learning: For PowerShell comment-based help .OUTPUTS sections: Each distinct return type should have its own .OUTPUTS entry with a description of when that type is returned, even if the underlying implementation uses array casting. This follows official PowerShell documentation standards where you list each return type on its own line under .OUTPUTS with clear descriptions of the conditions for each type.

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-16T13:15:17.108Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2134
File: source/Public/Get-SqlDscLogin.ps1:27-38
Timestamp: 2025-08-16T13:15:17.108Z
Learning: For PowerShell comment-based help in .OUTPUTS sections: Each distinct type that can be returned should have its own .OUTPUTS entry, even if the implementation technically always returns an array. This follows official PowerShell documentation standards and helps users understand what to expect in different usage scenarios.

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private}/*.ps1 : Public command and private function names must follow Verb-Noun format and use PowerShell approved verbs

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private}/*.ps1 : Public commands and private functions must be advanced functions and include [CmdletBinding()]

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private,Classes}/*.ps1 : Use PascalCase for function names and parameters in public commands, private functions, and class-based resources

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Private/*.ps1 : Each private function must be in its own script file named exactly as the function and located in source/Private (even if used by a single public command)

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private}/*.ps1 : For parameters, place attributes, datatype, and name on separate lines; separate parameters by a single blank line

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private}/*.ps1 : Every parameter in public commands and private functions must include a [Parameter()] attribute

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private}/*.ps1 : Even with no parameters, public commands and private functions must include an empty parameter block: param ()

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private,Classes}/*.ps1 : Comment-based help must precede each function/class with a comment block using at least .SYNOPSIS, .DESCRIPTION, .PARAMETER, .EXAMPLE, .NOTES

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to **/*.ps1 : Hashtable properties should be PascalCase and each on a separate line

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private}/*.ps1 : Only mandatory parameters should have [Parameter(Mandatory = $true)]; non-mandatory parameters must not set Mandatory

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
🪛 LanguageTool
.github/instructions/dsc-community-style-guidelines-powershell.instructions.md

[grammar] ~74-~74: There might be a problem here.
Context: ... a Force parameter for functions that uses $PSCmdlet.ShouldContinue or `$PSCmdlet.ShouldPro...

(QB_NEW_EN_MERGED_MATCH)


[grammar] ~74-~74: There might be a mistake here.
Context: ... that uses $PSCmdlet.ShouldContinue or $PSCmdlet.ShouldProcess - For state-changing functions, use `Supports...

(QB_NEW_EN_OTHER)


[grammar] ~75-~75: Use correct spacing
Context: ...ss- For state-changing functions, useSupportsShouldProcess` - Place ShouldProcess check immediately be...

(QB_NEW_EN_OTHER_ERROR_IDS_5)


[grammar] ~76-~76: Use hyphens correctly
Context: ...cess check immediately before each state-change - $PSCmdlet.ShouldProcess m...

(QB_NEW_EN_OTHER_ERROR_IDS_29)


[grammar] ~76-~76: Use hyphens correctly
Context: ...eck immediately before each state-change - $PSCmdlet.ShouldProcess must use required pattern - Use `$PSCmdlet.T...

(QB_NEW_EN_OTHER_ERROR_IDS_29)


[grammar] ~77-~77: There might be a mistake here.
Context: ...ShouldProcessmust use required pattern - Use$PSCmdlet.ThrowTerminatingError()` ...

(QB_NEW_EN_OTHER)


[grammar] ~86-~86: Use correct spacing
Context: ...code. ## ShouldProcess Required Pattern - Ensure VerboseDescription explains what ...

(QB_NEW_EN_OTHER_ERROR_IDS_5)


[grammar] ~88-~88: There might be a mistake here.
Context: ...oseDescription explains what will happen - Ensure VerboseWarning asks for confirmat...

(QB_NEW_EN_OTHER)


[grammar] ~90-~90: Use prepositions correctly
Context: ... Caption short and descriptive (without ending .) ```powershell $verboseDescription...

(QB_NEW_EN_OTHER_ERROR_IDS_7)


[grammar] ~90-~90: There might be a mistake here.
Context: ...ort and descriptive (without ending .) powershell $verboseDescriptionMessage = $script:localizedData.FunctionName_Action_ShouldProcessVerboseDescription -f $param1, $param2 $verboseWarningMessage = $script:localizedData.FunctionName_Action_ShouldProcessVerboseWarning -f $param1 $captionMessage = $script:localizedData.FunctionName_Action_ShouldProcessCaption if ($PSCmdlet.ShouldProcess($verboseDescriptionMessage, $verboseWarningMessage, $captionMessage)) { # state changing code } ## Force Parameter Pattern ```powershell i...

(QB_NEW_EN_OTHER)


[grammar] ~103-~103: Use correct spacing
Context: ...g code } ## Force Parameter Pattern powershell if ($Force.IsPresent -and -not $Confirm) { $ConfirmPreference = 'None' } ### Structure powershell <# .SYNOPSI...

(QB_NEW_EN_OTHER_ERROR_IDS_5)

🪛 markdownlint-cli2 (0.17.2)
.github/instructions/dsc-community-style-guidelines-powershell.instructions.md

74-74: Line length
Expected: 80; Actual: 109

(MD013, line-length)


76-76: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


77-77: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


93-93: Line length
Expected: 80; Actual: 122

(MD013, line-length)


94-94: Line length
Expected: 80; Actual: 105

(MD013, line-length)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
  • GitHub Check: PSScriptAnalyzer
  • GitHub Check: PSScriptAnalyzer
🔇 Additional comments (1)
.github/instructions/dsc-community-style-guidelines-powershell.instructions.md (1)

138-138: Use fully qualified type name in OutputType

Switch to [System.String] aligns with the guideline “use full type name.” Ensure the .OUTPUTS entry also lists System.String.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

♻️ Duplicate comments (8)
.github/instructions/dsc-community-style-guidelines-pester.instructions.md (4)

15-15: Hyphenate the attributive compound “parameter-binding”

Use a hyphen when the noun phrase is used attributively to tighten style and match prior guidance.

- - Never test verbose messages, debug messages or parameter binding behavior
+ - Never test verbose messages, debug messages or parameter-binding behavior

29-29: Make the ‘It’ rule explicit; remove the parenthetical

State the prohibition directly to avoid ambiguity.

- - `It` descriptions start with 'Should' (never use 'when')
+ - `It` descriptions must start with 'Should' and must not start with 'When'.

33-36: Make mocking rules imperative and punctuate consistently

Use parallel “Do not/Omit/Set” phrasing and end bullets with periods for consistency and clarity.

- - Never add an empty `-MockWith` block
- - Omit `-MockWith` when returning `$null`
- - Set `$PSDefaultParameterValues` for `Mock:ModuleName`, `Should:ModuleName`, `InModuleScope:ModuleName`
- - Omit `-ModuleName` parameter on Pester commands
+ - Do not add an empty `-MockWith` block.
+ - Omit `-MockWith` when the mock returns `$null`.
+ - Set `$PSDefaultParameterValues` for `Mock:ModuleName`, `Should:ModuleName`, and `InModuleScope:ModuleName`.
+ - Do not pass the `-ModuleName` parameter on Pester commands.

49-49: Surround the list with blank lines to satisfy markdownlint MD032

Add a blank line before and after the list block in “Best Practices” so markdownlint is happy.

-## Best Practices
+## Best Practices
+
 - Inside `It` blocks, assign unused return objects to `$null` (unless part of pipeline)
   - Tested entity must be called from within the `It` blocks
   - Keep results and assertions in same `It` block
   - Cover all scenarios and code paths
   - Use `BeforeEach` and `AfterEach` sparingly
   - Avoid try-catch-finally for cleanup, use `AfterAll` or `AfterEach`
   - Avoid unnecessary remove/recreate cycles
+
source/Public/Set-SqlDscAgentAlert.ps1 (4)

2-76: Help is solid; add a concise .NOTES to document SMO constraint and Force semantics

The help now meets the SYNOPSIS/DESCRIPTION/PARAMETER/INPUTS/OUTPUTS/EXAMPLE requirements with correct indentation. Add a short .NOTES clarifying:

  • Exactly one of Severity or MessageId must be non-zero on the alert object (SMO constraint).
  • Passing -Force suppresses confirmation unless -Confirm:$true is explicitly provided.

Apply this diff to append a .NOTES section to the help block:

@@
     .EXAMPLE
         $serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
         Set-SqlDscAgentAlert -ServerObject $serverObject -Name 'MyAlert' -Severity 16 -Force
 
         Updates the SQL Agent Alert named 'MyAlert' to severity level 16 without prompting for confirmation.
+    .NOTES
+        Only one of Severity or MessageId can be non-zero at a time. When one is set to a non-zero value,
+        this command ensures the other is set to 0 to satisfy SMO constraints. Passing -Force suppresses
+        confirmation prompts unless -Confirm:$true is explicitly specified.
 #>

128-130: Require at least one of -Severity or -MessageId

Mutual exclusivity is enforced, but callers can provide neither, making Set- a no-op. Fail fast with a localized terminating error.

         # Validate that both Severity and MessageId are not specified
         Assert-BoundParameter -BoundParameterList $PSBoundParameters -MutuallyExclusiveList1 @('Severity') -MutuallyExclusiveList2 @('MessageId')
 
+        # Require at least one of Severity or MessageId to be supplied
+        if (-not $PSBoundParameters.ContainsKey('Severity') -and -not $PSBoundParameters.ContainsKey('MessageId'))
+        {
+            $targetName = if ($PSCmdlet.ParameterSetName -eq 'ServerObject') { $Name } else { $AlertObject.Name }
+            # Localize this key: Set_SqlDscAgentAlert_NoPropertiesSpecified = 'Specify either -Severity or -MessageId for alert ''{0}''.' (SSAA0001)
+            $errorMessage = $script:localizedData.Set_SqlDscAgentAlert_NoPropertiesSpecified -f $targetName
+            New-InvalidArgumentException -Message $errorMessage
+        }

If you want, I can add the new string key to source/en-US/SqlServerDsc.strings.psd1 and wire it up.


152-156: Don’t assume Alert.Parent.Parent; derive instance name by parameter set

Relying on Parent.Parent is brittle and breaks with current SMO stubs that omit Parent. Use the ServerObject when in that parameter set.

-        $verboseDescriptionMessage = $script:localizedData.Set_SqlDscAgentAlert_UpdateShouldProcessVerboseDescription -f $alertObjectToUpdate.Name, $alertObjectToUpdate.Parent.Parent.InstanceName
+        $instanceName = if ($PSCmdlet.ParameterSetName -eq 'ServerObject') { $ServerObject.InstanceName } else { $alertObjectToUpdate.Parent.Parent.InstanceName }
+        $verboseDescriptionMessage = $script:localizedData.Set_SqlDscAgentAlert_UpdateShouldProcessVerboseDescription -f $alertObjectToUpdate.Name, $instanceName
         $verboseWarningMessage = $script:localizedData.Set_SqlDscAgentAlert_UpdateShouldProcessVerboseWarning -f $alertObjectToUpdate.Name
         $captionMessage = $script:localizedData.Set_SqlDscAgentAlert_UpdateShouldProcessCaption

164-190: Enforce SMO constraint: zero the counterpart property before setting the new value; guard against both zero

Without clearing the counterpart, Alter() can leave both properties non-zero (or both zero, depending on input and prior state), violating SMO rules.

         if ($PSBoundParameters.ContainsKey('Severity'))
         {
             if ($alertObjectToUpdate.Severity -ne $Severity)
             {
                 Write-Verbose -Message ($script:localizedData.Set_SqlDscAgentAlert_SettingSeverity -f $Severity, $alertObjectToUpdate.Name)
+                # Ensure MessageId is zeroed when setting Severity
+                if ($alertObjectToUpdate.MessageId -ne 0)
+                {
+                    $alertObjectToUpdate.MessageId = 0
+                    $hasChanges = $true
+                }
                 $alertObjectToUpdate.Severity = $Severity
                 $hasChanges = $true
             }
@@
         if ($PSBoundParameters.ContainsKey('MessageId'))
         {
             if ($alertObjectToUpdate.MessageId -ne $MessageId)
             {
                 Write-Verbose -Message ($script:localizedData.Set_SqlDscAgentAlert_SettingMessageId -f $MessageId, $alertObjectToUpdate.Name)
+                # Ensure Severity is zeroed when setting MessageId
+                if ($alertObjectToUpdate.Severity -ne 0)
+                {
+                    $alertObjectToUpdate.Severity = 0
+                    $hasChanges = $true
+                }
                 $alertObjectToUpdate.MessageId = $MessageId
                 $hasChanges = $true
             }
         }
+
+        # Guard: ensure we don't end up with both criteria zero, which is invalid for Alerts
+        if (($alertObjectToUpdate.Severity -eq 0) -and ($alertObjectToUpdate.MessageId -eq 0))
+        {
+            # Localize this key: Set_SqlDscAgentAlert_BothCriteriaZero = 'Alert ''{0}'' must have either Severity or MessageId set.' (SSAA0002)
+            $errorMessage = $script:localizedData.Set_SqlDscAgentAlert_BothCriteriaZero -f $alertObjectToUpdate.Name
+            New-InvalidArgumentException -Message $errorMessage
+        }

If you prefer verbose messages when zeroing, we can add localized strings (e.g., Set_SqlDscAgentAlert_ZeroingMessageId/ZeroingSeverity) — say the word and I’ll patch the strings file as well.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

💡 Knowledge Base configuration:

  • Jira integration is disabled
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 5912913 and d5e3f5f.

📒 Files selected for processing (2)
  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md (3 hunks)
  • source/Public/Set-SqlDscAgentAlert.ps1 (1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
source/Public/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

source/Public/*.ps1: Each public PowerShell command must be in its own script file named exactly as the command and located in source/Public
Public commands must localize Write-Debug/Verbose/Error/Warning and other messages using keys from source/en-US/SqlServerDsc.strings.psd1; keys prefixed with function name using underscores; data available as $script:localizedData

Files:

  • source/Public/Set-SqlDscAgentAlert.ps1
source/Public/*-SqlDsc*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

All public command names must have the noun prefixed with 'SqlDsc' (Verb-SqlDscNoun)

Files:

  • source/Public/Set-SqlDscAgentAlert.ps1
source/{Public,Private,Classes}/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

source/{Public,Private,Classes}/*.ps1: Comment-based help must precede each function/class with a comment block using at least .SYNOPSIS, .DESCRIPTION, .PARAMETER, .EXAMPLE, .NOTES
In comment-based help, each keyword must be indented 4 spaces and its text indented 8 spaces
Comment-based help .DESCRIPTION text must be descriptive and > 40 characters; .SYNOPSIS should be short; include at least one example
Use PascalCase for function names and parameters in public commands, private functions, and class-based resources

Files:

  • source/Public/Set-SqlDscAgentAlert.ps1
source/**/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Prefer SQL Server Management Objects (SMO) over T-SQL for interacting with SQL Server; only use T-SQL when SMO cannot achieve the functionality

Files:

  • source/Public/Set-SqlDscAgentAlert.ps1

⚙️ CodeRabbit configuration file

source/**/*.ps1: # Localization Guidelines

Requirements

  • Localize all Write-Debug, Write-Verbose, Write-Error, Write-Warning and $PSCmdlet.ThrowTerminatingError() messages
  • Use localized string keys, not hardcoded strings
  • Assume $script:localizedData is available

String Files

  • Commands/functions: source/en-US/SqlServerDsc.strings.psd1
  • Class resources: source/en-US/{ResourceClassName}.strings.psd1

Key Naming

  • Format: FunctionName_Description (underscore separators)
  • Example: Get_SqlDscDatabase_ConnectingToDatabase

String Format

ConvertFrom-StringData @'
    KeyName = Message with {0} placeholder. (PREFIX0001)
'@

String IDs

  • Format: (PREFIX####)
  • PREFIX: First letter of each word in class or function name (SqlSetup → SS, Get-SqlDscDatabase → GSDD)
  • Number: Sequential from 0001

Usage

Write-Verbose -Message ($script:localizedData.KeyName -f $value1)

Files:

  • source/Public/Set-SqlDscAgentAlert.ps1
**/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.ps1: PowerShell files must be UTF-8 without BOM and end with a newline
Try to limit lines to 120 characters
Use 4 spaces for indentation; never use tabs
Use '#' for single-line comments
Use <# ... #> for multiline comments; indent the multiline text 4 spaces
Use descriptive, clear, full names for variables, parameters, and function names; names must be more than 2 characters; no abbreviations
Use camelCase for local variable names
Never use Write-Host
Never use backtick (`) for line continuation
Use splatting to reduce line length
PowerShell reserved keywords should be lowercase
Use single quotes for string literals whenever possible; use double quotes only when interpolation is needed
Hashtable properties should be PascalCase and each on a separate line
When comparing to $null, place $null on the left side of the comparison

Files:

  • source/Public/Set-SqlDscAgentAlert.ps1
source/{Public,Private}/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

source/{Public,Private}/*.ps1: Public command and private function names must follow Verb-Noun format and use PowerShell approved verbs
Public commands and private functions must be advanced functions and include [CmdletBinding()]
Even with no parameters, public commands and private functions must include an empty parameter block: param ()
Every parameter in public commands and private functions must include a [Parameter()] attribute
Only mandatory parameters should have [Parameter(Mandatory = $true)]; non-mandatory parameters must not set Mandatory
For parameters, place attributes, datatype, and name on separate lines; separate parameters by a single blank line
Use Write-Verbose for action messages; Write-Debug for internal decision messages; Write-Error for errors; Write-Warning for warnings; Write-Information for informational messages

Files:

  • source/Public/Set-SqlDscAgentAlert.ps1
**

⚙️ CodeRabbit configuration file

**: # DSC Community Guidelines

Terminology

  • Command: Public command
  • Function: Private function
  • Resource: DSC class-based resource

Build & Test Workflow

  • Run project scripts in PowerShell from repository root
  • Build after source changes: .\build.ps1 -Tasks build
  • Test workflow: Build → Invoke-Pester -Path @('<test paths>') -Output Detailed
  • New session required after class changes

File Organization

  • Public commands: source/Public/{CommandName}.ps1
  • Private functions: source/Private/{FunctionName}.ps1
  • Unit tests: tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1
  • Integration tests: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Requirements

  • Always update CHANGELOG.md Unreleased section
  • Localize all strings using string keys
  • Check DscResource.Common before creating private functions
  • Separate reusable logic into private functions
  • Add unit tests for all commands/functions/resources
  • Add integration tests for all public commands and resources

Files:

  • source/Public/Set-SqlDscAgentAlert.ps1
**/*.ps?(m|d)1

⚙️ CodeRabbit configuration file

**/*.ps?(m|d)1: # PowerShell Guidelines

Naming

  • Use descriptive names (3+ characters, no abbreviations)
  • Functions: PascalCase with Verb-Noun format using approved verbs
  • Parameters: PascalCase
  • Variables: camelCase
  • Keywords: lower-case
  • Classes: PascalCase
  • Include scope for script/global/environment variables: $script:, $global:, $env:

Formatting

Indentation & Spacing

  • Use 4 spaces (no tabs)
  • One space around operators: $a = 1 + 2
  • One space between type and variable: [String] $name
  • One space between keyword and parenthesis: if ($condition)
  • No spaces on empty lines
  • Try to limit lines to 120 characters

Braces

  • Newline before opening brace (except variable assignments)
  • One newline after opening brace
  • Two newlines after closing brace (one if followed by another brace or continuation)

Quotes

  • Use single quotes unless variable expansion is needed: 'text' vs "text $variable"

Arrays

  • Single line: @('one', 'two', 'three')
  • Multi-line: each element on separate line with proper indentation
  • Do not use the unary comma operator (,) in return statements to force
    an array

Hashtables

  • Empty: @{}
  • Multi-line: each property on separate line with proper indentation
  • Properties: Use PascalCase

Comments

  • Single line: # Comment (capitalized, on own line)
  • Multi-line: <# Comment #> format (opening and closing brackets on own line), and indent text
  • No commented-out code

Comment-based help

  • Always add comment-based help to all functions and scripts
  • Comment-based help: SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, EXAMPLE sections before function/class
  • Comment-based help indentation: keywords 4 spaces, text 8 spaces
  • Include examples for all parameter sets and combinations
  • INPUTS: List each pipeline‑accepted type (one per line) with a 1‑line description.
  • OUTPUTS: List each return type (one per line) with a 1‑line description. Must match both [OutputType()] and actual ...

Files:

  • source/Public/Set-SqlDscAgentAlert.ps1
🧠 Learnings (20)
📚 Learning: 2025-08-17T10:48:15.384Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/suffix.ps1:24-24
Timestamp: 2025-08-17T10:48:15.384Z
Learning: In source/suffix.ps1, the Write-Verbose message in the catch block for Import-SqlDscPreferredModule does not need localization because the exception message from Import-SqlDscPreferredModule is already localized by that command, making it an edge case exception to the localization guidelines.

Applied to files:

  • source/Public/Set-SqlDscAgentAlert.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Private/*.ps1 : Private functions must localize Write-Debug/Verbose/Error/Warning and other messages using keys from source/en-US/SqlServerDsc.strings.psd1; keys prefixed with function name using underscores; data available as $script:localizedData

Applied to files:

  • source/Public/Set-SqlDscAgentAlert.ps1
📚 Learning: 2025-08-17T10:13:30.079Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/Public/Remove-SqlDscLogin.ps1:104-108
Timestamp: 2025-08-17T10:13:30.079Z
Learning: In SqlServerDsc unit tests, SMO object stubs (like Login objects) should have properly mocked Parent properties with correct Server stub types and valid InstanceName values, rather than handling null Parent scenarios in production code.

Applied to files:

  • source/Public/Set-SqlDscAgentAlert.ps1
📚 Learning: 2025-08-18T10:44:38.990Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2132
File: source/Public/New-SqlDscLogin.ps1:254-257
Timestamp: 2025-08-18T10:44:38.990Z
Learning: When implementing Force and Confirm parameter interaction in PowerShell functions with SupportsShouldProcess, use the pattern `if ($Force.IsPresent -and -not $Confirm)` to suppress confirmations. This ensures that explicit `-Confirm:$true` is respected even when `-Force` is present, preserving user intent when they explicitly request confirmation alongside Force.

Applied to files:

  • source/Public/Set-SqlDscAgentAlert.ps1
📚 Learning: 2025-08-17T10:03:59.993Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/Public/Remove-SqlDscLogin.ps1:83-86
Timestamp: 2025-08-17T10:03:59.993Z
Learning: In PowerShell functions with SupportsShouldProcess, the $Confirm automatic variable defaults to $false when no -Confirm parameter is passed, and only becomes $true when -Confirm or -Confirm:$true is explicitly passed. The logic `if ($Force.IsPresent -and -not $Confirm)` correctly handles both cases where no -Confirm is passed and where -Confirm:$false is explicitly passed.

Applied to files:

  • source/Public/Set-SqlDscAgentAlert.ps1
📚 Learning: 2025-08-16T13:15:17.108Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2134
File: source/Public/Get-SqlDscLogin.ps1:27-38
Timestamp: 2025-08-16T13:15:17.108Z
Learning: For PowerShell comment-based help .OUTPUTS sections: Each distinct return type should have its own .OUTPUTS entry with a description of when that type is returned, even if the underlying implementation uses array casting. This follows official PowerShell documentation standards where you list each return type on its own line under .OUTPUTS with clear descriptions of the conditions for each type.

Applied to files:

  • source/Public/Set-SqlDscAgentAlert.ps1
📚 Learning: 2025-08-16T13:15:17.108Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2134
File: source/Public/Get-SqlDscLogin.ps1:27-38
Timestamp: 2025-08-16T13:15:17.108Z
Learning: For PowerShell comment-based help in .OUTPUTS sections: Each distinct type that can be returned should have its own .OUTPUTS entry, even if the implementation technically always returns an array. This follows official PowerShell documentation standards and helps users understand what to expect in different usage scenarios.

Applied to files:

  • source/Public/Set-SqlDscAgentAlert.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : All tests must use Pester and Pester v5.0 syntax

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Unit/**/*.Tests.ps1 : Never test, mock, or use Should -Invoke for Write-Verbose or Write-Debug in unit tests

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T10:15:48.194Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: tests/Unit/Public/Remove-SqlDscLogin.Tests.ps1:36-39
Timestamp: 2025-08-17T10:15:48.194Z
Learning: Public command unit tests guideline: Never use InModuleScope unless accessing localized strings from $script:localizedData. PSDefaultParameterValues for InModuleScope should be kept in public command tests to support localized string retrieval when necessary.

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Test code must not exist outside of a Describe block

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Each test file must contain exactly one Describe block named after the subject (public command, private function, or resource)

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Each scenario/path should be in Context blocks starting with 'When'; It block descriptions should start with 'Should' and must call the subject; results and assertions stay within the same It; BeforeAll/BeforeEach must not call the subject

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Use BeforeAll/BeforeEach/AfterAll/AfterEach inside Context, placed near the It blocks using them; duplication across contexts is acceptable; AfterAll can clean up; use BeforeEach/AfterEach sparingly

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Include the standard integration test setup block (BeforeDiscovery/BeforeAll with module loading) before the first Describe block

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Unit/**/*.Tests.ps1 : Include the standard unit test setup block (BeforeDiscovery/BeforeAll/AfterAll with module loading and PSDefaultParameterValues) before the Describe block

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Unit/Private/*.Tests.ps1 : Unit tests for private functions must be placed in tests/Unit/Private and named <Function>.Tests.ps1

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Files that need to be mocked in tests must be created in Pester's $TestDrive

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Unit/Classes/*.Tests.ps1 : Unit tests for class-based resources must be placed in tests/Unit/Classes and named <Resource>.Tests.ps1

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Integration tests must exist for all public commands, not mock any commands, be placed at tests/Integration/Commands, and be named <Command>.Integration.Tests.ps1

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
🪛 LanguageTool
.github/instructions/dsc-community-style-guidelines-pester.instructions.md

[grammar] ~15-~15: There might be a mistake here.
Context: ...ks - Never test verbose messages, debug messages or parameter binding behavior - Pass al...

(QB_NEW_EN_OTHER)


[grammar] ~15-~15: There might be a mistake here.
Context: ...g messages or parameter binding behavior - Pass all mandatory parameters to avoid p...

(QB_NEW_EN_OTHER)


[grammar] ~29-~29: There might be a mistake here.
Context: ...s start with 'Should' (never use 'when') - Mock variables prefix: 'mock' - Prefer `...

(QB_NEW_EN_OTHER)


[grammar] ~30-~30: There might be a mistake here.
Context: ... 'when') - Mock variables prefix: 'mock' - Prefer -BeTrue/-BeFalse over `-Be $t...

(QB_NEW_EN)


[grammar] ~31-~31: There might be a mistake here.
Context: ...r -BeTrue/-BeFalse over -Be $true/-Be $false - No Should -Not -Throw - invoke command...

(QB_NEW_EN)


[typographical] ~32-~32: To join two clauses or set off examples, consider using an em dash.
Context: ...lseover-Be $true/-Be $false- NoShould -Not -Throw` - invoke commands directly - Never add an empty ...

(QB_NEW_EN_DASH_RULE_EM)


[grammar] ~32-~32: There might be a mistake here.
Context: ... -Not -Throw- invoke commands directly - Never add an empty-MockWith` block - O...

(QB_NEW_EN_OTHER)


[grammar] ~33-~33: There might be a mistake here.
Context: ...y - Never add an empty -MockWith block - Omit -MockWith when returning $null ...

(QB_NEW_EN_OTHER)


[grammar] ~34-~34: There might be a mistake here.
Context: ... block - Omit -MockWith when returning $null - Set $PSDefaultParameterValues for `Moc...

(QB_NEW_EN_OTHER)


[grammar] ~35-~35: There might be a mistake here.
Context: ...r Mock:ModuleName, Should:ModuleName, InModuleScope:ModuleName - Omit -ModuleName parameter on Pester c...

(QB_NEW_EN_OTHER)


[grammar] ~36-~36: There might be a mistake here.
Context: ...ModuleNameparameter on Pester commands ## File Organization - Class resources:te...

(QB_NEW_EN_OTHER)


[grammar] ~49-~49: There might be a mistake here.
Context: ... return objects to $null (unless part of pipeline) - Tested entity must be calle...

(QB_NEW_EN)

🪛 markdownlint-cli2 (0.17.2)
.github/instructions/dsc-community-style-guidelines-pester.instructions.md

49-49: Lists should be surrounded by blank lines

(MD032, blanks-around-lists)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
  • GitHub Check: PSScriptAnalyzer
🔇 Additional comments (9)
source/Public/Set-SqlDscAgentAlert.ps1 (9)

97-105: Good: Strong numeric typing and validation

Using [int] with ValidateRange aligns with SMO and prevents accidental string binding. The documented ranges match the attributes. LGTM.


123-126: Correct Force/Confirm interplay

The pattern if ($Force.IsPresent -and -not $Confirm) { $ConfirmPreference = 'None' } matches our learned guidance and preserves explicit -Confirm intent. Nice.


131-146: Good: Explicit $null comparison and localized not-found error

Explicit null comparison complies with our guidelines; using New-ObjectNotFoundException keeps error handling consistent. LGTM.


192-206: LGTM: Update persistence and PassThru behavior

Only calling Alter() when $hasChanges is true and returning the object on -PassThru matches our conventions.


207-211: LGTM: Localized error rethrow with original record

Catching and converting to New-InvalidOperationException with -ErrorRecord preserves context while keeping user-facing messages localized.


37-45: INPUTS section is now present and correctly documents pipeline types

The two input types are listed separately with short descriptions, matching our help standards. Nice.


46-51: OUTPUTS section follows the required structure

Return types are listed separately with concise descriptions; explicit None is included. Good.


80-118: Public command surface meets repository standards

  • Command name follows Verb-SqlDscNoun.
  • [CmdletBinding(SupportsShouldProcess = $true)], empty parameter sets avoided, all parameters have [Parameter()].
  • Types are fully qualified.

120-214: Add missing localization entries for Set-SqlDscAgentAlert

The verification script shows that two of the proposed new localized string keys are not present in source/en-US/SqlServerDsc.strings.psd1, while all existing Set_SqlDscAgentAlert_* keys are accounted for. The private helper and SMO stubs are already in place.

• In source/en-US/SqlServerDsc.strings.psd1, add entries for:

  • Set_SqlDscAgentAlert_NoPropertiesSpecified
  • Set_SqlDscAgentAlert_BothCriteriaZero
    • Private helper Get-AgentAlertObject is present at source/Private/Get-AgentAlertObject.ps1
    • SMO stubs in tests/Unit/Stubs/SMO.cs define Alert and JobServer classes (with InstanceName and Parent properties) to support the calls in Set-SqlDscAgentAlert
⛔ Skipped due to learnings
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/en-US/SqlServerDsc.strings.psd1 : All localized strings for public commands and private functions must be added to source/en-US/SqlServerDsc.strings.psd1 following existing key patterns
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Private/*.ps1 : Private functions must localize Write-Debug/Verbose/Error/Warning and other messages using keys from source/en-US/SqlServerDsc.strings.psd1; keys prefixed with function name using underscores; data available as $script:localizedData
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Public/*.ps1 : Public commands must localize Write-Debug/Verbose/Error/Warning and other messages using keys from source/en-US/SqlServerDsc.strings.psd1; keys prefixed with function name using underscores; data available as $script:localizedData
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/suffix.ps1:24-24
Timestamp: 2025-08-17T10:48:15.384Z
Learning: In source/suffix.ps1, the Write-Verbose message in the catch block for Import-SqlDscPreferredModule does not need localization because the exception message from Import-SqlDscPreferredModule is already localized by that command, making it an edge case exception to the localization guidelines.
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Use localized strings in tests only when necessary, retrieving values from $script:localizedData inside InModuleScope

… New-SqlDscAgentAlert, and Test-SqlDscAgentAlert to streamline code and improve readability.
@johlju
Copy link
Member Author

johlju commented Aug 24, 2025

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Aug 24, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

♻️ Duplicate comments (7)
.github/instructions/dsc-community-style-guidelines-pester.instructions.md (4)

15-15: Hyphenate attributive compound “parameter-binding”.

Use the hyphenated form when used adjectivally.
[ suggest_nitpick ]

- - Never test verbose messages, debug messages or parameter binding behavior
+ - Never test verbose messages, debug messages or parameter‑binding behavior

29-29: Clarify rule: forbid starting It descriptions with “When”, not any occurrence of “when”.

Be precise; the prohibition targets the prefix, not the token anywhere in the sentence.
[ suggest_nitpick ]

- - `It` descriptions start with 'Should', must not contain 'when'
+ - `It` descriptions must start with 'Should' and must not start with 'When'

33-36: Make mocking bullets imperative, parallel, and consistently punctuated.

Improves readability and aligns with house style used elsewhere.
[ suggest_nitpick ]

- - Never add an empty `-MockWith` block
- - Omit `-MockWith` when returning `$null`
- - Set `$PSDefaultParameterValues` for `Mock:ModuleName`, `Should:ModuleName`, `InModuleScope:ModuleName`
- - Omit `-ModuleName` parameter on Pester commands
+ - Do not add an empty `-MockWith` block.
+ - Omit `-MockWith` when the mock returns `$null`.
+ - Set `$PSDefaultParameterValues` for `Mock:ModuleName`, `Should:ModuleName`, and `InModuleScope:ModuleName`.
+ - Do not pass the `-ModuleName` parameter on Pester commands.

49-49: Add blank lines around the list item to satisfy markdownlint MD032.

Surround the list with blank lines.
[ suggest_nitpick ]

 ## Best Practices
- - Inside `It` blocks, assign unused return objects to `$null` (unless part of pipeline)
+ 
+ - Inside `It` blocks, assign unused return objects to `$null` (unless part of pipeline)
+ 
tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1 (2)

49-58: Fix missing pre-test cleanup (alerts may already exist, causing New-SqlDscAgentAlert to throw).

You declare $testAlerts but never use it; if prior runs left alerts behind, the two New-SqlDscAgentAlert calls will fail. Clean the slate using SMO, not the module’s commands, per test guidelines.

Apply:

-        # Clean up any test alerts that might exist from previous runs
-        $testAlerts = @(
+        # Clean up any test alerts that might exist from previous runs
+        $script:testAlerts = @(
             'IntegrationTest_SeverityAlert',
             'IntegrationTest_MessageIdAlert'
-        )
+        )
+
+        # Use SMO for cleanup (avoid calling commands under test in setup)
+        foreach ($alertName in $script:testAlerts)
+        {
+            try
+            {
+                $existingAlert = $script:sqlServerObject.JobServer.Alerts[$alertName]
+                if ($null -ne $existingAlert)
+                {
+                    $existingAlert.Drop()
+                }
+            }
+            catch
+            {
+                # Alert doesn't exist, ignore
+            }
+        }

60-67: Use SMO in teardown; avoid invoking module commands in cleanup.

Replace Remove-SqlDscAgentAlert with SMO .Drop() to keep teardown independent of module behavior, as recommended earlier.

Apply:

-        # Clean up test alerts
-        $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_SeverityAlert' -Force -ErrorAction 'SilentlyContinue'
-        $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_MessageIdAlert' -Force -ErrorAction 'SilentlyContinue'
+        # Clean up test alerts via SMO
+        foreach ($alertName in $script:testAlerts)
+        {
+            try
+            {
+                $existingAlert = $script:sqlServerObject.JobServer.Alerts[$alertName]
+                if ($null -ne $existingAlert)
+                {
+                    $existingAlert.Drop()
+                }
+            }
+            catch { }
+        }
tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 (1)

54-60: Use SMO for teardown instead of module commands.

Keep cleanup independent of public commands to avoid masking failures and cross-command coupling in integration tests.

Apply:

-        $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_GetAlert1' -Force -ErrorAction 'SilentlyContinue'
-        $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_GetAlert2' -Force -ErrorAction 'SilentlyContinue'
+        foreach ($alertName in @('IntegrationTest_GetAlert1','IntegrationTest_GetAlert2'))
+        {
+            try
+            {
+                $existingAlert = $script:sqlServerObject.JobServer.Alerts[$alertName]
+                if ($null -ne $existingAlert)
+                {
+                    $existingAlert.Drop()
+                }
+            }
+            catch { }
+        }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

💡 Knowledge Base configuration:

  • Jira integration is disabled
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d5e3f5f and 3582c0d.

📒 Files selected for processing (4)
  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md (3 hunks)
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 (1 hunks)
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 (1 hunks)
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1 (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**

⚙️ CodeRabbit configuration file

**: # DSC Community Guidelines

Terminology

  • Command: Public command
  • Function: Private function
  • Resource: DSC class-based resource

Build & Test Workflow

  • Run project scripts in PowerShell from repository root
  • Build after source changes: .\build.ps1 -Tasks build
  • Test workflow: Build → Invoke-Pester -Path @('<test paths>') -Output Detailed
  • New session required after class changes

File Organization

  • Public commands: source/Public/{CommandName}.ps1
  • Private functions: source/Private/{FunctionName}.ps1
  • Unit tests: tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1
  • Integration tests: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Requirements

  • Always update CHANGELOG.md Unreleased section
  • Localize all strings using string keys
  • Check DscResource.Common before creating private functions
  • Separate reusable logic into private functions
  • Add unit tests for all commands/functions/resources
  • Add integration tests for all public commands and resources

Files:

  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
**/*.ps?(m|d)1

⚙️ CodeRabbit configuration file

**/*.ps?(m|d)1: # PowerShell Guidelines

Naming

  • Use descriptive names (3+ characters, no abbreviations)
  • Functions: PascalCase with Verb-Noun format using approved verbs
  • Parameters: PascalCase
  • Variables: camelCase
  • Keywords: lower-case
  • Classes: PascalCase
  • Include scope for script/global/environment variables: $script:, $global:, $env:

Formatting

Indentation & Spacing

  • Use 4 spaces (no tabs)
  • One space around operators: $a = 1 + 2
  • One space between type and variable: [String] $name
  • One space between keyword and parenthesis: if ($condition)
  • No spaces on empty lines
  • Try to limit lines to 120 characters

Braces

  • Newline before opening brace (except variable assignments)
  • One newline after opening brace
  • Two newlines after closing brace (one if followed by another brace or continuation)

Quotes

  • Use single quotes unless variable expansion is needed: 'text' vs "text $variable"

Arrays

  • Single line: @('one', 'two', 'three')
  • Multi-line: each element on separate line with proper indentation
  • Do not use the unary comma operator (,) in return statements to force
    an array

Hashtables

  • Empty: @{}
  • Multi-line: each property on separate line with proper indentation
  • Properties: Use PascalCase

Comments

  • Single line: # Comment (capitalized, on own line)
  • Multi-line: <# Comment #> format (opening and closing brackets on own line), and indent text
  • No commented-out code

Comment-based help

  • Always add comment-based help to all functions and scripts
  • Comment-based help: SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, EXAMPLE sections before function/class
  • Comment-based help indentation: keywords 4 spaces, text 8 spaces
  • Include examples for all parameter sets and combinations
  • INPUTS: List each pipeline‑accepted type (one per line) with a 1‑line description.
  • OUTPUTS: List each return type (one per line) with a 1‑line description. Must match both [OutputType()] and actual ...

Files:

  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
**/*.[Tt]ests.ps1

⚙️ CodeRabbit configuration file

**/*.[Tt]ests.ps1: # Tests Guidelines

Core Requirements

  • All public commands, private functions and classes must have unit tests
  • All public commands and class-based resources must have integration tests
  • Use Pester v5 syntax only
  • One Describe block per file matching the tested entity name
  • Test code only inside Describe blocks
  • Assertions only in It blocks
  • Never test Write-Verbose, Write-Debug, or parameter binding behavior
  • Pass all mandatory parameters to avoid prompts

Structure & Scope

  • Public commands: Never use InModuleScope (unless retrieving localized strings)
  • Private functions/class resources: Always use InModuleScope
  • Each scenario = separate Context block
  • Use nested Context blocks for complex scenarios
  • Mocking in BeforeAll (BeforeEach only when required)
  • Setup/teardown in BeforeAll,BeforeEach/AfterAll,AfterEach close to usage

Syntax Rules

  • PascalCase: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
  • It descriptions start with 'Should'
  • Context descriptions start with 'When'
  • Mock variables prefix: 'mock'
  • Prefer -BeTrue/-BeFalse over -Be $true/-Be $false
  • No Should -Not -Throw - invoke commands directly

File Organization

  • Class resources: tests/Unit/Classes/{Name}.Tests.ps1
  • Public commands: tests/Unit/Public/{Name}.Tests.ps1
  • Private functions: tests/Unit/Private/{Name}.Tests.ps1

Data-Driven Tests

  • Define variables in separate BeforeDiscovery for -ForEach (close to usage)
  • -ForEach allowed on Context and It blocks
  • Keep scope close to usage context

Best Practices

  • Assign unused return objects to $null
  • Tested entity must be called from within the It blocks
  • Keep results and assertions in same It block
  • Cover all scenarios and code paths
  • Use BeforeEach and AfterEach sparingly
  • Avoid try-catch-finally for cleanup, use AfterAll or AfterEach
  • Avoid unnecessary remove/recreate cyc...

Files:

  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1

⚙️ CodeRabbit configuration file

tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1: # Integration Tests Guidelines

Requirements

  • Location Commands: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1
  • Location Resources: tests/Integration/Resources/{ResourceName}.Integration.Tests.ps1
  • No mocking - real environment only
  • Cover all scenarios and code paths
  • Use Get-ComputerName for computer names in CI
  • Avoid ExpectedMessage for Should -Throw assertions
  • Only run integration tests in CI unless explicitly instructed.
  • Call commands with -Force parameter where applicable (avoids prompting).

Required Setup Block

[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
param ()

BeforeDiscovery {
    try
    {
        if (-not (Get-Module -Name 'DscResource.Test'))
        {
            # Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
            if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
            {
                # Redirect all streams to $null, except the error stream (stream 2)
                & "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
            }

            # If the dependencies have not been resolved, this will throw an error.
            Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
        }
    }
    catch [System.IO.FileNotFoundException]
    {
        throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.'
    }
}

BeforeAll {
    $script:dscModuleName = 'SqlServerDsc'

    Import-Module -Name $script:dscModuleName -Force -ErrorAction 'Stop'
}

Files:

  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
🧠 Learnings (17)
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Integration tests must exist for all public commands, not mock any commands, be placed at tests/Integration/Commands, and be named <Command>.Integration.Tests.ps1

Applied to files:

  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to azure-pipelines.yml : Add each public command integration test script to a group within the Integration_Test_Commands_SqlServer stage in ./azure-pipelines.yml, choosing the appropriate group

Applied to files:

  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Include the standard integration test setup block (BeforeDiscovery/BeforeAll with module loading) before the first Describe block

Applied to files:

  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : In CI, integration tests must use Get-ComputerName when the computer name is needed

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Use BeforeAll/BeforeEach/AfterAll/AfterEach inside Context, placed near the It blocks using them; duplication across contexts is acceptable; AfterAll can clean up; use BeforeEach/AfterEach sparingly

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Each scenario/path should be in Context blocks starting with 'When'; It block descriptions should start with 'Should' and must call the subject; results and assertions stay within the same It; BeforeAll/BeforeEach must not call the subject

Applied to files:

  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Test code must not exist outside of a Describe block

Applied to files:

  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Unit/**/*.Tests.ps1 : Do not use Should -Not -Throw; invoke the command directly

Applied to files:

  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T10:48:15.384Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/suffix.ps1:24-24
Timestamp: 2025-08-17T10:48:15.384Z
Learning: In source/suffix.ps1, the Write-Verbose message in the catch block for Import-SqlDscPreferredModule does not need localization because the exception message from Import-SqlDscPreferredModule is already localized by that command, making it an edge case exception to the localization guidelines.

Applied to files:

  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : All tests must use Pester and Pester v5.0 syntax

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T10:15:48.194Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: tests/Unit/Public/Remove-SqlDscLogin.Tests.ps1:36-39
Timestamp: 2025-08-17T10:15:48.194Z
Learning: Public command unit tests guideline: Never use InModuleScope unless accessing localized strings from $script:localizedData. PSDefaultParameterValues for InModuleScope should be kept in public command tests to support localized string retrieval when necessary.

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Unit/**/*.Tests.ps1 : Never test, mock, or use Should -Invoke for Write-Verbose or Write-Debug in unit tests

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Each test file must contain exactly one Describe block named after the subject (public command, private function, or resource)

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Unit/**/*.Tests.ps1 : Include the standard unit test setup block (BeforeDiscovery/BeforeAll/AfterAll with module loading and PSDefaultParameterValues) before the Describe block

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Unit/Private/*.Tests.ps1 : Unit tests for private functions must be placed in tests/Unit/Private and named <Function>.Tests.ps1

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Files that need to be mocked in tests must be created in Pester's $TestDrive

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Unit/Classes/*.Tests.ps1 : Unit tests for class-based resources must be placed in tests/Unit/Classes and named <Resource>.Tests.ps1

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-pester.instructions.md
🪛 LanguageTool
.github/instructions/dsc-community-style-guidelines-pester.instructions.md

[grammar] ~15-~15: There might be a mistake here.
Context: ...ks - Never test verbose messages, debug messages or parameter binding behavior - Pass al...

(QB_NEW_EN_OTHER)


[grammar] ~15-~15: There might be a mistake here.
Context: ...g messages or parameter binding behavior - Pass all mandatory parameters to avoid p...

(QB_NEW_EN_OTHER)


[grammar] ~29-~29: There might be a mistake here.
Context: ... - It descriptions start with 'Should', must not contain 'when' - Mock variable...

(QB_NEW_EN_OTHER)


[grammar] ~29-~29: There might be a mistake here.
Context: ...s start with 'Should', must not contain 'when' - Mock variables prefix: 'mock' - Prefer `...

(QB_NEW_EN_OTHER)


[grammar] ~30-~30: There might be a mistake here.
Context: ...n 'when' - Mock variables prefix: 'mock' - Prefer -BeTrue/-BeFalse over `-Be $t...

(QB_NEW_EN)


[grammar] ~31-~31: There might be a mistake here.
Context: ...r -BeTrue/-BeFalse over -Be $true/-Be $false - No Should -Not -Throw - invoke command...

(QB_NEW_EN)


[typographical] ~32-~32: To join two clauses or set off examples, consider using an em dash.
Context: ...lseover-Be $true/-Be $false- NoShould -Not -Throw` - invoke commands directly - Never add an empty ...

(QB_NEW_EN_DASH_RULE_EM)


[grammar] ~32-~32: There might be a mistake here.
Context: ... -Not -Throw- invoke commands directly - Never add an empty-MockWith` block - O...

(QB_NEW_EN_OTHER)


[grammar] ~33-~33: There might be a mistake here.
Context: ...y - Never add an empty -MockWith block - Omit -MockWith when returning $null ...

(QB_NEW_EN_OTHER)


[grammar] ~34-~34: There might be a mistake here.
Context: ... block - Omit -MockWith when returning $null - Set $PSDefaultParameterValues for `Moc...

(QB_NEW_EN_OTHER)


[grammar] ~35-~35: There might be a mistake here.
Context: ...Mock:ModuleName, Should:ModuleName, InModuleScope:ModuleName - Omit -ModuleName parameter on Pester c...

(QB_NEW_EN)


[grammar] ~36-~36: There might be a mistake here.
Context: ...ModuleNameparameter on Pester commands ## File Organization - Class resources:te...

(QB_NEW_EN_OTHER)


[grammar] ~49-~49: There might be a mistake here.
Context: ... return objects to $null (unless part of pipeline) - Tested entity must be calle...

(QB_NEW_EN)

🪛 markdownlint-cli2 (0.17.2)
.github/instructions/dsc-community-style-guidelines-pester.instructions.md

49-49: Lists should be surrounded by blank lines

(MD032, blanks-around-lists)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: dsccommunity.SqlServerDsc (Integration Test Commands - SQL Server Commands SQL2022_WIN2025)
  • GitHub Check: dsccommunity.SqlServerDsc (Integration Test Commands - SQL Server Commands SQL2022_WIN2022)
  • GitHub Check: dsccommunity.SqlServerDsc (Integration Test Commands - SQL Server Commands SQL2019_WIN2025)
  • GitHub Check: dsccommunity.SqlServerDsc (Integration Test Commands - SQL Server Commands SQL2019_WIN2022)
  • GitHub Check: dsccommunity.SqlServerDsc (Integration Test Commands - SQL Server Commands SQL2017_WIN2022)
  • GitHub Check: dsccommunity.SqlServerDsc (Quality Test and Unit Test Publish Code Coverage)
  • GitHub Check: dsccommunity.SqlServerDsc (Quality Test and Unit Test HQRM)
  • GitHub Check: dsccommunity.SqlServerDsc (Quality Test and Unit Test Determine DSC Resource Test Requirements)
  • GitHub Check: dsccommunity.SqlServerDsc (Quality Test and Unit Test Unit)
  • GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
🔇 Additional comments (4)
tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1 (2)

69-116: Solid scenario coverage and structure.

Contexts are well-formed; numeric parameters passed as integers; avoided brittle -ExpectedMessage. Nice alignment with the repo’s test style.


44-47: CI Integration Test Entry Verified

The azure-pipelines.yml already references tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1 (line 307), so this integration test will be picked up in CI.

tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 (2)

1-43: Harness looks correct.

Standard integration test setup is present (BeforeDiscovery guard, module import, CI env var, module unload).


62-67: Fix type assertion for collections.

Get-SqlDscAgentAlert returns a collection; asserting the array to be of [Alert] type will fail. Assert each element’s type.

Apply:

-        $alerts | Should -BeOfType [Microsoft.SqlServer.Management.Smo.Agent.Alert]
+        $alerts | Should -All -BeOfType ([Microsoft.SqlServer.Management.Smo.Agent.Alert])
⛔ Skipped due to learnings
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2134
File: tests/Unit/Public/Get-SqlDscLogin.Tests.ps1:178-185
Timestamp: 2025-08-15T05:37:29.255Z
Learning: In PowerShell Pester tests, when piping an array to `Should -BeOfType`, PowerShell's pipeline automatically unrolls the array and checks the type of each individual element, not the array type itself. This means `$result | Should -BeOfType 'SomeType'` for an array will validate every element's type without needing the `-All` modifier.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 11

♻️ Duplicate comments (5)
tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1 (1)

59-66: Optional: avoid coupling teardown to module commands; use SMO Drop() instead.

Teardown calls another public command (Remove-SqlDscAgentAlert). Prefer SMO cleanup to isolate this suite from other command behavior.

-        # Clean up test alerts
-        $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_SeverityAlert' -Force -ErrorAction 'SilentlyContinue'
-        $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_MessageIdAlert' -Force -ErrorAction 'SilentlyContinue'
+        # Clean up test alerts without invoking module commands
+        foreach ($name in @('IntegrationTest_SeverityAlert', 'IntegrationTest_MessageIdAlert'))
+        {
+            try { $script:sqlServerObject.JobServer.Alerts[$name].Drop() } catch { }
+        }
tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 (1)

59-65: Optional: prefer SMO-based cleanup in teardown.

Teardown currently depends on Remove-SqlDscAgentAlert. Using SMO decouples these tests from other command behavior.

-        $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_GetAlert1' -Force -ErrorAction 'SilentlyContinue'
-        $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_GetAlert2' -Force -ErrorAction 'SilentlyContinue'
+        foreach ($name in @('IntegrationTest_GetAlert1', 'IntegrationTest_GetAlert2'))
+        {
+            try { $script:sqlServerObject.JobServer.Alerts[$name].Drop() } catch { }
+        }
tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 (3)

75-82: Restructure: wrap scenarios in Context 'When …' blocks per repo test guidelines.

Each scenario must live inside a Context starting with ‘When’. Group the five It-blocks accordingly; keep subject calls within It bodies.

-    It 'Should create alert with severity' {
+    Context 'When creating with severity' {
+        It 'Should create alert with severity' {
             $null = $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_SeverityAlert' -Severity 14 -ErrorAction Stop
-
-        $alert = $script:sqlServerObject | Get-SqlDscAgentAlert -Name 'IntegrationTest_SeverityAlert'
-        $alert | Should -Not -BeNullOrEmpty
-        $alert.Name | Should -Be 'IntegrationTest_SeverityAlert'
-        $alert.Severity | Should -Be 14
-    }
+            $alert = $script:sqlServerObject | Get-SqlDscAgentAlert -Name 'IntegrationTest_SeverityAlert'
+            $alert | Should -Not -BeNullOrEmpty
+            $alert.Name | Should -Be 'IntegrationTest_SeverityAlert'
+            $alert.Severity | Should -Be 14
+        }
+    }
 
-    It 'Should create alert with message ID' {
+    Context 'When creating with message ID' {
+        It 'Should create alert with message ID' {
             $null = $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_MessageIdAlert' -MessageId 50002 -ErrorAction Stop
-
-        $alert = $script:sqlServerObject | Get-SqlDscAgentAlert -Name 'IntegrationTest_MessageIdAlert'
-        $alert | Should -Not -BeNullOrEmpty
-        $alert.Name | Should -Be 'IntegrationTest_MessageIdAlert'
-        $alert.MessageId | Should -Be 50002
-    }
+            $alert = $script:sqlServerObject | Get-SqlDscAgentAlert -Name 'IntegrationTest_MessageIdAlert'
+            $alert | Should -Not -BeNullOrEmpty
+            $alert.Name | Should -Be 'IntegrationTest_MessageIdAlert'
+            $alert.MessageId | Should -Be 50002
+        }
+    }
 
-    It 'Should return alert object when PassThru is specified' {
+    Context 'When using PassThru' {
+        It 'Should return alert object when PassThru is specified' {
             $result = $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_PassThruAlert' -Severity 16 -PassThru -ErrorAction Stop
-
-        $result | Should -Not -BeNullOrEmpty
-        $result.Name | Should -Be 'IntegrationTest_PassThruAlert'
-        $result.Severity | Should -Be 16
-    }
+            $result | Should -Not -BeNullOrEmpty
+            $result.Name | Should -Be 'IntegrationTest_PassThruAlert'
+            $result.Severity | Should -Be 16
+        }
+    }
 
-    It 'Should throw error when alert already exists' {
-        # First create the alert
-        $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_DuplicateAlert' -Severity 16 -ErrorAction Stop
-
-        # Try to create it again - should throw
-        { $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_DuplicateAlert' -Severity 14 } |
-            Should -Throw
-    }
+    Context 'When creating a duplicate' {
+        It 'Should throw error when alert already exists' {
+            # First create the alert
+            $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_DuplicateAlert' -Severity 16 -ErrorAction Stop
+            # Try to create it again - should throw
+            { $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_DuplicateAlert' -Severity 14 } | Should -Throw
+        }
+    }
 
-    It 'Should throw error when both Severity and MessageId are specified' {
-        { $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_InvalidAlert' -Severity 16 -MessageId 50001 } |
-            Should -Throw
-    }
+    Context 'When both Severity and MessageId are specified' {
+        It 'Should throw error when both Severity and MessageId are specified' {
+            { $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_InvalidAlert' -Severity 16 -MessageId 50001 } | Should -Throw
+        }
+    }

Also applies to: 84-91, 93-99, 101-108, 110-113


96-98: Add a type assertion for PassThru result.

Validate the returned object type to tighten the contract.

         $result | Should -Not -BeNullOrEmpty
+        $result | Should -BeOfType ([Microsoft.SqlServer.Management.Smo.Agent.Alert])
         $result.Name | Should -Be 'IntegrationTest_PassThruAlert'
         $result.Severity | Should -Be 16

65-69: Optional: prefer SMO for cleanup (teardown decoupling).

Teardown uses Remove-SqlDscAgentAlert. Consider SMO .Drop() to avoid depending on other commands.

-        foreach ($alertName in $testAlerts)
-        {
-            $null = $script:sqlServerObject |
-                Remove-SqlDscAgentAlert -Name $alertName -Force -ErrorAction 'SilentlyContinue'
-        }
+        foreach ($alertName in $testAlerts)
+        {
+            try { $script:sqlServerObject.JobServer.Alerts[$alertName].Drop() } catch { }
+        }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

💡 Knowledge Base configuration:

  • Jira integration is disabled
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3582c0d and a694dca.

📒 Files selected for processing (5)
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 (1 hunks)
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 (1 hunks)
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 (1 hunks)
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 (1 hunks)
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1 (1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
tests/**/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

tests/**/*.ps1: All tests must use Pester and Pester v5.0 syntax
Do not test parameter validation
Test code must not exist outside of a Describe block
Each test file must contain exactly one Describe block named after the subject (public command, private function, or resource)
Each scenario/path should be in Context blocks starting with 'When'; It block descriptions should start with 'Should' and must call the subject; results and assertions stay within the same It; BeforeAll/BeforeEach must not call the subject
Use BeforeAll/BeforeEach/AfterAll/AfterEach inside Context, placed near the It blocks using them; duplication across contexts is acceptable; AfterAll can clean up; use BeforeEach/AfterEach sparingly
Use localized strings in tests only when necessary, retrieving values from $script:localizedData inside InModuleScope
Files that need to be mocked in tests must be created in Pester's $TestDrive

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
tests/Integration/Commands/*.Integration.Tests.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

tests/Integration/Commands/*.Integration.Tests.ps1: Integration tests must exist for all public commands, not mock any commands, be placed at tests/Integration/Commands, and be named .Integration.Tests.ps1
In CI, integration tests must use Get-ComputerName when the computer name is needed
Include the standard integration test setup block (BeforeDiscovery/BeforeAll with module loading) before the first Describe block

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
**/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.ps1: PowerShell files must be UTF-8 without BOM and end with a newline
Try to limit lines to 120 characters
Use 4 spaces for indentation; never use tabs
Use '#' for single-line comments
Use <# ... #> for multiline comments; indent the multiline text 4 spaces
Use descriptive, clear, full names for variables, parameters, and function names; names must be more than 2 characters; no abbreviations
Use camelCase for local variable names
Never use Write-Host
Never use backtick (`) for line continuation
Use splatting to reduce line length
PowerShell reserved keywords should be lowercase
Use single quotes for string literals whenever possible; use double quotes only when interpolation is needed
Hashtable properties should be PascalCase and each on a separate line
When comparing to $null, place $null on the left side of the comparison

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
**

⚙️ CodeRabbit configuration file

**: # DSC Community Guidelines

Terminology

  • Command: Public command
  • Function: Private function
  • Resource: DSC class-based resource

Build & Test Workflow

  • Run project scripts in PowerShell from repository root
  • Build after source changes: .\build.ps1 -Tasks build
  • Test workflow: Build → Invoke-Pester -Path @('<test paths>') -Output Detailed
  • New session required after class changes

File Organization

  • Public commands: source/Public/{CommandName}.ps1
  • Private functions: source/Private/{FunctionName}.ps1
  • Unit tests: tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1
  • Integration tests: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Requirements

  • Always update CHANGELOG.md Unreleased section
  • Localize all strings using string keys
  • Check DscResource.Common before creating private functions
  • Separate reusable logic into private functions
  • Add unit tests for all commands/functions/resources
  • Add integration tests for all public commands and resources

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
**/*.ps?(m|d)1

⚙️ CodeRabbit configuration file

**/*.ps?(m|d)1: # PowerShell Guidelines

Naming

  • Use descriptive names (3+ characters, no abbreviations)
  • Functions: PascalCase with Verb-Noun format using approved verbs
  • Parameters: PascalCase
  • Variables: camelCase
  • Keywords: lower-case
  • Classes: PascalCase
  • Include scope for script/global/environment variables: $script:, $global:, $env:

Formatting

Indentation & Spacing

  • Use 4 spaces (no tabs)
  • One space around operators: $a = 1 + 2
  • One space between type and variable: [String] $name
  • One space between keyword and parenthesis: if ($condition)
  • No spaces on empty lines
  • Try to limit lines to 120 characters

Braces

  • Newline before opening brace (except variable assignments)
  • One newline after opening brace
  • Two newlines after closing brace (one if followed by another brace or continuation)

Quotes

  • Use single quotes unless variable expansion is needed: 'text' vs "text $variable"

Arrays

  • Single line: @('one', 'two', 'three')
  • Multi-line: each element on separate line with proper indentation
  • Do not use the unary comma operator (,) in return statements to force
    an array

Hashtables

  • Empty: @{}
  • Multi-line: each property on separate line with proper indentation
  • Properties: Use PascalCase

Comments

  • Single line: # Comment (capitalized, on own line)
  • Multi-line: <# Comment #> format (opening and closing brackets on own line), and indent text
  • No commented-out code

Comment-based help

  • Always add comment-based help to all functions and scripts
  • Comment-based help: SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, EXAMPLE sections before function/class
  • Comment-based help indentation: keywords 4 spaces, text 8 spaces
  • Include examples for all parameter sets and combinations
  • INPUTS: List each pipeline‑accepted type (one per line) with a 1‑line description.
  • OUTPUTS: List each return type (one per line) with a 1‑line description. Must match both [OutputType()] and actual ...

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
**/*.[Tt]ests.ps1

⚙️ CodeRabbit configuration file

**/*.[Tt]ests.ps1: # Tests Guidelines

Core Requirements

  • All public commands, private functions and classes must have unit tests
  • All public commands and class-based resources must have integration tests
  • Use Pester v5 syntax only
  • One Describe block per file matching the tested entity name
  • Test code only inside Describe blocks
  • Assertions only in It blocks
  • Never test Write-Verbose, Write-Debug, or parameter binding behavior
  • Pass all mandatory parameters to avoid prompts

Structure & Scope

  • Public commands: Never use InModuleScope (unless retrieving localized strings)
  • Private functions/class resources: Always use InModuleScope
  • Each scenario = separate Context block
  • Use nested Context blocks for complex scenarios
  • Mocking in BeforeAll (BeforeEach only when required)
  • Setup/teardown in BeforeAll,BeforeEach/AfterAll,AfterEach close to usage

Syntax Rules

  • PascalCase: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
  • It descriptions start with 'Should'
  • Context descriptions start with 'When'
  • Mock variables prefix: 'mock'
  • Prefer -BeTrue/-BeFalse over -Be $true/-Be $false
  • No Should -Not -Throw - invoke commands directly

File Organization

  • Class resources: tests/Unit/Classes/{Name}.Tests.ps1
  • Public commands: tests/Unit/Public/{Name}.Tests.ps1
  • Private functions: tests/Unit/Private/{Name}.Tests.ps1

Data-Driven Tests

  • Define variables in separate BeforeDiscovery for -ForEach (close to usage)
  • -ForEach allowed on Context and It blocks
  • Keep scope close to usage context

Best Practices

  • Assign unused return objects to $null
  • Tested entity must be called from within the It blocks
  • Keep results and assertions in same It block
  • Cover all scenarios and code paths
  • Use BeforeEach and AfterEach sparingly
  • Avoid try-catch-finally for cleanup, use AfterAll or AfterEach
  • Avoid unnecessary remove/recreate cyc...

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1

⚙️ CodeRabbit configuration file

tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1: # Integration Tests Guidelines

Requirements

  • Location Commands: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1
  • Location Resources: tests/Integration/Resources/{ResourceName}.Integration.Tests.ps1
  • No mocking - real environment only
  • Cover all scenarios and code paths
  • Use Get-ComputerName for computer names in CI
  • Avoid ExpectedMessage for Should -Throw assertions
  • Only run integration tests in CI unless explicitly instructed.
  • Call commands with -Force parameter where applicable (avoids prompting).

Required Setup Block

[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
param ()

BeforeDiscovery {
    try
    {
        if (-not (Get-Module -Name 'DscResource.Test'))
        {
            # Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
            if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
            {
                # Redirect all streams to $null, except the error stream (stream 2)
                & "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
            }

            # If the dependencies have not been resolved, this will throw an error.
            Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
        }
    }
    catch [System.IO.FileNotFoundException]
    {
        throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.'
    }
}

BeforeAll {
    $script:dscModuleName = 'SqlServerDsc'

    Import-Module -Name $script:dscModuleName -Force -ErrorAction 'Stop'
}

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
🧠 Learnings (12)
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Integration tests must exist for all public commands, not mock any commands, be placed at tests/Integration/Commands, and be named <Command>.Integration.Tests.ps1

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to azure-pipelines.yml : Add each public command integration test script to a group within the Integration_Test_Commands_SqlServer stage in ./azure-pipelines.yml, choosing the appropriate group

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : In CI, integration tests must use Get-ComputerName when the computer name is needed

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Use BeforeAll/BeforeEach/AfterAll/AfterEach inside Context, placed near the It blocks using them; duplication across contexts is acceptable; AfterAll can clean up; use BeforeEach/AfterEach sparingly

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Include the standard integration test setup block (BeforeDiscovery/BeforeAll with module loading) before the first Describe block

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Each scenario/path should be in Context blocks starting with 'When'; It block descriptions should start with 'Should' and must call the subject; results and assertions stay within the same It; BeforeAll/BeforeEach must not call the subject

Applied to files:

  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Test code must not exist outside of a Describe block

Applied to files:

  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Unit/**/*.Tests.ps1 : Do not use Should -Not -Throw; invoke the command directly

Applied to files:

  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T10:48:15.384Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/suffix.ps1:24-24
Timestamp: 2025-08-17T10:48:15.384Z
Learning: In source/suffix.ps1, the Write-Verbose message in the catch block for Import-SqlDscPreferredModule does not need localization because the exception message from Import-SqlDscPreferredModule is already localized by that command, making it an edge case exception to the localization guidelines.

Applied to files:

  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Each test file must contain exactly one Describe block named after the subject (public command, private function, or resource)

Applied to files:

  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T10:15:48.194Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: tests/Unit/Public/Remove-SqlDscLogin.Tests.ps1:36-39
Timestamp: 2025-08-17T10:15:48.194Z
Learning: Public command unit tests guideline: Never use InModuleScope unless accessing localized strings from $script:localizedData. PSDefaultParameterValues for InModuleScope should be kept in public command tests to support localized string retrieval when necessary.

Applied to files:

  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-15T05:37:29.255Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2134
File: tests/Unit/Public/Get-SqlDscLogin.Tests.ps1:178-185
Timestamp: 2025-08-15T05:37:29.255Z
Learning: In PowerShell Pester tests, when piping an array to `Should -BeOfType`, PowerShell's pipeline automatically unrolls the array and checks the type of each individual element, not the array type itself. This means `$result | Should -BeOfType 'SomeType'` for an array will validate every element's type without needing the `-All` modifier.

Applied to files:

  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
  • GitHub Check: PSScriptAnalyzer

johlju added 2 commits August 24, 2025 16:11
…opping the SQL Server service to ensure a clean test environment and save resources.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

♻️ Duplicate comments (11)
.github/instructions/SqlServerDsc-guidelines.instructions.md (1)

36-39: Fix markdownlint issues: add blank line after heading and move long inline code into a fenced block

This resolves MD022/MD032/MD013 and improves readability of the Add-Type example.

-## Unit tests
-- When unit test uses SMO types, ensure they are properly stubbed in SMO.cs
-- Load stub types from SMO.cs in unit test files, e.g. `Add-Type -Path "$PSScriptRoot/../Stubs/SMO.cs"`
-- After changing SMO stub types, run tests in a new PowerShell session for changes to take effect.
+## Unit tests
+
+- When a unit test uses SMO types, ensure they are properly stubbed in `SMO.cs`.
+- Load stub types from `SMO.cs` in unit test files, for example:
+
+```powershell
+Add-Type -Path "$PSScriptRoot/../Stubs/SMO.cs"
+```
+
+- After changing SMO stub types, run tests in a new PowerShell session for changes to take effect.
tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 (1)

49-49: Grammar nit in comment: “throw” → “throws an exception.”

-        $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
+        $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throws an exception.
tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1 (1)

49-49: Grammar nit in comment: “throw” → “throws an exception.”

-        $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
+        $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throws an exception.
tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 (2)

49-49: Grammar nit in comment: “throw” → “throws an exception.”

-        $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIIOS name throw exception.
+        $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throws an exception.

62-71: Use SMO for teardown to avoid invoking other module commands

Prefer SMO .Drop() for removing artifacts in AfterAll so cleanup is independent of the module’s public commands.

-        $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_GetAlert1' -Force -ErrorAction 'SilentlyContinue'
-        $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_GetAlert2' -Force -ErrorAction 'SilentlyContinue'
+        try { $script:sqlServerObject.JobServer.Alerts['IntegrationTest_GetAlert1'].Drop() } catch { }
+        try { $script:sqlServerObject.JobServer.Alerts['IntegrationTest_GetAlert2'].Drop() } catch { }
tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 (2)

49-49: Grammar nit in comment: “throw” → “throws an exception.”

-        $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
+        $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throws an exception.

61-69: Decouple teardown from module commands; prefer SMO Drop()

Avoid depending on Remove-SqlDscAgentAlert for cleanup; use SMO to drop the test alert.

-        $null = $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_UpdateAlert' -Force -ErrorAction 'SilentlyContinue'
+        try { $script:sqlServerObject.JobServer.Alerts['IntegrationTest_UpdateAlert'].Drop() } catch { }
tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 (4)

49-49: Grammar nit in comment.

Use “throws an exception”.

-        $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
+        $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throws an exception.

58-79: Decouple teardown from other cmdlets (optional).

Using Remove-SqlDscAgentAlert in teardown ties this test to another command. Prefer SMO-based cleanup for isolation.

-        foreach ($alertName in $testAlerts)
-        {
-            $null = $script:sqlServerObject |
-                Remove-SqlDscAgentAlert -Name $alertName -Force -ErrorAction 'SilentlyContinue'
-        }
+        foreach ($alertName in $testAlerts)
+        {
+            try
+            {
+                $existingAlert = $script:sqlServerObject.JobServer.Alerts[$alertName]
+                if ($null -ne $existingAlert) { $existingAlert.Drop() }
+            }
+            catch { }
+        }

81-120: Restructure tests into Context 'When ...' blocks per repo guidelines.

Each scenario should live in a Context with setup near usage. The current Describe-level Its work but don’t follow required structure.

-    It 'Should create alert with severity' {
-        $null = $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_SeverityAlert' -Severity 14 -ErrorAction Stop
-
-        $alert = $script:sqlServerObject | Get-SqlDscAgentAlert -Name 'IntegrationTest_SeverityAlert'
-        $alert | Should -Not -BeNullOrEmpty
-        $alert.Name | Should -Be 'IntegrationTest_SeverityAlert'
-        $alert.Severity | Should -Be 14
-    }
+    Context 'When creating with severity' {
+        BeforeEach {
+            $null = $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_SeverityAlert' -Force -ErrorAction 'SilentlyContinue'
+        }
+        It 'Should create alert with severity' {
+            $null = $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_SeverityAlert' -Severity 14 -ErrorAction Stop
+            $alert = $script:sqlServerObject | Get-SqlDscAgentAlert -Name 'IntegrationTest_SeverityAlert'
+            $alert | Should -Not -BeNullOrEmpty
+            $alert.Name | Should -Be 'IntegrationTest_SeverityAlert'
+            $alert.Severity | Should -Be 14
+        }
+    }
 
-    It 'Should create alert with message ID' {
-        $null = $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_MessageIdAlert' -MessageId 50002 -ErrorAction Stop
-
-        $alert = $script:sqlServerObject | Get-SqlDscAgentAlert -Name 'IntegrationTest_MessageIdAlert'
-        $alert | Should -Not -BeNullOrEmpty
-        $alert.Name | Should -Be 'IntegrationTest_MessageIdAlert'
-        $alert.MessageId | Should -Be 50002
-    }
+    Context 'When creating with message ID' {
+        BeforeEach {
+            $null = $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_MessageIdAlert' -Force -ErrorAction 'SilentlyContinue'
+        }
+        It 'Should create alert with message ID' {
+            $null = $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_MessageIdAlert' -MessageId 50002 -ErrorAction Stop
+            $alert = $script:sqlServerObject | Get-SqlDscAgentAlert -Name 'IntegrationTest_MessageIdAlert'
+            $alert | Should -Not -BeNullOrEmpty
+            $alert.Name | Should -Be 'IntegrationTest_MessageIdAlert'
+            $alert.MessageId | Should -Be 50002
+        }
+    }
 
-    It 'Should return alert object when PassThru is specified' {
-        $result = $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_PassThruAlert' -Severity 16 -PassThru -ErrorAction Stop
-
-        $result | Should -Not -BeNullOrEmpty
-        $result.Name | Should -Be 'IntegrationTest_PassThruAlert'
-        $result.Severity | Should -Be 16
-    }
+    Context 'When using PassThru' {
+        BeforeEach {
+            $null = $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_PassThruAlert' -Force -ErrorAction 'SilentlyContinue'
+        }
+        It 'Should return alert object when PassThru is specified' {
+            $result = $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_PassThruAlert' -Severity 16 -PassThru -ErrorAction Stop
+            $result | Should -Not -BeNullOrEmpty
+            $result | Should -BeOfType ([Microsoft.SqlServer.Management.Smo.Agent.Alert])
+            $result.Name | Should -Be 'IntegrationTest_PassThruAlert'
+            $result.Severity | Should -Be 16
+        }
+    }
 
-    It 'Should throw error when alert already exists' {
-        # First create the alert
-        $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_DuplicateAlert' -Severity 16 -ErrorAction Stop
-
-        # Try to create it again - should throw
-        { $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_DuplicateAlert' -Severity 14 } |
-            Should -Throw
-    }
+    Context 'When creating a duplicate' {
+        BeforeAll {
+            $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_DuplicateAlert' -Severity 16 -ErrorAction Stop
+        }
+        AfterAll {
+            $null = $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_DuplicateAlert' -Force -ErrorAction 'SilentlyContinue'
+        }
+        It 'Should throw error when alert already exists' {
+            { $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_DuplicateAlert' -Severity 14 } | Should -Throw
+        }
+    }
 
-    It 'Should throw error when both Severity and MessageId are specified' {
-        { $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_InvalidAlert' -Severity 16 -MessageId 50001 } |
-            Should -Throw
-    }
+    Context 'When both Severity and MessageId are specified' {
+        It 'Should throw error when both Severity and MessageId are specified' {
+            { $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_InvalidAlert' -Severity 16 -MessageId 50001 } | Should -Throw
+        }
+    }

99-105: Add a type assertion for PassThru result (small improvement).

Assert the CLR type of the returned object for stronger verification.

         $result | Should -Not -BeNullOrEmpty
+        $result | Should -BeOfType ([Microsoft.SqlServer.Management.Smo.Agent.Alert])
         $result.Name | Should -Be 'IntegrationTest_PassThruAlert'
         $result.Severity | Should -Be 16
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

💡 Knowledge Base configuration:

  • Jira integration is disabled
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a694dca and 8c1efad.

📒 Files selected for processing (6)
  • .github/instructions/SqlServerDsc-guidelines.instructions.md (2 hunks)
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 (1 hunks)
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 (1 hunks)
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 (1 hunks)
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 (1 hunks)
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1 (1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
tests/**/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

tests/**/*.ps1: All tests must use Pester and Pester v5.0 syntax
Do not test parameter validation
Test code must not exist outside of a Describe block
Each test file must contain exactly one Describe block named after the subject (public command, private function, or resource)
Each scenario/path should be in Context blocks starting with 'When'; It block descriptions should start with 'Should' and must call the subject; results and assertions stay within the same It; BeforeAll/BeforeEach must not call the subject
Use BeforeAll/BeforeEach/AfterAll/AfterEach inside Context, placed near the It blocks using them; duplication across contexts is acceptable; AfterAll can clean up; use BeforeEach/AfterEach sparingly
Use localized strings in tests only when necessary, retrieving values from $script:localizedData inside InModuleScope
Files that need to be mocked in tests must be created in Pester's $TestDrive

Files:

  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
tests/Integration/Commands/*.Integration.Tests.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

tests/Integration/Commands/*.Integration.Tests.ps1: Integration tests must exist for all public commands, not mock any commands, be placed at tests/Integration/Commands, and be named .Integration.Tests.ps1
In CI, integration tests must use Get-ComputerName when the computer name is needed
Include the standard integration test setup block (BeforeDiscovery/BeforeAll with module loading) before the first Describe block

Files:

  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
**/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.ps1: PowerShell files must be UTF-8 without BOM and end with a newline
Try to limit lines to 120 characters
Use 4 spaces for indentation; never use tabs
Use '#' for single-line comments
Use <# ... #> for multiline comments; indent the multiline text 4 spaces
Use descriptive, clear, full names for variables, parameters, and function names; names must be more than 2 characters; no abbreviations
Use camelCase for local variable names
Never use Write-Host
Never use backtick (`) for line continuation
Use splatting to reduce line length
PowerShell reserved keywords should be lowercase
Use single quotes for string literals whenever possible; use double quotes only when interpolation is needed
Hashtable properties should be PascalCase and each on a separate line
When comparing to $null, place $null on the left side of the comparison

Files:

  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
**

⚙️ CodeRabbit configuration file

**: # DSC Community Guidelines

Terminology

  • Command: Public command
  • Function: Private function
  • Resource: DSC class-based resource

Build & Test Workflow

  • Run project scripts in PowerShell from repository root
  • Build after source changes: .\build.ps1 -Tasks build
  • Test workflow: Build → Invoke-Pester -Path @('<test paths>') -Output Detailed
  • New session required after class changes

File Organization

  • Public commands: source/Public/{CommandName}.ps1
  • Private functions: source/Private/{FunctionName}.ps1
  • Unit tests: tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1
  • Integration tests: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Requirements

  • Always update CHANGELOG.md Unreleased section
  • Localize all strings using string keys
  • Check DscResource.Common before creating private functions
  • Separate reusable logic into private functions
  • Add unit tests for all commands/functions/resources
  • Add integration tests for all public commands and resources

Files:

  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
**/*.ps?(m|d)1

⚙️ CodeRabbit configuration file

**/*.ps?(m|d)1: # PowerShell Guidelines

Naming

  • Use descriptive names (3+ characters, no abbreviations)
  • Functions: PascalCase with Verb-Noun format using approved verbs
  • Parameters: PascalCase
  • Variables: camelCase
  • Keywords: lower-case
  • Classes: PascalCase
  • Include scope for script/global/environment variables: $script:, $global:, $env:

Formatting

Indentation & Spacing

  • Use 4 spaces (no tabs)
  • One space around operators: $a = 1 + 2
  • One space between type and variable: [String] $name
  • One space between keyword and parenthesis: if ($condition)
  • No spaces on empty lines
  • Try to limit lines to 120 characters

Braces

  • Newline before opening brace (except variable assignments)
  • One newline after opening brace
  • Two newlines after closing brace (one if followed by another brace or continuation)

Quotes

  • Use single quotes unless variable expansion is needed: 'text' vs "text $variable"

Arrays

  • Single line: @('one', 'two', 'three')
  • Multi-line: each element on separate line with proper indentation
  • Do not use the unary comma operator (,) in return statements to force
    an array

Hashtables

  • Empty: @{}
  • Multi-line: each property on separate line with proper indentation
  • Properties: Use PascalCase

Comments

  • Single line: # Comment (capitalized, on own line)
  • Multi-line: <# Comment #> format (opening and closing brackets on own line), and indent text
  • No commented-out code

Comment-based help

  • Always add comment-based help to all functions and scripts
  • Comment-based help: SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, EXAMPLE sections before function/class
  • Comment-based help indentation: keywords 4 spaces, text 8 spaces
  • Include examples for all parameter sets and combinations
  • INPUTS: List each pipeline‑accepted type (one per line) with a 1‑line description.
  • OUTPUTS: List each return type (one per line) with a 1‑line description. Must match both [OutputType()] and actual ...

Files:

  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
**/*.[Tt]ests.ps1

⚙️ CodeRabbit configuration file

**/*.[Tt]ests.ps1: # Tests Guidelines

Core Requirements

  • All public commands, private functions and classes must have unit tests
  • All public commands and class-based resources must have integration tests
  • Use Pester v5 syntax only
  • One Describe block per file matching the tested entity name
  • Test code only inside Describe blocks
  • Assertions only in It blocks
  • Never test Write-Verbose, Write-Debug, or parameter binding behavior
  • Pass all mandatory parameters to avoid prompts

Structure & Scope

  • Public commands: Never use InModuleScope (unless retrieving localized strings)
  • Private functions/class resources: Always use InModuleScope
  • Each scenario = separate Context block
  • Use nested Context blocks for complex scenarios
  • Mocking in BeforeAll (BeforeEach only when required)
  • Setup/teardown in BeforeAll,BeforeEach/AfterAll,AfterEach close to usage

Syntax Rules

  • PascalCase: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
  • It descriptions start with 'Should'
  • Context descriptions start with 'When'
  • Mock variables prefix: 'mock'
  • Prefer -BeTrue/-BeFalse over -Be $true/-Be $false
  • No Should -Not -Throw - invoke commands directly

File Organization

  • Class resources: tests/Unit/Classes/{Name}.Tests.ps1
  • Public commands: tests/Unit/Public/{Name}.Tests.ps1
  • Private functions: tests/Unit/Private/{Name}.Tests.ps1

Data-Driven Tests

  • Define variables in separate BeforeDiscovery for -ForEach (close to usage)
  • -ForEach allowed on Context and It blocks
  • Keep scope close to usage context

Best Practices

  • Assign unused return objects to $null
  • Tested entity must be called from within the It blocks
  • Keep results and assertions in same It block
  • Cover all scenarios and code paths
  • Use BeforeEach and AfterEach sparingly
  • Avoid try-catch-finally for cleanup, use AfterAll or AfterEach
  • Avoid unnecessary remove/recreate cyc...

Files:

  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1

⚙️ CodeRabbit configuration file

tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1: # Integration Tests Guidelines

Requirements

  • Location Commands: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1
  • Location Resources: tests/Integration/Resources/{ResourceName}.Integration.Tests.ps1
  • No mocking - real environment only
  • Cover all scenarios and code paths
  • Use Get-ComputerName for computer names in CI
  • Avoid ExpectedMessage for Should -Throw assertions
  • Only run integration tests in CI unless explicitly instructed.
  • Call commands with -Force parameter where applicable (avoids prompting).

Required Setup Block

[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
param ()

BeforeDiscovery {
    try
    {
        if (-not (Get-Module -Name 'DscResource.Test'))
        {
            # Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
            if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
            {
                # Redirect all streams to $null, except the error stream (stream 2)
                & "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
            }

            # If the dependencies have not been resolved, this will throw an error.
            Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
        }
    }
    catch [System.IO.FileNotFoundException]
    {
        throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.'
    }
}

BeforeAll {
    $script:dscModuleName = 'SqlServerDsc'

    Import-Module -Name $script:dscModuleName -Force -ErrorAction 'Stop'
}

Files:

  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
🧠 Learnings (22)
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Integration tests must exist for all public commands, not mock any commands, be placed at tests/Integration/Commands, and be named <Command>.Integration.Tests.ps1

Applied to files:

  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • .github/instructions/SqlServerDsc-guidelines.instructions.md
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Unit/**/*.Tests.ps1 : Do not use Should -Not -Throw; invoke the command directly

Applied to files:

  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T10:13:30.079Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/Public/Remove-SqlDscLogin.ps1:104-108
Timestamp: 2025-08-17T10:13:30.079Z
Learning: In SqlServerDsc unit tests, SMO object stubs (like Login objects) should have properly mocked Parent properties with correct Server stub types and valid InstanceName values, rather than handling null Parent scenarios in production code.

Applied to files:

  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • .github/instructions/SqlServerDsc-guidelines.instructions.md
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Include the standard integration test setup block (BeforeDiscovery/BeforeAll with module loading) before the first Describe block

Applied to files:

  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • .github/instructions/SqlServerDsc-guidelines.instructions.md
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to azure-pipelines.yml : Add each public command integration test script to a group within the Integration_Test_Commands_SqlServer stage in ./azure-pipelines.yml, choosing the appropriate group

Applied to files:

  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • .github/instructions/SqlServerDsc-guidelines.instructions.md
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : All tests must use Pester and Pester v5.0 syntax

Applied to files:

  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • .github/instructions/SqlServerDsc-guidelines.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Each scenario/path should be in Context blocks starting with 'When'; It block descriptions should start with 'Should' and must call the subject; results and assertions stay within the same It; BeforeAll/BeforeEach must not call the subject

Applied to files:

  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • .github/instructions/SqlServerDsc-guidelines.instructions.md
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Use BeforeAll/BeforeEach/AfterAll/AfterEach inside Context, placed near the It blocks using them; duplication across contexts is acceptable; AfterAll can clean up; use BeforeEach/AfterEach sparingly

Applied to files:

  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • .github/instructions/SqlServerDsc-guidelines.instructions.md
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Test code must not exist outside of a Describe block

Applied to files:

  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T10:48:15.384Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/suffix.ps1:24-24
Timestamp: 2025-08-17T10:48:15.384Z
Learning: In source/suffix.ps1, the Write-Verbose message in the catch block for Import-SqlDscPreferredModule does not need localization because the exception message from Import-SqlDscPreferredModule is already localized by that command, making it an edge case exception to the localization guidelines.

Applied to files:

  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/en-US/SqlServerDsc.strings.psd1 : All localized strings for public commands and private functions must be added to source/en-US/SqlServerDsc.strings.psd1 following existing key patterns

Applied to files:

  • .github/instructions/SqlServerDsc-guidelines.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Public/*-SqlDsc*.ps1 : All public command names must have the noun prefixed with 'SqlDsc' (Verb-SqlDscNoun)

Applied to files:

  • .github/instructions/SqlServerDsc-guidelines.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Classes/*.ps1 : A DSC resource should inherit SqlResourceBase if it needs to connect to a SQL Server Database Engine

Applied to files:

  • .github/instructions/SqlServerDsc-guidelines.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Classes/*.ps1 : A DSC resource should inherit ResourceBase only when it cannot inherit SqlResourceBase or when not related to SQL Server Database Engine

Applied to files:

  • .github/instructions/SqlServerDsc-guidelines.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private}/*.ps1 : Public command and private function names must follow Verb-Noun format and use PowerShell approved verbs

Applied to files:

  • .github/instructions/SqlServerDsc-guidelines.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/{Public,Private,Classes}/*.ps1 : Use PascalCase for function names and parameters in public commands, private functions, and class-based resources

Applied to files:

  • .github/instructions/SqlServerDsc-guidelines.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to source/Public/*.ps1 : Public commands must localize Write-Debug/Verbose/Error/Warning and other messages using keys from source/en-US/SqlServerDsc.strings.psd1; keys prefixed with function name using underscores; data available as $script:localizedData

Applied to files:

  • .github/instructions/SqlServerDsc-guidelines.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Unit/Public/*.Tests.ps1 : Public command unit tests must include tests to validate parameter properties (e.g., Mandatory, ValueFromPipeline)

Applied to files:

  • .github/instructions/SqlServerDsc-guidelines.instructions.md
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : In CI, integration tests must use Get-ComputerName when the computer name is needed

Applied to files:

  • .github/instructions/SqlServerDsc-guidelines.instructions.md
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Each test file must contain exactly one Describe block named after the subject (public command, private function, or resource)

Applied to files:

  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T10:15:48.194Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: tests/Unit/Public/Remove-SqlDscLogin.Tests.ps1:36-39
Timestamp: 2025-08-17T10:15:48.194Z
Learning: Public command unit tests guideline: Never use InModuleScope unless accessing localized strings from $script:localizedData. PSDefaultParameterValues for InModuleScope should be kept in public command tests to support localized string retrieval when necessary.

Applied to files:

  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-15T05:37:29.255Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2134
File: tests/Unit/Public/Get-SqlDscLogin.Tests.ps1:178-185
Timestamp: 2025-08-15T05:37:29.255Z
Learning: In PowerShell Pester tests, when piping an array to `Should -BeOfType`, PowerShell's pipeline automatically unrolls the array and checks the type of each individual element, not the array type itself. This means `$result | Should -BeOfType 'SomeType'` for an array will validate every element's type without needing the `-All` modifier.

Applied to files:

  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
🧬 Code graph analysis (1)
.github/instructions/SqlServerDsc-guidelines.instructions.md (1)
tests/Unit/Stubs/SMO.cs (1)
  • Microsoft (11-1023)
🪛 LanguageTool
.github/instructions/SqlServerDsc-guidelines.instructions.md

[grammar] ~10-~10: Use correct spacing
Context: ...Private function: {Verb}-{Noun} format ## Resources - Database Engine resources: i...

(QB_NEW_EN_OTHER_ERROR_IDS_5)


[grammar] ~30-~30: Make sure to use plural and singular nouns correctly
Context: ...SqlDscDatabaseEngine` for SQL Server DB session, and always with correct CI credentials...

(QB_NEW_EN_OTHER_ERROR_IDS_10)


[grammar] ~30-~30: There might be a mistake here.
Context: ..., and always with correct CI credentials - Use Disconnect-SqlDscDatabaseEngine af...

(QB_NEW_EN_OTHER)


[grammar] ~31-~31: There might be a mistake here.
Context: ... Disconnect-SqlDscDatabaseEngine after Connect-SqlDscDatabaseEngine - Test config: tests/Integration/Commands/...

(QB_NEW_EN_OTHER)


[grammar] ~32-~32: There might be a mistake here.
Context: ...nd tests/Integration/Resources/README.md - Integration test script files must be ad...

(QB_NEW_EN_OTHER)


[grammar] ~33-~33: There might be a mistake here.
Context: ...the test stage in ./azure-pipelines.yml. - Choose the appropriate group number base...

(QB_NEW_EN)


[grammar] ~34-~34: There might be a mistake here.
Context: ...umber based on the required dependencies ## Unit tests - When unit test uses SMO typ...

(QB_NEW_EN_OTHER)


[grammar] ~36-~36: There might be a mistake here.
Context: ...the required dependencies ## Unit tests - When unit test uses SMO types, ensure th...

(QB_NEW_EN)


[grammar] ~37-~37: There might be a mistake here.
Context: ...sure they are properly stubbed in SMO.cs - Load stub types from SMO.cs in unit test...

(QB_NEW_EN_OTHER)


[grammar] ~38-~38: There might be a mistake here.
Context: ...pes from SMO.cs in unit test files, e.g. Add-Type -Path "$PSScriptRoot/../Stubs/SMO.cs" - After changing SMO stub types, run tests...

(QB_NEW_EN_OTHER)


[grammar] ~39-~39: There might be a mistake here.
Context: ...hell session for changes to take effect.

(QB_NEW_EN)

🪛 markdownlint-cli2 (0.17.2)
.github/instructions/SqlServerDsc-guidelines.instructions.md

29-29: Line length
Expected: 80; Actual: 96

(MD013, line-length)


30-30: Line length
Expected: 80; Actual: 104

(MD013, line-length)


33-33: Line length
Expected: 80; Actual: 106

(MD013, line-length)


36-36: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below

(MD022, blanks-around-headings)


37-37: Lists should be surrounded by blank lines

(MD032, blanks-around-lists)


39-39: Line length
Expected: 80; Actual: 98

(MD013, line-length)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
  • GitHub Check: PSScriptAnalyzer
  • GitHub Check: PSScriptAnalyzer
🔇 Additional comments (8)
tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 (2)

44-66: Good integration harness and lifecycle handling

Describe-level service start/stop, connection management, and module import/unload follow the repo’s integration-test setup. Tags for SQL versions look good.


67-77: Scenario reads well and aligns with guidelines

Creates, removes, and verifies in the same It; uses numeric Severity, -Force, and keeps assertions close to the action. LGTM.

tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1 (1)

74-122: Well-structured scenarios; assertions and inputs look correct

  • Contexts prefixed with “When” and Its starting with “Should” align with guidelines.
  • Numeric literals are used for Severity/MessageId.
  • Avoids brittle ExpectedMessage assertions; uses Should -Throw.
tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 (1)

73-100: LGTM – Return types verified

– Confirmed in source/Public/Get-SqlDscAgentAlert.ps1 that the cmdlet is annotated with
[OutputType([Microsoft.SqlServer.Management.Smo.Agent.Alert], ParameterSetName='ByName')]
and
[OutputType([Microsoft.SqlServer.Management.Smo.Agent.Alert[]], ParameterSetName='All')] (lines 55–56), ensuring only SMO Alert instances (or arrays thereof) are emitted.
– Numeric literals and property assertions in the integration tests align correctly with expected Alert properties.

tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 (1)

71-118: Comprehensive update scenarios; PassThru and error paths covered

  • Uses numeric values for Severity/MessageId.
  • Verifies reset semantics when switching between Severity and MessageId.
  • PassThru coverage is appreciated.
  • Error cases (non-existent and conflicting params) are asserted correctly.
tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 (3)

4-24: Standard integration setup block present and correct.

Includes the expected BeforeDiscovery/BeforeAll prelude, module import/unload, and CI flag handling. Location and naming are per guidelines.

Also applies to: 26-35, 37-42


44-44: Describe name and tags look good.

Single Describe named after the public command with SQL version tags; matches repository conventions.


82-82: Good: Severity/MessageId passed as integers and no ExpectedMessage usage.

These align with integration test rules (no message matching; use numeric types).

Also applies to: 91-91, 109-109, 112-112, 117-117

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

♻️ Duplicate comments (4)
tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 (4)

55-56: Fix for undefined instance variable looks good.

Using $script:sqlServerInstance in Connect-SqlDscDatabaseEngine resolves the earlier undefined variable issue.


67-68: Good: numeric parameters are unquoted.

Passing -Severity and -MessageId as integers aligns with parameter types.


71-74: Prefer SMO for teardown to avoid coupling to other public commands.

Use SMO .Drop() for cleanup instead of Remove-SqlDscAgentAlert to keep this test focused on Get- and reduce cross-command dependencies in teardown.

-        $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_GetAlert1' -Force -ErrorAction 'SilentlyContinue'
-        $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_GetAlert2' -Force -ErrorAction 'SilentlyContinue'
+        try { $script:sqlServerObject.JobServer.Alerts['IntegrationTest_GetAlert1'].Drop() } catch { }
+        try { $script:sqlServerObject.JobServer.Alerts['IntegrationTest_GetAlert2'].Drop() } catch { }

49-49: Grammar nit in comment.

“throw” → “throws an”.

-        $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
+        $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throws an exception.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

💡 Knowledge Base configuration:

  • Jira integration is disabled
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8c1efad and a33cca4.

📒 Files selected for processing (1)
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 (1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
tests/**/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

tests/**/*.ps1: All tests must use Pester and Pester v5.0 syntax
Do not test parameter validation
Test code must not exist outside of a Describe block
Each test file must contain exactly one Describe block named after the subject (public command, private function, or resource)
Each scenario/path should be in Context blocks starting with 'When'; It block descriptions should start with 'Should' and must call the subject; results and assertions stay within the same It; BeforeAll/BeforeEach must not call the subject
Use BeforeAll/BeforeEach/AfterAll/AfterEach inside Context, placed near the It blocks using them; duplication across contexts is acceptable; AfterAll can clean up; use BeforeEach/AfterEach sparingly
Use localized strings in tests only when necessary, retrieving values from $script:localizedData inside InModuleScope
Files that need to be mocked in tests must be created in Pester's $TestDrive

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
tests/Integration/Commands/*.Integration.Tests.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

tests/Integration/Commands/*.Integration.Tests.ps1: Integration tests must exist for all public commands, not mock any commands, be placed at tests/Integration/Commands, and be named .Integration.Tests.ps1
In CI, integration tests must use Get-ComputerName when the computer name is needed
Include the standard integration test setup block (BeforeDiscovery/BeforeAll with module loading) before the first Describe block

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
**/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.ps1: PowerShell files must be UTF-8 without BOM and end with a newline
Try to limit lines to 120 characters
Use 4 spaces for indentation; never use tabs
Use '#' for single-line comments
Use <# ... #> for multiline comments; indent the multiline text 4 spaces
Use descriptive, clear, full names for variables, parameters, and function names; names must be more than 2 characters; no abbreviations
Use camelCase for local variable names
Never use Write-Host
Never use backtick (`) for line continuation
Use splatting to reduce line length
PowerShell reserved keywords should be lowercase
Use single quotes for string literals whenever possible; use double quotes only when interpolation is needed
Hashtable properties should be PascalCase and each on a separate line
When comparing to $null, place $null on the left side of the comparison

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
**

⚙️ CodeRabbit configuration file

**: # DSC Community Guidelines

Terminology

  • Command: Public command
  • Function: Private function
  • Resource: DSC class-based resource

Build & Test Workflow

  • Run project scripts in PowerShell from repository root
  • Build after source changes: .\build.ps1 -Tasks build
  • Test workflow: Build → Invoke-Pester -Path @('<test paths>') -Output Detailed
  • New session required after class changes

File Organization

  • Public commands: source/Public/{CommandName}.ps1
  • Private functions: source/Private/{FunctionName}.ps1
  • Unit tests: tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1
  • Integration tests: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Requirements

  • Always update CHANGELOG.md Unreleased section
  • Localize all strings using string keys
  • Check DscResource.Common before creating private functions
  • Separate reusable logic into private functions
  • Add unit tests for all commands/functions/resources
  • Add integration tests for all public commands and resources

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
**/*.ps?(m|d)1

⚙️ CodeRabbit configuration file

**/*.ps?(m|d)1: # PowerShell Guidelines

Naming

  • Use descriptive names (3+ characters, no abbreviations)
  • Functions: PascalCase with Verb-Noun format using approved verbs
  • Parameters: PascalCase
  • Variables: camelCase
  • Keywords: lower-case
  • Classes: PascalCase
  • Include scope for script/global/environment variables: $script:, $global:, $env:

Formatting

Indentation & Spacing

  • Use 4 spaces (no tabs)
  • One space around operators: $a = 1 + 2
  • One space between type and variable: [String] $name
  • One space between keyword and parenthesis: if ($condition)
  • No spaces on empty lines
  • Try to limit lines to 120 characters

Braces

  • Newline before opening brace (except variable assignments)
  • One newline after opening brace
  • Two newlines after closing brace (one if followed by another brace or continuation)

Quotes

  • Use single quotes unless variable expansion is needed: 'text' vs "text $variable"

Arrays

  • Single line: @('one', 'two', 'three')
  • Multi-line: each element on separate line with proper indentation
  • Do not use the unary comma operator (,) in return statements to force
    an array

Hashtables

  • Empty: @{}
  • Multi-line: each property on separate line with proper indentation
  • Properties: Use PascalCase

Comments

  • Single line: # Comment (capitalized, on own line)
  • Multi-line: <# Comment #> format (opening and closing brackets on own line), and indent text
  • No commented-out code

Comment-based help

  • Always add comment-based help to all functions and scripts
  • Comment-based help: SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, EXAMPLE sections before function/class
  • Comment-based help indentation: keywords 4 spaces, text 8 spaces
  • Include examples for all parameter sets and combinations
  • INPUTS: List each pipeline‑accepted type (one per line) with a 1‑line description.
  • OUTPUTS: List each return type (one per line) with a 1‑line description. Must match both [OutputType()] and actual ...

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
**/*.[Tt]ests.ps1

⚙️ CodeRabbit configuration file

**/*.[Tt]ests.ps1: # Tests Guidelines

Core Requirements

  • All public commands, private functions and classes must have unit tests
  • All public commands and class-based resources must have integration tests
  • Use Pester v5 syntax only
  • One Describe block per file matching the tested entity name
  • Test code only inside Describe blocks
  • Assertions only in It blocks
  • Never test Write-Verbose, Write-Debug, or parameter binding behavior
  • Pass all mandatory parameters to avoid prompts

Structure & Scope

  • Public commands: Never use InModuleScope (unless retrieving localized strings)
  • Private functions/class resources: Always use InModuleScope
  • Each scenario = separate Context block
  • Use nested Context blocks for complex scenarios
  • Mocking in BeforeAll (BeforeEach only when required)
  • Setup/teardown in BeforeAll,BeforeEach/AfterAll,AfterEach close to usage

Syntax Rules

  • PascalCase: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
  • It descriptions start with 'Should'
  • Context descriptions start with 'When'
  • Mock variables prefix: 'mock'
  • Prefer -BeTrue/-BeFalse over -Be $true/-Be $false
  • No Should -Not -Throw - invoke commands directly

File Organization

  • Class resources: tests/Unit/Classes/{Name}.Tests.ps1
  • Public commands: tests/Unit/Public/{Name}.Tests.ps1
  • Private functions: tests/Unit/Private/{Name}.Tests.ps1

Data-Driven Tests

  • Define variables in separate BeforeDiscovery for -ForEach (close to usage)
  • -ForEach allowed on Context and It blocks
  • Keep scope close to usage context

Best Practices

  • Assign unused return objects to $null
  • Tested entity must be called from within the It blocks
  • Keep results and assertions in same It block
  • Cover all scenarios and code paths
  • Use BeforeEach and AfterEach sparingly
  • Avoid try-catch-finally for cleanup, use AfterAll or AfterEach
  • Avoid unnecessary remove/recreate cyc...

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1

⚙️ CodeRabbit configuration file

tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1: # Integration Tests Guidelines

Requirements

  • Location Commands: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1
  • Location Resources: tests/Integration/Resources/{ResourceName}.Integration.Tests.ps1
  • No mocking - real environment only
  • Cover all scenarios and code paths
  • Use Get-ComputerName for computer names in CI
  • Avoid ExpectedMessage for Should -Throw assertions
  • Only run integration tests in CI unless explicitly instructed.
  • Call commands with -Force parameter where applicable (avoids prompting).

Required Setup Block

[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
param ()

BeforeDiscovery {
    try
    {
        if (-not (Get-Module -Name 'DscResource.Test'))
        {
            # Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
            if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
            {
                # Redirect all streams to $null, except the error stream (stream 2)
                & "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
            }

            # If the dependencies have not been resolved, this will throw an error.
            Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
        }
    }
    catch [System.IO.FileNotFoundException]
    {
        throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.'
    }
}

BeforeAll {
    $script:dscModuleName = 'SqlServerDsc'

    Import-Module -Name $script:dscModuleName -Force -ErrorAction 'Stop'
}

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
🧠 Learnings (6)
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Integration tests must exist for all public commands, not mock any commands, be placed at tests/Integration/Commands, and be named <Command>.Integration.Tests.ps1

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to azure-pipelines.yml : Add each public command integration test script to a group within the Integration_Test_Commands_SqlServer stage in ./azure-pipelines.yml, choosing the appropriate group

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Include the standard integration test setup block (BeforeDiscovery/BeforeAll with module loading) before the first Describe block

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : In CI, integration tests must use Get-ComputerName when the computer name is needed

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Use BeforeAll/BeforeEach/AfterAll/AfterEach inside Context, placed near the It blocks using them; duplication across contexts is acceptable; AfterAll can clean up; use BeforeEach/AfterEach sparingly

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T10:13:30.079Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/Public/Remove-SqlDscLogin.ps1:104-108
Timestamp: 2025-08-17T10:13:30.079Z
Learning: In SqlServerDsc unit tests, SMO object stubs (like Login objects) should have properly mocked Parent properties with correct Server stub types and valid InstanceName values, rather than handling null Parent scenarios in production code.

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
  • GitHub Check: PSScriptAnalyzer
  • GitHub Check: PSScriptAnalyzer
🔇 Additional comments (3)
tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 (3)

4-24: Setup block matches the required integration test pattern.

Good use of the standard BeforeDiscovery/BeforeAll bootstrap (module resolution and import).

Also applies to: 26-35


1-1: CI wiring check: ensure this test is added to the pipeline group.

Per repo learnings, add this file to an Integration_Test_Commands_SqlServer group in azure-pipelines.yml so it executes in CI.

Proposed verification (manual):

  • Confirm a new/updated entry referencing tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 exists under the correct group in azure-pipelines.yml.

92-94: Fix type assertion for collections.

BeOfType on an array checks the array type, not the element type. Assert elements individually.

-        $alerts | Should -BeOfType [Microsoft.SqlServer.Management.Smo.Agent.Alert]
+        $alerts | ForEach-Object { $_ | Should -BeOfType [Microsoft.SqlServer.Management.Smo.Agent.Alert] }
⛔ Skipped due to learnings
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2134
File: tests/Unit/Public/Get-SqlDscLogin.Tests.ps1:178-185
Timestamp: 2025-08-15T05:37:29.255Z
Learning: In PowerShell Pester tests, when piping an array to `Should -BeOfType`, PowerShell's pipeline automatically unrolls the array and checks the type of each individual element, not the array type itself. This means `$result | Should -BeOfType 'SomeType'` for an array will validate every element's type without needing the `-All` modifier.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

♻️ Duplicate comments (7)
tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 (7)

44-117: Restructure under a Context to comply with tests guidelines.

Place setup/teardown inside a Context 'When alerts exist' and keep Its within that Context to match tests/**/*.ps1 rules.

Apply:

-Describe 'Get-SqlDscAgentAlert' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' {
-    BeforeAll {
+Describe 'Get-SqlDscAgentAlert' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' {
+    Context 'When alerts exist' {
+        BeforeAll {
@@
-    }
-
-    AfterAll {
-        ...
-    }
-
-    It 'Should get all alerts' {
-        ...
-    }
-    It 'Should get specific alert by name' {
-        ...
-    }
-    It 'Should return null for non-existent alert' {
-        ...
-    }
-    It 'Should get alert with message ID' {
-        ...
-    }
+        }
+
+        AfterAll {
+            ...
+        }
+
+        It 'Should get all alerts' {
+            ...
+        }
+
+        It 'Should get specific alert by name' {
+            ...
+        }
+
+        It 'Should return null for non-existent alert' {
+            ...
+        }
+
+        It 'Should get alert with message ID' {
+            ...
+        }
+    }
 }

46-48: Guard Start-Service to avoid errors if already running.

-        # Starting the named instance SQL Server service prior to running tests.
-        Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
+        # Ensure the named instance SQL Server service is running prior to tests.
+        if ((Get-Service -Name 'MSSQL$DSCSQLTEST').Status -ne 'Running')
+        {
+            Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
+        }

49-49: Grammar nit in comment.

-        $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
+        $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throws an exception.

57-65: Make sp_addmessage idempotent to support reruns.

-        Write-Verbose -Message 'Add SQL Server system message for testing message ID alerts' -Verbose
-        $addMessageQuery = @'
-EXECUTE sp_addmessage
-    50001,
-    16,
-    N'Mock message';
-'@
+        Write-Verbose -Message 'Ensure SQL Server system message 50001 exists for testing message ID alerts' -Verbose
+        $addMessageQuery = @'
+IF NOT EXISTS (SELECT 1 FROM sys.messages WHERE message_id = 50001 AND language_id = 1033)
+BEGIN
+    EXECUTE sp_addmessage
+        50001,
+        16,
+        N''Mock message'';
+END
+'@

71-74: Use SMO for teardown; avoid invoking module commands in cleanup.

-        $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_GetAlert1' -Force -ErrorAction 'SilentlyContinue'
-        $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_GetAlert2' -Force -ErrorAction 'SilentlyContinue'
+        foreach ($alertName in @('IntegrationTest_GetAlert1', 'IntegrationTest_GetAlert2'))
+        {
+            try
+            {
+                $alert = $script:sqlServerObject.JobServer.Alerts[$alertName]
+                if ($null -ne $alert)
+                {
+                    $alert.Drop()
+                }
+            }
+            catch
+            {
+                # Ignore if not found or cannot drop
+            }
+        }

75-81: Remove commented-out code; keep a concise TODO.

-# TODO: Keep this commented until we have a correct command to remove messages, and we can have another integration tests keeping a persistent message
-#         # Remove SQL Server system message
-#         $removeMessageQuery = @'
-# EXECUTE sp_dropmessage 50001;
-# '@
-#         $script:sqlServerObject | Invoke-SqlDscQuery -DatabaseName 'master' -Query $removeMessageQuery -Force -ErrorAction 'SilentlyContinue'
+        # TODO: Keep message 50001 until a correct removal command exists; another integration test may depend on it.

110-116: Align test intent: filter by -MessageId (or reword description).

Prefer querying by -MessageId to match the It description.

-    It 'Should get alert with message ID' {
-        $alert = $script:sqlServerObject | Get-SqlDscAgentAlert -Name 'IntegrationTest_GetAlert2'
+    It 'Should get alert with message ID' {
+        $alerts = $script:sqlServerObject | Get-SqlDscAgentAlert -MessageId 50001
@@
-        $alert | Should -Not -BeNullOrEmpty
-        $alert.Name | Should -Be 'IntegrationTest_GetAlert2'
-        $alert.MessageId | Should -Be 50001
+        $alerts | Should -Not -BeNullOrEmpty
+        $alerts | ForEach-Object { $_.MessageId | Should -Be 50001 }
+        ($alerts | Select-Object -First 1).Name | Should -Be 'IntegrationTest_GetAlert2'

If -MessageId is not supported, rename the It to "Should get alert created with message ID" and keep the -Name query.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

💡 Knowledge Base configuration:

  • Jira integration is disabled
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a33cca4 and 84bf73b.

📒 Files selected for processing (2)
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 (1 hunks)
  • tests/Integration/Commands/Get-SqlDscRole.Integration.Tests.ps1 (0 hunks)
💤 Files with no reviewable changes (1)
  • tests/Integration/Commands/Get-SqlDscRole.Integration.Tests.ps1
🧰 Additional context used
📓 Path-based instructions (7)
tests/**/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

tests/**/*.ps1: All tests must use Pester and Pester v5.0 syntax
Do not test parameter validation
Test code must not exist outside of a Describe block
Each test file must contain exactly one Describe block named after the subject (public command, private function, or resource)
Each scenario/path should be in Context blocks starting with 'When'; It block descriptions should start with 'Should' and must call the subject; results and assertions stay within the same It; BeforeAll/BeforeEach must not call the subject
Use BeforeAll/BeforeEach/AfterAll/AfterEach inside Context, placed near the It blocks using them; duplication across contexts is acceptable; AfterAll can clean up; use BeforeEach/AfterEach sparingly
Use localized strings in tests only when necessary, retrieving values from $script:localizedData inside InModuleScope
Files that need to be mocked in tests must be created in Pester's $TestDrive

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
tests/Integration/Commands/*.Integration.Tests.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

tests/Integration/Commands/*.Integration.Tests.ps1: Integration tests must exist for all public commands, not mock any commands, be placed at tests/Integration/Commands, and be named .Integration.Tests.ps1
In CI, integration tests must use Get-ComputerName when the computer name is needed
Include the standard integration test setup block (BeforeDiscovery/BeforeAll with module loading) before the first Describe block

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
**/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.ps1: PowerShell files must be UTF-8 without BOM and end with a newline
Try to limit lines to 120 characters
Use 4 spaces for indentation; never use tabs
Use '#' for single-line comments
Use <# ... #> for multiline comments; indent the multiline text 4 spaces
Use descriptive, clear, full names for variables, parameters, and function names; names must be more than 2 characters; no abbreviations
Use camelCase for local variable names
Never use Write-Host
Never use backtick (`) for line continuation
Use splatting to reduce line length
PowerShell reserved keywords should be lowercase
Use single quotes for string literals whenever possible; use double quotes only when interpolation is needed
Hashtable properties should be PascalCase and each on a separate line
When comparing to $null, place $null on the left side of the comparison

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
**

⚙️ CodeRabbit configuration file

**: # DSC Community Guidelines

Terminology

  • Command: Public command
  • Function: Private function
  • Resource: DSC class-based resource

Build & Test Workflow

  • Run project scripts in PowerShell from repository root
  • Build after source changes: .\build.ps1 -Tasks build
  • Test workflow: Build → Invoke-Pester -Path @('<test paths>') -Output Detailed
  • New session required after class changes

File Organization

  • Public commands: source/Public/{CommandName}.ps1
  • Private functions: source/Private/{FunctionName}.ps1
  • Unit tests: tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1
  • Integration tests: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Requirements

  • Always update CHANGELOG.md Unreleased section
  • Localize all strings using string keys
  • Check DscResource.Common before creating private functions
  • Separate reusable logic into private functions
  • Add unit tests for all commands/functions/resources
  • Add integration tests for all public commands and resources

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
**/*.ps?(m|d)1

⚙️ CodeRabbit configuration file

**/*.ps?(m|d)1: # PowerShell Guidelines

Naming

  • Use descriptive names (3+ characters, no abbreviations)
  • Functions: PascalCase with Verb-Noun format using approved verbs
  • Parameters: PascalCase
  • Variables: camelCase
  • Keywords: lower-case
  • Classes: PascalCase
  • Include scope for script/global/environment variables: $script:, $global:, $env:

Formatting

Indentation & Spacing

  • Use 4 spaces (no tabs)
  • One space around operators: $a = 1 + 2
  • One space between type and variable: [String] $name
  • One space between keyword and parenthesis: if ($condition)
  • No spaces on empty lines
  • Try to limit lines to 120 characters

Braces

  • Newline before opening brace (except variable assignments)
  • One newline after opening brace
  • Two newlines after closing brace (one if followed by another brace or continuation)

Quotes

  • Use single quotes unless variable expansion is needed: 'text' vs "text $variable"

Arrays

  • Single line: @('one', 'two', 'three')
  • Multi-line: each element on separate line with proper indentation
  • Do not use the unary comma operator (,) in return statements to force
    an array

Hashtables

  • Empty: @{}
  • Multi-line: each property on separate line with proper indentation
  • Properties: Use PascalCase

Comments

  • Single line: # Comment (capitalized, on own line)
  • Multi-line: <# Comment #> format (opening and closing brackets on own line), and indent text
  • No commented-out code

Comment-based help

  • Always add comment-based help to all functions and scripts
  • Comment-based help: SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, EXAMPLE sections before function/class
  • Comment-based help indentation: keywords 4 spaces, text 8 spaces
  • Include examples for all parameter sets and combinations
  • INPUTS: List each pipeline‑accepted type (one per line) with a 1‑line description.
  • OUTPUTS: List each return type (one per line) with a 1‑line description. Must match both [OutputType()] and actual ...

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
**/*.[Tt]ests.ps1

⚙️ CodeRabbit configuration file

**/*.[Tt]ests.ps1: # Tests Guidelines

Core Requirements

  • All public commands, private functions and classes must have unit tests
  • All public commands and class-based resources must have integration tests
  • Use Pester v5 syntax only
  • One Describe block per file matching the tested entity name
  • Test code only inside Describe blocks
  • Assertions only in It blocks
  • Never test Write-Verbose, Write-Debug, or parameter binding behavior
  • Pass all mandatory parameters to avoid prompts

Structure & Scope

  • Public commands: Never use InModuleScope (unless retrieving localized strings)
  • Private functions/class resources: Always use InModuleScope
  • Each scenario = separate Context block
  • Use nested Context blocks for complex scenarios
  • Mocking in BeforeAll (BeforeEach only when required)
  • Setup/teardown in BeforeAll,BeforeEach/AfterAll,AfterEach close to usage

Syntax Rules

  • PascalCase: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
  • It descriptions start with 'Should'
  • Context descriptions start with 'When'
  • Mock variables prefix: 'mock'
  • Prefer -BeTrue/-BeFalse over -Be $true/-Be $false
  • No Should -Not -Throw - invoke commands directly

File Organization

  • Class resources: tests/Unit/Classes/{Name}.Tests.ps1
  • Public commands: tests/Unit/Public/{Name}.Tests.ps1
  • Private functions: tests/Unit/Private/{Name}.Tests.ps1

Data-Driven Tests

  • Define variables in separate BeforeDiscovery for -ForEach (close to usage)
  • -ForEach allowed on Context and It blocks
  • Keep scope close to usage context

Best Practices

  • Assign unused return objects to $null
  • Tested entity must be called from within the It blocks
  • Keep results and assertions in same It block
  • Cover all scenarios and code paths
  • Use BeforeEach and AfterEach sparingly
  • Avoid try-catch-finally for cleanup, use AfterAll or AfterEach
  • Avoid unnecessary remove/recreate cyc...

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1

⚙️ CodeRabbit configuration file

tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1: # Integration Tests Guidelines

Requirements

  • Location Commands: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1
  • Location Resources: tests/Integration/Resources/{ResourceName}.Integration.Tests.ps1
  • No mocking - real environment only
  • Cover all scenarios and code paths
  • Use Get-ComputerName for computer names in CI
  • Avoid ExpectedMessage for Should -Throw assertions
  • Only run integration tests in CI unless explicitly instructed.
  • Call commands with -Force parameter where applicable (avoids prompting).

Required Setup Block

[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
param ()

BeforeDiscovery {
    try
    {
        if (-not (Get-Module -Name 'DscResource.Test'))
        {
            # Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
            if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
            {
                # Redirect all streams to $null, except the error stream (stream 2)
                & "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
            }

            # If the dependencies have not been resolved, this will throw an error.
            Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
        }
    }
    catch [System.IO.FileNotFoundException]
    {
        throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.'
    }
}

BeforeAll {
    $script:dscModuleName = 'SqlServerDsc'

    Import-Module -Name $script:dscModuleName -Force -ErrorAction 'Stop'
}

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
🧠 Learnings (10)
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Integration tests must exist for all public commands, not mock any commands, be placed at tests/Integration/Commands, and be named <Command>.Integration.Tests.ps1

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to azure-pipelines.yml : Add each public command integration test script to a group within the Integration_Test_Commands_SqlServer stage in ./azure-pipelines.yml, choosing the appropriate group

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Include the standard integration test setup block (BeforeDiscovery/BeforeAll with module loading) before the first Describe block

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : In CI, integration tests must use Get-ComputerName when the computer name is needed

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Use BeforeAll/BeforeEach/AfterAll/AfterEach inside Context, placed near the It blocks using them; duplication across contexts is acceptable; AfterAll can clean up; use BeforeEach/AfterEach sparingly

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T10:13:30.079Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/Public/Remove-SqlDscLogin.ps1:104-108
Timestamp: 2025-08-17T10:13:30.079Z
Learning: In SqlServerDsc unit tests, SMO object stubs (like Login objects) should have properly mocked Parent properties with correct Server stub types and valid InstanceName values, rather than handling null Parent scenarios in production code.

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Each scenario/path should be in Context blocks starting with 'When'; It block descriptions should start with 'Should' and must call the subject; results and assertions stay within the same It; BeforeAll/BeforeEach must not call the subject

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Test code must not exist outside of a Describe block

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Each test file must contain exactly one Describe block named after the subject (public command, private function, or resource)

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T10:15:48.194Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: tests/Unit/Public/Remove-SqlDscLogin.Tests.ps1:36-39
Timestamp: 2025-08-17T10:15:48.194Z
Learning: Public command unit tests guideline: Never use InModuleScope unless accessing localized strings from $script:localizedData. PSDefaultParameterValues for InModuleScope should be kept in public command tests to support localized string retrieval when necessary.

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
  • GitHub Check: PSScriptAnalyzer
  • GitHub Check: PSScriptAnalyzer
🔇 Additional comments (7)
tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 (7)

1-2: Header and analyzer suppression look good.

Standard pattern for integration tests; no issues.


4-24: Standard integration setup block is correct.

Dependency bootstrap and import for DscResource.Test follow guidelines.


26-35: Module import and CI flag initialization are appropriate.

Good use of $env:SqlServerDscCI and clear instance naming.


37-42: Module unload is handled correctly.

Prevents cross-test contamination.


44-44: Integration test already registered in Azure Pipelines

Confirmed that tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 is listed under the Integration_Test_Commands_SqlServer stage (azure-pipelines.yml, line 304), so no further changes are needed.


90-94: Fix type assertion for arrays.

-BeOfType on an array checks the array type; assert element types instead.

-        $alerts | Should -Not -BeNullOrEmpty
-        $alerts | Should -BeOfType [Microsoft.SqlServer.Management.Smo.Agent.Alert]
+        $alerts | Should -Not -BeNullOrEmpty
+        $alerts | ForEach-Object { $_ | Should -BeOfType ([Microsoft.SqlServer.Management.Smo.Agent.Alert]) }
⛔ Skipped due to learnings
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2134
File: tests/Unit/Public/Get-SqlDscLogin.Tests.ps1:178-185
Timestamp: 2025-08-15T05:37:29.255Z
Learning: In PowerShell Pester tests, when piping an array to `Should -BeOfType`, PowerShell's pipeline automatically unrolls the array and checks the type of each individual element, not the array type itself. This means `$result | Should -BeOfType 'SomeType'` for an array will validate every element's type without needing the `-All` modifier.

66-69: Remove -Force suggestion: New-SqlDscAgentAlert does not support a -Force switch

I verified the New-SqlDscAgentAlert function in source/Public/New-SqlDscAgentAlert.ps1 has a [CmdletBinding(SupportsShouldProcess=$true)] attribute but no [switch] $Force parameter is declared. Adding -Force would therefore error out. Please ignore the original recommendation to add -Force in these integration tests.

Likely an incorrect or invalid review comment.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (10)
tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 (10)

44-117: Move setup/teardown under a Context block per tests//*.ps1 guidelines**

Scenarios should be inside Context blocks starting with 'When'; place BeforeAll/AfterAll near the It blocks they support. Wrap the current content inside a Context (e.g., 'When alerts exist').

Apply:

 Describe 'Get-SqlDscAgentAlert' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' {
-    BeforeAll {
+    Context 'When alerts exist' {
+        BeforeAll {
@@
-    }
-
-    AfterAll {
+        }
+
+        AfterAll {
@@
-    }
-
-    It 'Should get all alerts' {
+        }
+
+        It 'Should get all alerts' {
@@
-    }
-
-    It 'Should get specific alert by name' {
+        }
+
+        It 'Should get specific alert by name' {
@@
-    }
-
-    It 'Should return null for non-existent alert' {
+        }
+
+        It 'Should return null for non-existent alert' {
@@
-    }
-
-    It 'Should get alert with message ID' {
+        }
+
+        It 'Should get alert with message ID' {
@@
-    }
+        }
+    }
 }

46-47: Guard Start-Service to avoid failure if already running

Prevent Start-Service from throwing when the service is already running.

Apply:

-        # Starting the named instance SQL Server service prior to running tests.
-        Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
+        # Ensure the named instance SQL Server service is running prior to tests.
+        if ((Get-Service -Name 'MSSQL$DSCSQLTEST').Status -ne 'Running')
+        {
+            Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
+        }

49-49: Grammar nit in comment

“throw” → “throws”.

Apply:

-        $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
+        $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throws an exception.

55-55: Fail fast on connection errors

Add -ErrorAction 'Stop' so failures surface immediately.

Apply:

-        $script:sqlServerObject = Connect-SqlDscDatabaseEngine -InstanceName $script:sqlServerInstance -Credential $script:mockSqlAdminCredential
+        $script:sqlServerObject = Connect-SqlDscDatabaseEngine -InstanceName $script:sqlServerInstance -Credential $script:mockSqlAdminCredential -ErrorAction 'Stop'

58-64: Make sp_addmessage idempotent to support reruns

Unconditional sp_addmessage fails if the message already exists. Wrap with IF NOT EXISTS.

Apply:

-        $addMessageQuery = @'
-EXECUTE sp_addmessage
-    50001,
-    16,
-    N'Mock message';
-'@
+        $addMessageQuery = @'
+IF NOT EXISTS (SELECT 1 FROM sys.messages WHERE message_id = 50001 AND language_id = 1033)
+BEGIN
+    EXECUTE sp_addmessage
+        50001,
+        16,
+        N''Mock message'';
+END
+'@

66-66: Pre-drop lingering test alerts with SMO to make setup idempotent

Ensure clean slate before creating test alerts.

Apply before creating alerts:

+        # Ensure no pre-existing test alerts remain from previous runs
+        foreach ($alertName in @('IntegrationTest_GetAlert1', 'IntegrationTest_GetAlert2'))
+        {
+            try
+            {
+                $existing = $script:sqlServerObject.JobServer.Alerts[$alertName]
+                if ($null -ne $existing)
+                {
+                    $existing.Drop()
+                }
+            }
+            catch
+            {
+                # Ignore if alert not found
+            }
+        }

71-74: Do not use module cmdlets for teardown; prefer SMO Drop()

Teardown should not call module cmdlets; use SMO to remove alerts.

Apply:

-        $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_GetAlert1' -Force -ErrorAction 'SilentlyContinue'
-        $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_GetAlert2' -Force -ErrorAction 'SilentlyContinue'
+        foreach ($alertName in @('IntegrationTest_GetAlert1', 'IntegrationTest_GetAlert2'))
+        {
+            try
+            {
+                $existing = $script:sqlServerObject.JobServer.Alerts[$alertName]
+                if ($null -ne $existing)
+                {
+                    $existing.Drop()
+                }
+            }
+            catch
+            {
+                # Ignore if not found
+            }
+        }

75-81: Remove commented-out code; keep a concise TODO

Guidelines disallow commented-out code. Replace with a single TODO line.

Apply:

-# TODO: Keep this commented until we have a correct command to remove messages, and we can have another integration tests keeping a persistent message
-#         # Remove SQL Server system message
-#         $removeMessageQuery = @'
-# EXECUTE sp_dropmessage 50001;
-# '@
-#         $script:sqlServerObject | Invoke-SqlDscQuery -DatabaseName 'master' -Query $removeMessageQuery -Force -ErrorAction 'SilentlyContinue'
+        # TODO: Keep message 50001 until a correct removal command exists (another integration test may depend on it).

85-86: Guard Stop-Service to avoid failure if already stopped

Prevent Stop-Service from throwing when already stopped.

Apply:

-        # Stop the named instance SQL Server service to save memory on the build worker.
-        Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
+        # Stop the named instance SQL Server service to save memory on the build worker.
+        if ((Get-Service -Name 'MSSQL$DSCSQLTEST').Status -eq 'Running')
+        {
+            Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop'
+        }

110-116: Align test intent and invocation for Message ID scenario

Description says message ID but the call filters by Name. Prefer filtering by -MessageId (if supported); otherwise adjust description.

Option A (preferred if supported):

-    It 'Should get alert with message ID' {
-        $alert = $script:sqlServerObject | Get-SqlDscAgentAlert -Name 'IntegrationTest_GetAlert2'
+    It 'Should get alert with message ID' {
+        $alerts = $script:sqlServerObject | Get-SqlDscAgentAlert -MessageId 50001
@@
-        $alert | Should -Not -BeNullOrEmpty
-        $alert.Name | Should -Be 'IntegrationTest_GetAlert2'
-        $alert.MessageId | Should -Be 50001
+        $alerts | Should -Not -BeNullOrEmpty
+        $alerts | ForEach-Object { $_.MessageId | Should -Be 50001 }
+        ($alerts | Select-Object -First 1).Name | Should -Be 'IntegrationTest_GetAlert2'

Option B (if -MessageId is not a parameter):

-    It 'Should get alert with message ID' {
+    It 'Should get alert created with message ID' {
         $alert = $script:sqlServerObject | Get-SqlDscAgentAlert -Name 'IntegrationTest_GetAlert2'
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

💡 Knowledge Base configuration:

  • Jira integration is disabled
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 84bf73b and babe813.

📒 Files selected for processing (1)
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 (1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
tests/**/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

tests/**/*.ps1: All tests must use Pester and Pester v5.0 syntax
Do not test parameter validation
Test code must not exist outside of a Describe block
Each test file must contain exactly one Describe block named after the subject (public command, private function, or resource)
Each scenario/path should be in Context blocks starting with 'When'; It block descriptions should start with 'Should' and must call the subject; results and assertions stay within the same It; BeforeAll/BeforeEach must not call the subject
Use BeforeAll/BeforeEach/AfterAll/AfterEach inside Context, placed near the It blocks using them; duplication across contexts is acceptable; AfterAll can clean up; use BeforeEach/AfterEach sparingly
Use localized strings in tests only when necessary, retrieving values from $script:localizedData inside InModuleScope
Files that need to be mocked in tests must be created in Pester's $TestDrive

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
tests/Integration/Commands/*.Integration.Tests.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

tests/Integration/Commands/*.Integration.Tests.ps1: Integration tests must exist for all public commands, not mock any commands, be placed at tests/Integration/Commands, and be named .Integration.Tests.ps1
In CI, integration tests must use Get-ComputerName when the computer name is needed
Include the standard integration test setup block (BeforeDiscovery/BeforeAll with module loading) before the first Describe block

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
**/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.ps1: PowerShell files must be UTF-8 without BOM and end with a newline
Try to limit lines to 120 characters
Use 4 spaces for indentation; never use tabs
Use '#' for single-line comments
Use <# ... #> for multiline comments; indent the multiline text 4 spaces
Use descriptive, clear, full names for variables, parameters, and function names; names must be more than 2 characters; no abbreviations
Use camelCase for local variable names
Never use Write-Host
Never use backtick (`) for line continuation
Use splatting to reduce line length
PowerShell reserved keywords should be lowercase
Use single quotes for string literals whenever possible; use double quotes only when interpolation is needed
Hashtable properties should be PascalCase and each on a separate line
When comparing to $null, place $null on the left side of the comparison

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
**

⚙️ CodeRabbit configuration file

**: # DSC Community Guidelines

Terminology

  • Command: Public command
  • Function: Private function
  • Resource: DSC class-based resource

Build & Test Workflow

  • Run project scripts in PowerShell from repository root
  • Build after source changes: .\build.ps1 -Tasks build
  • Test workflow: Build → Invoke-Pester -Path @('<test paths>') -Output Detailed
  • New session required after class changes

File Organization

  • Public commands: source/Public/{CommandName}.ps1
  • Private functions: source/Private/{FunctionName}.ps1
  • Unit tests: tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1
  • Integration tests: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Requirements

  • Always update CHANGELOG.md Unreleased section
  • Localize all strings using string keys
  • Check DscResource.Common before creating private functions
  • Separate reusable logic into private functions
  • Add unit tests for all commands/functions/resources
  • Add integration tests for all public commands and resources

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
**/*.ps?(m|d)1

⚙️ CodeRabbit configuration file

**/*.ps?(m|d)1: # PowerShell Guidelines

Naming

  • Use descriptive names (3+ characters, no abbreviations)
  • Functions: PascalCase with Verb-Noun format using approved verbs
  • Parameters: PascalCase
  • Variables: camelCase
  • Keywords: lower-case
  • Classes: PascalCase
  • Include scope for script/global/environment variables: $script:, $global:, $env:

Formatting

Indentation & Spacing

  • Use 4 spaces (no tabs)
  • One space around operators: $a = 1 + 2
  • One space between type and variable: [String] $name
  • One space between keyword and parenthesis: if ($condition)
  • No spaces on empty lines
  • Try to limit lines to 120 characters

Braces

  • Newline before opening brace (except variable assignments)
  • One newline after opening brace
  • Two newlines after closing brace (one if followed by another brace or continuation)

Quotes

  • Use single quotes unless variable expansion is needed: 'text' vs "text $variable"

Arrays

  • Single line: @('one', 'two', 'three')
  • Multi-line: each element on separate line with proper indentation
  • Do not use the unary comma operator (,) in return statements to force
    an array

Hashtables

  • Empty: @{}
  • Multi-line: each property on separate line with proper indentation
  • Properties: Use PascalCase

Comments

  • Single line: # Comment (capitalized, on own line)
  • Multi-line: <# Comment #> format (opening and closing brackets on own line), and indent text
  • No commented-out code

Comment-based help

  • Always add comment-based help to all functions and scripts
  • Comment-based help: SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, EXAMPLE sections before function/class
  • Comment-based help indentation: keywords 4 spaces, text 8 spaces
  • Include examples for all parameter sets and combinations
  • INPUTS: List each pipeline‑accepted type (one per line) with a 1‑line description.
  • OUTPUTS: List each return type (one per line) with a 1‑line description. Must match both [OutputType()] and actual ...

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
**/*.[Tt]ests.ps1

⚙️ CodeRabbit configuration file

**/*.[Tt]ests.ps1: # Tests Guidelines

Core Requirements

  • All public commands, private functions and classes must have unit tests
  • All public commands and class-based resources must have integration tests
  • Use Pester v5 syntax only
  • One Describe block per file matching the tested entity name
  • Test code only inside Describe blocks
  • Assertions only in It blocks
  • Never test Write-Verbose, Write-Debug, or parameter binding behavior
  • Pass all mandatory parameters to avoid prompts

Structure & Scope

  • Public commands: Never use InModuleScope (unless retrieving localized strings)
  • Private functions/class resources: Always use InModuleScope
  • Each scenario = separate Context block
  • Use nested Context blocks for complex scenarios
  • Mocking in BeforeAll (BeforeEach only when required)
  • Setup/teardown in BeforeAll,BeforeEach/AfterAll,AfterEach close to usage

Syntax Rules

  • PascalCase: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
  • It descriptions start with 'Should'
  • Context descriptions start with 'When'
  • Mock variables prefix: 'mock'
  • Prefer -BeTrue/-BeFalse over -Be $true/-Be $false
  • No Should -Not -Throw - invoke commands directly

File Organization

  • Class resources: tests/Unit/Classes/{Name}.Tests.ps1
  • Public commands: tests/Unit/Public/{Name}.Tests.ps1
  • Private functions: tests/Unit/Private/{Name}.Tests.ps1

Data-Driven Tests

  • Define variables in separate BeforeDiscovery for -ForEach (close to usage)
  • -ForEach allowed on Context and It blocks
  • Keep scope close to usage context

Best Practices

  • Assign unused return objects to $null
  • Tested entity must be called from within the It blocks
  • Keep results and assertions in same It block
  • Cover all scenarios and code paths
  • Use BeforeEach and AfterEach sparingly
  • Avoid try-catch-finally for cleanup, use AfterAll or AfterEach
  • Avoid unnecessary remove/recreate cyc...

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1

⚙️ CodeRabbit configuration file

tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1: # Integration Tests Guidelines

Requirements

  • Location Commands: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1
  • Location Resources: tests/Integration/Resources/{ResourceName}.Integration.Tests.ps1
  • No mocking - real environment only
  • Cover all scenarios and code paths
  • Use Get-ComputerName for computer names in CI
  • Avoid ExpectedMessage for Should -Throw assertions
  • Only run integration tests in CI unless explicitly instructed.
  • Call commands with -Force parameter where applicable (avoids prompting).

Required Setup Block

[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
param ()

BeforeDiscovery {
    try
    {
        if (-not (Get-Module -Name 'DscResource.Test'))
        {
            # Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
            if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
            {
                # Redirect all streams to $null, except the error stream (stream 2)
                & "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
            }

            # If the dependencies have not been resolved, this will throw an error.
            Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
        }
    }
    catch [System.IO.FileNotFoundException]
    {
        throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.'
    }
}

BeforeAll {
    $script:dscModuleName = 'SqlServerDsc'

    Import-Module -Name $script:dscModuleName -Force -ErrorAction 'Stop'
}

Files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
🧠 Learnings (10)
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Integration tests must exist for all public commands, not mock any commands, be placed at tests/Integration/Commands, and be named <Command>.Integration.Tests.ps1

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to azure-pipelines.yml : Add each public command integration test script to a group within the Integration_Test_Commands_SqlServer stage in ./azure-pipelines.yml, choosing the appropriate group

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Include the standard integration test setup block (BeforeDiscovery/BeforeAll with module loading) before the first Describe block

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : In CI, integration tests must use Get-ComputerName when the computer name is needed

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Use BeforeAll/BeforeEach/AfterAll/AfterEach inside Context, placed near the It blocks using them; duplication across contexts is acceptable; AfterAll can clean up; use BeforeEach/AfterEach sparingly

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T10:13:30.079Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/Public/Remove-SqlDscLogin.ps1:104-108
Timestamp: 2025-08-17T10:13:30.079Z
Learning: In SqlServerDsc unit tests, SMO object stubs (like Login objects) should have properly mocked Parent properties with correct Server stub types and valid InstanceName values, rather than handling null Parent scenarios in production code.

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Each scenario/path should be in Context blocks starting with 'When'; It block descriptions should start with 'Should' and must call the subject; results and assertions stay within the same It; BeforeAll/BeforeEach must not call the subject

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Test code must not exist outside of a Describe block

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Each test file must contain exactly one Describe block named after the subject (public command, private function, or resource)

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T10:15:48.194Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: tests/Unit/Public/Remove-SqlDscLogin.Tests.ps1:36-39
Timestamp: 2025-08-17T10:15:48.194Z
Learning: Public command unit tests guideline: Never use InModuleScope unless accessing localized strings from $script:localizedData. PSDefaultParameterValues for InModuleScope should be kept in public command tests to support localized string retrieval when necessary.

Applied to files:

  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: dsccommunity.SqlServerDsc (Quality Test and Unit Test Determine DSC Resource Test Requirements)
  • GitHub Check: dsccommunity.SqlServerDsc (Quality Test and Unit Test HQRM)
  • GitHub Check: dsccommunity.SqlServerDsc (Quality Test and Unit Test Unit)
  • GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
🔇 Additional comments (3)
tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 (3)

4-24: Standard integration setup block is correct

BeforeDiscovery resolves DscResource.Test, performs noop fallback, and throws a clear error otherwise. This matches the required setup template.


26-42: Module import/unload and CI flag handling look good

Setting $env:SqlServerDscCI in BeforeAll and clearing it in AfterAll, plus unloading the module, align with guidelines.


92-94: Fix type assertion for “all alerts” scenario

When multiple alerts are returned, $alerts is an Object[]; assert element types instead.

Apply:

-        $alerts | Should -Not -BeNullOrEmpty
-        $alerts | Should -BeOfType [Microsoft.SqlServer.Management.Smo.Agent.Alert]
+        $alerts | Should -Not -BeNullOrEmpty
+        $alerts | ForEach-Object { $_ | Should -BeOfType [Microsoft.SqlServer.Management.Smo.Agent.Alert] }
⛔ Skipped due to learnings
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2134
File: tests/Unit/Public/Get-SqlDscLogin.Tests.ps1:178-185
Timestamp: 2025-08-15T05:37:29.255Z
Learning: In PowerShell Pester tests, when piping an array to `Should -BeOfType`, PowerShell's pipeline automatically unrolls the array and checks the type of each individual element, not the array type itself. This means `$result | Should -BeOfType 'SomeType'` for an array will validate every element's type without needing the `-All` modifier.

…ndling and conditional message creation for system messages.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (3)
tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1 (2)

49-49: Grammar nit in inline comment

“throw” → “throws”.

-        $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
+        $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throws an exception.

62-72: Prefer SMO Drop() for teardown instead of invoking module commands

Keeps the Test-* subject isolated and avoids cascading failures from other commands during cleanup.

-        # Clean up test alerts
-        $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_SeverityAlert' -Force -ErrorAction 'SilentlyContinue'
-        $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_MessageIdAlert' -Force -ErrorAction 'SilentlyContinue'
+        # Clean up test alerts without invoking module commands
+        try { $script:sqlServerObject.JobServer.Alerts['IntegrationTest_SeverityAlert'].Drop() } catch { }
+        try { $script:sqlServerObject.JobServer.Alerts['IntegrationTest_MessageIdAlert'].Drop() } catch { }
tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 (1)

61-69: Optional: decouple teardown from other public commands; drop via SMO.

Relying on Remove-SqlDscAgentAlert in teardown can cascade failures if that command regresses. Prefer removing the alert via SMO to keep this test independent of other commands.

-        $null = $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_UpdateAlert' -Force -ErrorAction 'SilentlyContinue'
+        try
+        {
+            $alertToRemove = $script:sqlServerObject.JobServer.Alerts['IntegrationTest_UpdateAlert']
+            if ($null -ne $alertToRemove)
+            {
+                $alertToRemove.Drop()
+            }
+        }
+        catch
+        {
+            # no-op
+        }
🧹 Nitpick comments (4)
tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1 (1)

57-60: Make setup idempotent by dropping pre-existing alerts via SMO before creating

If a prior run left the alerts behind, New-SqlDscAgentAlert will fail. Drop any leftovers first to keep the setup resilient.

         # Create test alerts for testing
+        # Ensure a clean state if alerts exist from previous runs
+        foreach ($name in @('IntegrationTest_SeverityAlert', 'IntegrationTest_MessageIdAlert'))
+        {
+            try { $script:sqlServerObject.JobServer.Alerts[$name].Drop() } catch { }
+        }
+
         $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_SeverityAlert' -Severity 16 -ErrorAction Stop
         $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_MessageIdAlert' -MessageId 50001 -ErrorAction Stop
tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 (3)

49-49: Grammar nit in comment.

Change “throw” → “throws” for correctness.

-        $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception.
+        $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throws an exception.

80-80: Minor indentation nit.

This comment line is over‑indented compared to surrounding code. Align to the usual 8 spaces inside the It block.

-                # Add SQL Server system message for testing message ID alerts
+        # Add SQL Server system message for testing message ID alerts

71-130: Optional: group scenarios into Context blocks for clearer intent.

Guidelines favor Context blocks starting with “When …”. Consider grouping the Its to improve structure (you can keep Describe‑level setup or duplicate minimal setup per Context if needed).

Example refactor sketch:

 Describe 'Set-SqlDscAgentAlert' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' {
-    It 'Should update alert severity using ServerObject parameter set' {
+    Context 'When using ServerObject parameter set' {
+        It 'Should update alert severity' {
             ...
-    It 'Should update alert message ID using ServerObject parameter set' {
+        It 'Should update alert message ID' {
             ...
-    It 'Should update alert using AlertObject parameter set' {
+    }
+
+    Context 'When using AlertObject parameter set' {
+        It 'Should update alert' {
             ...
-    It 'Should return updated alert when PassThru is specified' {
+    }
+
+    Context 'When using PassThru' {
+        It 'Should return updated alert' {
             ...
-    It 'Should throw error when alert does not exist' {
+    }
+
+    Context 'When input is invalid' {
+        It 'Should throw error when alert does not exist' {
             ...
-    It 'Should throw error when both Severity and MessageId are specified' {
+        It 'Should throw error when both Severity and MessageId are specified' {
             ...
+    }
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • Jira integration is disabled
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between babe813 and 7ded823.

📒 Files selected for processing (5)
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 (1 hunks)
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 (1 hunks)
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 (1 hunks)
  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 (1 hunks)
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1 (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1
🧰 Additional context used
📓 Path-based instructions (7)
tests/**/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

tests/**/*.ps1: All tests must use Pester and Pester v5.0 syntax
Do not test parameter validation
Test code must not exist outside of a Describe block
Each test file must contain exactly one Describe block named after the subject (public command, private function, or resource)
Each scenario/path should be in Context blocks starting with 'When'; It block descriptions should start with 'Should' and must call the subject; results and assertions stay within the same It; BeforeAll/BeforeEach must not call the subject
Use BeforeAll/BeforeEach/AfterAll/AfterEach inside Context, placed near the It blocks using them; duplication across contexts is acceptable; AfterAll can clean up; use BeforeEach/AfterEach sparingly
Use localized strings in tests only when necessary, retrieving values from $script:localizedData inside InModuleScope
Files that need to be mocked in tests must be created in Pester's $TestDrive

Files:

  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
tests/Integration/Commands/*.Integration.Tests.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

tests/Integration/Commands/*.Integration.Tests.ps1: Integration tests must exist for all public commands, not mock any commands, be placed at tests/Integration/Commands, and be named .Integration.Tests.ps1
In CI, integration tests must use Get-ComputerName when the computer name is needed
Include the standard integration test setup block (BeforeDiscovery/BeforeAll with module loading) before the first Describe block

Files:

  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
**/*.ps1

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.ps1: PowerShell files must be UTF-8 without BOM and end with a newline
Try to limit lines to 120 characters
Use 4 spaces for indentation; never use tabs
Use '#' for single-line comments
Use <# ... #> for multiline comments; indent the multiline text 4 spaces
Use descriptive, clear, full names for variables, parameters, and function names; names must be more than 2 characters; no abbreviations
Use camelCase for local variable names
Never use Write-Host
Never use backtick (`) for line continuation
Use splatting to reduce line length
PowerShell reserved keywords should be lowercase
Use single quotes for string literals whenever possible; use double quotes only when interpolation is needed
Hashtable properties should be PascalCase and each on a separate line
When comparing to $null, place $null on the left side of the comparison

Files:

  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
**

⚙️ CodeRabbit configuration file

**: # DSC Community Guidelines

Terminology

  • Command: Public command
  • Function: Private function
  • Resource: DSC class-based resource

Build & Test Workflow

  • Run project scripts in PowerShell from repository root
  • Build after source changes: .\build.ps1 -Tasks build
  • Test workflow: Build → Invoke-Pester -Path @('<test paths>') -Output Detailed
  • New session required after class changes

File Organization

  • Public commands: source/Public/{CommandName}.ps1
  • Private functions: source/Private/{FunctionName}.ps1
  • Unit tests: tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1
  • Integration tests: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Requirements

  • Always update CHANGELOG.md Unreleased section
  • Localize all strings using string keys
  • Check DscResource.Common before creating private functions
  • Separate reusable logic into private functions
  • Add unit tests for all commands/functions/resources
  • Add integration tests for all public commands and resources

Files:

  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
**/*.ps?(m|d)1

⚙️ CodeRabbit configuration file

**/*.ps?(m|d)1: # PowerShell Guidelines

Naming

  • Use descriptive names (3+ characters, no abbreviations)
  • Functions: PascalCase with Verb-Noun format using approved verbs
  • Parameters: PascalCase
  • Variables: camelCase
  • Keywords: lower-case
  • Classes: PascalCase
  • Include scope for script/global/environment variables: $script:, $global:, $env:

Formatting

Indentation & Spacing

  • Use 4 spaces (no tabs)
  • One space around operators: $a = 1 + 2
  • One space between type and variable: [String] $name
  • One space between keyword and parenthesis: if ($condition)
  • No spaces on empty lines
  • Try to limit lines to 120 characters

Braces

  • Newline before opening brace (except variable assignments)
  • One newline after opening brace
  • Two newlines after closing brace (one if followed by another brace or continuation)

Quotes

  • Use single quotes unless variable expansion is needed: 'text' vs "text $variable"

Arrays

  • Single line: @('one', 'two', 'three')
  • Multi-line: each element on separate line with proper indentation
  • Do not use the unary comma operator (,) in return statements to force
    an array

Hashtables

  • Empty: @{}
  • Multi-line: each property on separate line with proper indentation
  • Properties: Use PascalCase

Comments

  • Single line: # Comment (capitalized, on own line)
  • Multi-line: <# Comment #> format (opening and closing brackets on own line), and indent text
  • No commented-out code

Comment-based help

  • Always add comment-based help to all functions and scripts
  • Comment-based help: SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, EXAMPLE sections before function/class
  • Comment-based help indentation: keywords 4 spaces, text 8 spaces
  • Include examples for all parameter sets and combinations
  • INPUTS: List each pipeline‑accepted type (one per line) with a 1‑line description.
  • OUTPUTS: List each return type (one per line) with a 1‑line description. Must match both [OutputType()] and actual ...

Files:

  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
**/*.[Tt]ests.ps1

⚙️ CodeRabbit configuration file

**/*.[Tt]ests.ps1: # Tests Guidelines

Core Requirements

  • All public commands, private functions and classes must have unit tests
  • All public commands and class-based resources must have integration tests
  • Use Pester v5 syntax only
  • One Describe block per file matching the tested entity name
  • Test code only inside Describe blocks
  • Assertions only in It blocks
  • Never test Write-Verbose, Write-Debug, or parameter binding behavior
  • Pass all mandatory parameters to avoid prompts

Structure & Scope

  • Public commands: Never use InModuleScope (unless retrieving localized strings)
  • Private functions/class resources: Always use InModuleScope
  • Each scenario = separate Context block
  • Use nested Context blocks for complex scenarios
  • Mocking in BeforeAll (BeforeEach only when required)
  • Setup/teardown in BeforeAll,BeforeEach/AfterAll,AfterEach close to usage

Syntax Rules

  • PascalCase: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
  • It descriptions start with 'Should'
  • Context descriptions start with 'When'
  • Mock variables prefix: 'mock'
  • Prefer -BeTrue/-BeFalse over -Be $true/-Be $false
  • No Should -Not -Throw - invoke commands directly

File Organization

  • Class resources: tests/Unit/Classes/{Name}.Tests.ps1
  • Public commands: tests/Unit/Public/{Name}.Tests.ps1
  • Private functions: tests/Unit/Private/{Name}.Tests.ps1

Data-Driven Tests

  • Define variables in separate BeforeDiscovery for -ForEach (close to usage)
  • -ForEach allowed on Context and It blocks
  • Keep scope close to usage context

Best Practices

  • Assign unused return objects to $null
  • Tested entity must be called from within the It blocks
  • Keep results and assertions in same It block
  • Cover all scenarios and code paths
  • Use BeforeEach and AfterEach sparingly
  • Avoid try-catch-finally for cleanup, use AfterAll or AfterEach
  • Avoid unnecessary remove/recreate cyc...

Files:

  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1

⚙️ CodeRabbit configuration file

tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1: # Integration Tests Guidelines

Requirements

  • Location Commands: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1
  • Location Resources: tests/Integration/Resources/{ResourceName}.Integration.Tests.ps1
  • No mocking - real environment only
  • Cover all scenarios and code paths
  • Use Get-ComputerName for computer names in CI
  • Avoid ExpectedMessage for Should -Throw assertions
  • Only run integration tests in CI unless explicitly instructed.
  • Call commands with -Force parameter where applicable (avoids prompting).

Required Setup Block

[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
param ()

BeforeDiscovery {
    try
    {
        if (-not (Get-Module -Name 'DscResource.Test'))
        {
            # Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
            if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
            {
                # Redirect all streams to $null, except the error stream (stream 2)
                & "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
            }

            # If the dependencies have not been resolved, this will throw an error.
            Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
        }
    }
    catch [System.IO.FileNotFoundException]
    {
        throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.'
    }
}

BeforeAll {
    $script:dscModuleName = 'SqlServerDsc'

    Import-Module -Name $script:dscModuleName -Force -ErrorAction 'Stop'
}

Files:

  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
🧠 Learnings (9)
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Unit/**/*.Tests.ps1 : Do not use Should -Not -Throw; invoke the command directly

Applied to files:

  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T10:13:30.079Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/Public/Remove-SqlDscLogin.ps1:104-108
Timestamp: 2025-08-17T10:13:30.079Z
Learning: In SqlServerDsc unit tests, SMO object stubs (like Login objects) should have properly mocked Parent properties with correct Server stub types and valid InstanceName values, rather than handling null Parent scenarios in production code.

Applied to files:

  • tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1
  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Integration tests must exist for all public commands, not mock any commands, be placed at tests/Integration/Commands, and be named <Command>.Integration.Tests.ps1

Applied to files:

  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Include the standard integration test setup block (BeforeDiscovery/BeforeAll with module loading) before the first Describe block

Applied to files:

  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to azure-pipelines.yml : Add each public command integration test script to a group within the Integration_Test_Commands_SqlServer stage in ./azure-pipelines.yml, choosing the appropriate group

Applied to files:

  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Each scenario/path should be in Context blocks starting with 'When'; It block descriptions should start with 'Should' and must call the subject; results and assertions stay within the same It; BeforeAll/BeforeEach must not call the subject

Applied to files:

  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Use BeforeAll/BeforeEach/AfterAll/AfterEach inside Context, placed near the It blocks using them; duplication across contexts is acceptable; AfterAll can clean up; use BeforeEach/AfterEach sparingly

Applied to files:

  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T09:48:55.756Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T09:48:55.756Z
Learning: Applies to tests/**/*.ps1 : Test code must not exist outside of a Describe block

Applied to files:

  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
📚 Learning: 2025-08-17T10:48:15.384Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/suffix.ps1:24-24
Timestamp: 2025-08-17T10:48:15.384Z
Learning: In source/suffix.ps1, the Write-Verbose message in the catch block for Import-SqlDscPreferredModule does not need localization because the exception message from Import-SqlDscPreferredModule is already localized by that command, making it an edge case exception to the localization guidelines.

Applied to files:

  • tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
  • GitHub Check: PSScriptAnalyzer
  • GitHub Check: PSScriptAnalyzer
🔇 Additional comments (13)
tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1 (5)

4-24: Standard integration setup block looks good

Includes the required BeforeDiscovery guard and dependency bootstrap; aligns with repo guidelines.


26-42: Module load/unload and CI flag management are correct

Good use of Import-Module/Remove-Module and temporary SqlServerDscCI env flag.


74-114: Good test structure and assertions

Contexts use the required 'When' prefix; Its use 'Should -BeTrue/-BeFalse' with result and assertion in the same block.


116-121: Error case assertion follows integration test guidance

Using plain Should -Throw (no ExpectedMessage) is correct and stable across environments/localization.


44-44: Integration test already included in CI

Confirmed that tests/Integration/Commands/Test-SqlDscAgentAlert.Integration.Tests.ps1 is referenced in azure-pipelines.yml (line 307) under the Integration_Test_Commands_SqlServer stage. No further action needed.

tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 (8)

4-24: Standard integration harness looks correct.

The BeforeDiscovery block matches the repository’s required setup and handles dependency resolution and module import robustly.


26-35: Good module bootstrap and target instance setup.

  • Module import is fail-fast.
  • CI flag and DSCSQLTEST instance selection are clear and conventional.

54-59: Connection and test alert creation: LGTM.

  • Uses numeric literal for Severity (14) per guidelines.
  • -ErrorAction Stop ensures fail-fast behavior in setup.

71-77: ServerObject parameter set path: assertions are precise.

Validates both the set field (Severity) and the reset counterpart (MessageId) explicitly. Good coverage.


92-98: MessageId path: LGTM.

  • Idempotent setup for sys.messages is solid.
  • Properly verifies mutual exclusivity by asserting Severity resets to 0 when MessageId is set.

100-112: AlertObject parameter set path: LGTM.

Clear reset, update via piped Alert object, and verification via a fresh Get to avoid stale state.


114-120: PassThru contract validated correctly.

Checks object presence and key fields (Name, Severity). Concise and effective.


122-130: Error scenarios: good negative coverage without pinning messages.

  • Uses numeric literals for numeric parameters.
  • Avoids -ExpectedMessage per guidance.

@johlju johlju merged commit 6488425 into dsccommunity:main Aug 25, 2025
25 checks passed
@johlju johlju deleted the f/refactor-sqlagentalert branch August 25, 2025 10:03
@coderabbitai coderabbitai bot mentioned this pull request Jan 3, 2026
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet