Skip to content

Invoke-ReportServerSetupAction: Expand environment variables in path parameters#2383

Merged
johlju merged 9 commits intodsccommunity:mainfrom
johlju:f/issue-#2085
Dec 31, 2025
Merged

Invoke-ReportServerSetupAction: Expand environment variables in path parameters#2383
johlju merged 9 commits intodsccommunity:mainfrom
johlju:f/issue-#2085

Conversation

@johlju
Copy link
Member

@johlju johlju commented Dec 28, 2025

Pull Request (PR) description

  • Invoke-ReportServerSetupAction
    • Now uses Format-Path with -ExpandEnvironmentVariable to expand environment
      variables in all path parameters (MediaPath, LogPath, InstallFolder)
      (issue #2085).

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 December 28, 2025 15:03
@coderabbitai
Copy link

coderabbitai bot commented Dec 28, 2025

Walkthrough

Adds a new public command Invoke-ReportServerSetupAction and normalizes path inputs by running MediaPath (required) and LogPath/InstallFolder (when bound) through Format-Path with environment-variable expansion before invoking the setup process.

Changes

Cohort / File(s) Summary
Changelog
CHANGELOG.md
Documents the new public command Invoke-ReportServerSetupAction and that path parameters now expand environment variables via Format-Path.
Private action implementation
source/Private/Invoke-ReportServerSetupAction.ps1
New/updated implementation: formats MediaPath (required) and conditionally LogPath/InstallFolder using Format-Path with EnsureDriveLetterRoot, NoTrailingDirectorySeparator, ExpandEnvironmentVariable, ErrorAction=Stop; uses formatted values when building and calling Start-SqlSetupProcess.
Unit tests — Private action
tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
Adds tests that mock Format-Path, Test-Path, and Start-SqlSetupProcess to assert environment-variable expansion for MediaPath, LogPath, and InstallFolder, and that Start-SqlSetupProcess receives expanded paths.
Unit tests — Class tests
tests/Unit/Classes/...
tests/Unit/Classes/SqlAudit.Tests.ps1, tests/Unit/Classes/SqlDatabasePermission.Tests.ps1, tests/Unit/Classes/SqlPermission.Tests.ps1
Introduces mocks for GetCurrentState() across many Get/Set/Test flows, reorders mocking sequence, and adjusts expectations (some Set tests now expect Modify() to be called).
Unit test stubs
tests/Unit/Stubs/SMO.cs
Adds public fields and Connect()/Disconnect() methods to Microsoft.SqlServer.Management.Smo.ServerConnection test stub to support connection-related test scenarios.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Caller as Caller (Invoke-ReportServerSetupAction)
participant Formatter as Format-Path (DscResource.Common)
participant FS as FileSystem / Test-Path
participant Setup as Start-SqlSetupProcess

Note over Caller,Formatter: Normalize path inputs
Caller->>Formatter: Format MediaPath (EnsureDriveLetterRoot, NoTrailingDirectorySeparator, ExpandEnvironmentVariable)
Formatter-->>Caller: formatted MediaPath
alt LogPath/InstallFolder bound
Caller->>Formatter: Format LogPath / InstallFolder (same flags)
Formatter-->>Caller: formatted LogPath / InstallFolder
end
Caller->>FS: Test-Path(formatted MediaPath)
FS-->>Caller: exists (true/false)
Caller->>Setup: Start process with FilePath=formatted MediaPath and ArgumentList including formatted paths
Setup-->>Caller: exit code / result

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Pre-merge checks

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Changes to SMO.cs stubs, SqlAudit, SqlDatabasePermission, and SqlPermission test files appear to be unrelated to the primary objective of expanding environment variables in Invoke-ReportServerSetupAction path parameters. Review and clarify why test stubs and unrelated class tests were modified. Consider separating these changes into a distinct PR if they address different issues.
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: expanding environment variables in path parameters of Invoke-ReportServerSetupAction using Format-Path.
Description check ✅ Passed The description is directly related to the changeset, clearly explaining the use of Format-Path with -ExpandEnvironmentVariable for path parameters and referencing the linked issue.
Linked Issues check ✅ Passed The PR fully addresses issue #2085 by implementing Format-Path with -ExpandEnvironmentVariable for all path parameters (MediaPath, LogPath, InstallFolder) as suggested.

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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

🧹 Nitpick comments (1)
tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1 (1)

433-559: LGTM! Comprehensive test coverage for environment variable expansion.

The new test context effectively verifies that:

  • Format-Path is called with the correct parameters (-EnsureDriveLetterRoot, -NoTrailingDirectorySeparator, -ExpandEnvironmentVariable) for MediaPath, LogPath, and InstallFolder
  • Expanded paths are properly passed to Start-SqlSetupProcess in both the FilePath parameter and ArgumentList

The test structure follows Pester v5 and DSC Community guidelines correctly, with proper use of InModuleScope, BeforeAll for mock setup, and appropriate assertions.

Optional: Consider similar test coverage for Uninstall and Repair actions

While the Install action tests are comprehensive, consider adding similar environment variable expansion tests for the Uninstall and Repair actions to ensure consistent behavior across all setup actions. However, if the implementation is identical across actions, testing one action may be sufficient to avoid test duplication.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 82bd423 and 1f0ec53.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • source/Private/Invoke-ReportServerSetupAction.ps1
  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
🧰 Additional context used
📓 Path-based instructions (12)
**/*.ps1

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

**/*.ps1: Format public commands as {Verb}-SqlDsc{Noun} following PowerShell naming conventions
Format private functions as {Verb}-{Noun} following PowerShell naming conventions

Files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
  • source/Private/Invoke-ReportServerSetupAction.ps1
**/*.[Tt]ests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-pester.instructions.md)

**/*.[Tt]ests.ps1: 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
Test code only inside Describe blocks
Assertions only in It blocks
Never test verbose messages, debug messages or parameter binding behavior
Pass all mandatory parameters to avoid prompts
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
Avoid try-catch-finally for cleanup, use AfterAll or AfterEach
Avoid unnecessary remove/recreate cycles
One Describe block per file matching the tested entity name
Context descriptions start with 'When'
It descriptions start with 'Should', must not contain 'when'
Mock variables prefix: 'mock'
Public commands: Never use InModuleScope (unless retrieving localized strings or creating an object using an internal class)
Private functions/class resources: Always use InModuleScope
Each class method = separate Context block
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
Spacing between blocks, arrange, act, and assert for readability
PascalCase: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
Use -BeTrue/-BeFalse never -Be $true/-Be $false
Never use Assert-MockCalled, use Should -Invoke instead
No Should -Not -Throw - invoke commands directly
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
Never use Mock inside InModuleScope-block
Never use param() inside -MockWith scriptblock...

Files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.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
  • Test code only inside Describe blocks
  • Assertions only in It blocks
  • Never test verbose messages, debug messages or parameter binding behavior
  • Pass all mandatory parameters to avoid prompts

Requirements

  • 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
  • Avoid try-catch-finally for cleanup, use AfterAll or AfterEach
  • Avoid unnecessary remove/recreate cycles

Naming

  • One Describe block per file matching the tested entity name
  • Context descriptions start with 'When'
  • It descriptions start with 'Should', must not contain 'when'
  • Mock variables prefix: 'mock'

Structure & Scope

  • Public commands: Never use InModuleScope (unless retrieving localized strings or creating an object using an internal class)
  • Private functions/class resources: Always use InModuleScope
  • Each class method = separate Context block
  • 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
  • Spacing between blocks, arrange, act, and assert for readability

Syntax Rules

  • PascalCase: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
  • Use -BeTrue/-BeFalse never -Be $true/-Be $false
  • Never use Assert-MockCalled, use Should -Invoke instead
  • No Should -Not -Throw - invoke commands directly
  • Never add an empty -MockWith block
  • Omit -MockWith when returning $null
  • Set $PSDefaultParameterValues for Mock:ModuleName, Should:ModuleName, `...

Files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
tests/Unit/Private/*.[Tt]ests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-pester.instructions.md)

Private functions: tests/Unit/Private/{Name}.Tests.ps1

Files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
tests/[Uu]nit/**/*.[Tt]ests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md)

tests/[Uu]nit/**/*.[Tt]ests.ps1: Test with localized strings using InModuleScope -ScriptBlock { $script:localizedData.Key }
Mock files using the $TestDrive variable (path to the test drive)
All public commands require parameter set validation tests
Use the exact setup block with BeforeDiscovery, BeforeAll, and AfterAll blocks including DscResource.Test module import and PSDefaultParameterValues configuration
Parameter set validation tests should use Get-Command with Where-Object filtering and Should assertions to verify ParameterSetName and ParameterListAsString
Parameter property tests should verify mandatory parameter attributes using Get-Command Parameters and Should -BeTrue assertions

Files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1

⚙️ CodeRabbit configuration file

tests/[Uu]nit/**/*.[Tt]ests.ps1: # Unit Tests Guidelines

  • Test with localized strings: Use InModuleScope -ScriptBlock { $script:localizedData.Key }
  • Mock files: Use $TestDrive variable (path to the test drive)
  • All public commands require parameter set validation tests
  • After modifying classes, always run tests in new session (for changes to take effect)

Test Setup Requirements

Use this exact setup block before Describe:

[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 noop" first.'
    }
}

BeforeAll {
    $script:moduleName = '{MyModuleName}'

    Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'

    $PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:moduleName
    $PSDefaultParameterValues['Mock:ModuleName'] = $script:moduleName
    $PSDefaultParameterValues['Should:ModuleName'] = $script:moduleName
}

AfterAll {
    $PSDefaultParameterValues.Remove('InModuleScope:ModuleName')
    $PSDefaultParameterValues.Remove('Mock:ModuleNam...

Files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
tests/Unit/**/*.Tests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines.instructions.md)

Unit tests should be located in tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1

Files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
**/*.{ps1,psm1,psd1}

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-powershell.instructions.md)

**/*.{ps1,psm1,psd1}: Use descriptive names (3+ characters, no abbreviations) for functions, parameters, variables, and classes
Functions: Use PascalCase with Verb-Noun format using approved verbs
Parameters: Use PascalCase naming
Variables: Use camelCase naming
Keywords: Use lower-case
Classes: Use PascalCase naming
Include scope for script/global/environment variables: $script:, $global:, $env:
Use 4 spaces for indentation (no tabs)
Use one space around operators: $a = 1 + 2
Use one space between type and variable: [String] $name
Use one space between keyword and parenthesis: if ($condition)
No spaces on empty lines
Limit lines to 120 characters
Place newline before opening brace (except variable assignments)
Place one newline after opening brace
Place two newlines after closing brace (one if followed by another brace or continuation)
Use single quotes unless variable expansion is needed: 'text' vs "text $variable"
For single-line arrays use: @('one', 'two', 'three')
For multi-line arrays: place each element on separate line with proper indentation
Do not use the unary comma operator (,) in return statements to force an array
For empty hashtables use: @{}
For hashtables: place each property on separate line with proper indentation and use PascalCase for property names
Single-line comments: use # Comment format (capitalized, on own line)
Multi-line comments: use <# Comment #> format (opening and closing brackets on own line with indented text)
No commented-out code
Always add comment-based help to all functions and scripts with SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, and EXAMPLE sections before function/class
Comment-based help indentation: keywords 4 spaces, text 8 spaces
Include examples in comment-based help for all parameter sets and combinations
INPUTS section in comment-based help: List each pipeline-accepted type as inline code with a 1-line description, repeat keyword for each input type, specify None. if there are no inp...

Files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
  • source/Private/Invoke-ReportServerSetupAction.ps1
**

⚙️ CodeRabbit configuration file

**: # DSC Community Guidelines

Terminology

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

Build & Test Workflow Requirements

  • Run PowerShell script files from repository root
  • Setup build and test environment (once per pwsh session): ./build.ps1 -Tasks noop
  • Build project before running tests: ./build.ps1 -Tasks build
  • Always run tests in new pwsh session: Invoke-Pester -Path @({test paths}) -Output Detailed

File Organization

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

Requirements

  • Follow instructions over existing code patterns
  • Follow PowerShell style and test guideline instructions strictly
  • Always update CHANGELOG.md Unreleased section
  • Localize all strings using string keys; remove any orphaned string keys
  • Check DscResource.Common before creating private functions
  • Separate reusable logic into private functions
  • DSC resources should always be created as class-based resources
  • Add unit tests for all commands/functions/resources
  • Add integration tests for all public commands and resources

Files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
  • source/Private/Invoke-ReportServerSetupAction.ps1
  • CHANGELOG.md
{**/*.ps1,**/*.psm1,**/*.psd1}

⚙️ CodeRabbit configuration file

{**/*.ps1,**/*.psm1,**/*.psd1}: # 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:

File naming

  • Class files: ###.ClassName.ps1 format (e.g. 001.SqlReason.ps1, 004.StartupParameters.ps1)

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: @{}
  • 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 as inline code with a 1‑line description...

Files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
  • source/Private/Invoke-ReportServerSetupAction.ps1
source/**/*.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-localization.instructions.md)

source/**/*.ps1: Localize all Write-Debug, Write-Verbose, Write-Error, Write-Warning and $PSCmdlet.ThrowTerminatingError() messages in PowerShell scripts
Use localized string keys from $script:localizedData, not hardcoded strings, in diagnostic messages
Reference localized strings using the syntax: Write-Verbose -Message ($script:localizedData.KeyName -f $value1)

Localize all strings using string keys; remove any orphaned string keys

Files:

  • source/Private/Invoke-ReportServerSetupAction.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/{MyModuleName}.strings.psd1
  • Class resources: source/en-US/{ResourceClassName}.strings.psd1

Key Naming Patterns

  • Format: Verb_FunctionName_Action (underscore separators), e.g. Get_Database_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/Private/Invoke-ReportServerSetupAction.ps1
source/Private/*.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines.instructions.md)

Private functions should be located in source/Private/{FunctionName}.ps1

Files:

  • source/Private/Invoke-ReportServerSetupAction.ps1
CHANGELOG.md

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-changelog.instructions.md)

CHANGELOG.md: Always update the Unreleased section in CHANGELOG.md
Use Keep a Changelog format in CHANGELOG.md
Describe notable changes briefly in CHANGELOG.md, ≤2 items per change type
Reference issues using format issue #<issue_number> in CHANGELOG.md
No empty lines between list items in same section of CHANGELOG.md
Skip adding entry if same change already exists in Unreleased section of CHANGELOG.md
No duplicate sections or items in Unreleased section of CHANGELOG.md

Always update CHANGELOG.md Unreleased section

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 #<issue_number>
  • No empty lines between list items in same section
  • Skip adding entry if same change already exists in Unreleased section
  • No duplicate sections or items in Unreleased section

Files:

  • CHANGELOG.md
**/*.md

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-markdown.instructions.md)

**/*.md: Wrap lines at word boundaries when over 80 characters (except tables/code blocks)
Use 2 spaces for indentation in Markdown files
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)
Escape backslashes in file paths only (not in code blocks)
Code blocks must specify language identifiers
Format parameters using bold in Markdown documentation
Format values and literals using inline code in Markdown documentation
Format resource/module/product names using italic in Markdown documentation
Format commands/files/paths using inline code in Markdown documentation

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)
  • Escape backslashes in file paths only (not in code blocks)
  • 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 (21)
📚 Learning: 2025-11-27T18:00:20.934Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-11-27T18:00:20.934Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : Mock files using the `$TestDrive` variable (path to the test drive)

Applied to files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Mock variables prefix: 'mock'

Applied to files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Use nested `Context` blocks for complex scenarios

Applied to files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-11-27T17:58:02.422Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: Applies to **/tests/**/*.tests.ps1 : Add `$env:SqlServerDscCI = $true` in `BeforeAll` block and remove in `AfterAll` block of unit tests

Applied to files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Each scenario = separate `Context` block

Applied to files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : `Context` descriptions start with 'When'

Applied to files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-11-27T17:58:02.422Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: Applies to **/tests/**/*.tests.ps1 : When unit tests test classes or commands containing SMO types like `[Microsoft.SqlServer.Management.Smo.*]`, ensure they are properly stubbed in SMO.cs

Applied to files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to tests/Unit/Private/*.[Tt]ests.ps1 : Private functions: `tests/Unit/Private/{Name}.Tests.ps1`

Applied to files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Mocking in `BeforeAll` (`BeforeEach` only when required)

Applied to files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Cover all scenarios and code paths

Applied to files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-08-17T10:15:48.194Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 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/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Set `$PSDefaultParameterValues` for `Mock:ModuleName`, `Should:ModuleName`, `InModuleScope:ModuleName`

Applied to files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Never use `Mock` inside `InModuleScope`-block

Applied to files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Avoid unnecessary remove/recreate cycles

Applied to files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-12-24T18:09:36.232Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-12-24T18:09:36.232Z
Learning: Applies to **/*.{ps1,psm1,psd1} : Set `$ErrorActionPreference = 'Stop'` before commands using `-ErrorAction 'Stop'` and restore previous value directly after invocation (do not use try-catch-finally)

Applied to files:

  • source/Private/Invoke-ReportServerSetupAction.ps1
📚 Learning: 2025-12-24T18:09:36.232Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-12-24T18:09:36.232Z
Learning: Applies to **/*.{ps1,psm1,psd1} : Never output sensitive data/secrets in any output stream

Applied to files:

  • source/Private/Invoke-ReportServerSetupAction.ps1
📚 Learning: 2025-12-24T18:09:36.232Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-12-24T18:09:36.232Z
Learning: Applies to **/*.{ps1,psm1,psd1} : Don't redefine reserved parameters (Verbose, Debug, etc.)

Applied to files:

  • source/Private/Invoke-ReportServerSetupAction.ps1
📚 Learning: 2025-12-24T18:09:36.232Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-12-24T18:09:36.232Z
Learning: Applies to **/*.{ps1,psm1,psd1} : Avoid global variables (exception: `$global:DSCMachineStatus`)

Applied to files:

  • source/Private/Invoke-ReportServerSetupAction.ps1
📚 Learning: 2025-09-06T19:18:18.857Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 0
File: :0-0
Timestamp: 2025-09-06T19:18:18.857Z
Learning: When a PowerShell command uses PSCmdlet.ShouldProcess and is called with -Verbose, the description message from ShouldProcess is automatically output as a verbose message. Therefore, there is no need to use Write-Verbose before or inside PSCmdlet.ShouldProcess blocks as PSCmdlet.ShouldProcess already provides the required verbose message through its description parameter.

Applied to files:

  • source/Private/Invoke-ReportServerSetupAction.ps1
📚 Learning: 2025-12-24T18:09:36.232Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-12-24T18:09:36.232Z
Learning: Applies to **/*.{ps1,psm1,psd1} : `$PSCmdlet.ShouldProcess` must use the required pattern with `$descriptionMessage`, `$confirmationMessage`, and `$captionMessage`

Applied to files:

  • source/Private/Invoke-ReportServerSetupAction.ps1
📚 Learning: 2025-11-27T17:58:02.422Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: Applies to **/resources/**/*.ps1 : Add `InstanceName`, `ServerName`, and `Credential` to `$this.ExcludeDscProperties` in Database Engine resources

Applied to files:

  • CHANGELOG.md
⏰ 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)
CHANGELOG.md (1)

10-13: Unreleased changelog entry for Invoke-ReportServerSetupAction looks consistent

The new Added entry is concise, correctly references [issue #2085], and follows the existing bullet/indentation and link style in this section. No changes needed.

@codecov
Copy link

codecov bot commented Dec 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94%. Comparing base (352435f) to head (efba844).
⚠️ Report is 38 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #2383   +/-   ##
=====================================
- Coverage     94%     94%   -1%     
=====================================
  Files        174     174           
  Lines      10095   10104    +9     
=====================================
+ Hits        9521    9523    +2     
- Misses       574     581    +7     
Flag Coverage Δ
unit 94% <100%> (-1%) ⬇️
Files with missing lines Coverage Δ
source/Private/Invoke-ReportServerSetupAction.ps1 98% <100%> (+<1%) ⬆️

... and 2 files 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: 0

🧹 Nitpick comments (3)
tests/Unit/Classes/SqlPermission.Tests.ps1 (1)

964-1003: Set() non-desired state: GetCurrentState + Compare wiring correctly drives a Modify() call

The mocked GetCurrentState returning only Grant ConnectSql combined with the Compare mock that expects ConnectSql + AlterAnyEndpoint is a solid way to force a single Modify() invocation. One small nit: the It description ("Should not call method Modify()") now contradicts the Should -Be 1 assertion; consider updating the description for clarity.

tests/Unit/Classes/SqlAudit.Tests.ps1 (1)

295-313: Set() non-desired state: verify intended relationship between Path values

The GetCurrentState mock reports Path = 'C:\Path' while the Compare mock says ExpectedValue = 'C:\NewFolder' and ActualValue = 'C:\Path', but the instance itself was initialized with Path = 'C:\Temp'. Functionally the test works because Compare drives the behavior, yet the three different path literals can be confusing; consider aligning the instance Path to the expected value or adding a brief comment describing the intended “desired vs current vs initial” roles.

tests/Unit/Classes/SqlDatabasePermission.Tests.ps1 (1)

986-1008: Set() non-desired state: GetCurrentState + Compare clearly encode missing DB permission

Here GetCurrentState reports the current Permission set (only Grant Connect), while Compare describes the extra expected Update grant vs the actual value. That combination nicely forces a single Modify() call in the test. As in SqlPermission.Tests.ps1, the It description still says "Should not call method Modify()" while asserting a count of 1; consider renaming the test for accuracy.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3998c00 and 124fc78.

📒 Files selected for processing (4)
  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Stubs/SMO.cs
🧰 Additional context used
📓 Path-based instructions (8)
**/*.ps1

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

**/*.ps1: Format public commands as {Verb}-SqlDsc{Noun} following PowerShell naming conventions
Format private functions as {Verb}-{Noun} following PowerShell naming conventions

Files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
**/*.[Tt]ests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-pester.instructions.md)

**/*.[Tt]ests.ps1: 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
Test code only inside Describe blocks
Assertions only in It blocks
Never test verbose messages, debug messages or parameter binding behavior
Pass all mandatory parameters to avoid prompts
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
Avoid try-catch-finally for cleanup, use AfterAll or AfterEach
Avoid unnecessary remove/recreate cycles
One Describe block per file matching the tested entity name
Context descriptions start with 'When'
It descriptions start with 'Should', must not contain 'when'
Mock variables prefix: 'mock'
Public commands: Never use InModuleScope (unless retrieving localized strings or creating an object using an internal class)
Private functions/class resources: Always use InModuleScope
Each class method = separate Context block
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
Spacing between blocks, arrange, act, and assert for readability
PascalCase: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
Use -BeTrue/-BeFalse never -Be $true/-Be $false
Never use Assert-MockCalled, use Should -Invoke instead
No Should -Not -Throw - invoke commands directly
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
Never use Mock inside InModuleScope-block
Never use param() inside -MockWith scriptblock...

Files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.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
  • Test code only inside Describe blocks
  • Assertions only in It blocks
  • Never test verbose messages, debug messages or parameter binding behavior
  • Pass all mandatory parameters to avoid prompts

Requirements

  • 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
  • Avoid try-catch-finally for cleanup, use AfterAll or AfterEach
  • Avoid unnecessary remove/recreate cycles

Naming

  • One Describe block per file matching the tested entity name
  • Context descriptions start with 'When'
  • It descriptions start with 'Should', must not contain 'when'
  • Mock variables prefix: 'mock'

Structure & Scope

  • Public commands: Never use InModuleScope (unless retrieving localized strings or creating an object using an internal class)
  • Private functions/class resources: Always use InModuleScope
  • Each class method = separate Context block
  • 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
  • Spacing between blocks, arrange, act, and assert for readability

Syntax Rules

  • PascalCase: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
  • Use -BeTrue/-BeFalse never -Be $true/-Be $false
  • Never use Assert-MockCalled, use Should -Invoke instead
  • No Should -Not -Throw - invoke commands directly
  • Never add an empty -MockWith block
  • Omit -MockWith when returning $null
  • Set $PSDefaultParameterValues for Mock:ModuleName, Should:ModuleName, `...

Files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
tests/Unit/Classes/*.[Tt]ests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-pester.instructions.md)

Class resources: tests/Unit/Classes/{Name}.Tests.ps1

Files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
tests/[Uu]nit/**/*.[Tt]ests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md)

tests/[Uu]nit/**/*.[Tt]ests.ps1: Test with localized strings using InModuleScope -ScriptBlock { $script:localizedData.Key }
Mock files using the $TestDrive variable (path to the test drive)
All public commands require parameter set validation tests
Use the exact setup block with BeforeDiscovery, BeforeAll, and AfterAll blocks including DscResource.Test module import and PSDefaultParameterValues configuration
Parameter set validation tests should use Get-Command with Where-Object filtering and Should assertions to verify ParameterSetName and ParameterListAsString
Parameter property tests should verify mandatory parameter attributes using Get-Command Parameters and Should -BeTrue assertions

Files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1

⚙️ CodeRabbit configuration file

tests/[Uu]nit/**/*.[Tt]ests.ps1: # Unit Tests Guidelines

  • Test with localized strings: Use InModuleScope -ScriptBlock { $script:localizedData.Key }
  • Mock files: Use $TestDrive variable (path to the test drive)
  • All public commands require parameter set validation tests
  • After modifying classes, always run tests in new session (for changes to take effect)

Test Setup Requirements

Use this exact setup block before Describe:

[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 noop" first.'
    }
}

BeforeAll {
    $script:moduleName = '{MyModuleName}'

    Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'

    $PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:moduleName
    $PSDefaultParameterValues['Mock:ModuleName'] = $script:moduleName
    $PSDefaultParameterValues['Should:ModuleName'] = $script:moduleName
}

AfterAll {
    $PSDefaultParameterValues.Remove('InModuleScope:ModuleName')
    $PSDefaultParameterValues.Remove('Mock:ModuleNam...

Files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
tests/Unit/**/*.Tests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines.instructions.md)

Unit tests should be located in tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1

Files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
**/*.{ps1,psm1,psd1}

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-powershell.instructions.md)

**/*.{ps1,psm1,psd1}: Use descriptive names (3+ characters, no abbreviations) for functions, parameters, variables, and classes
Functions: Use PascalCase with Verb-Noun format using approved verbs
Parameters: Use PascalCase naming
Variables: Use camelCase naming
Keywords: Use lower-case
Classes: Use PascalCase naming
Include scope for script/global/environment variables: $script:, $global:, $env:
Use 4 spaces for indentation (no tabs)
Use one space around operators: $a = 1 + 2
Use one space between type and variable: [String] $name
Use one space between keyword and parenthesis: if ($condition)
No spaces on empty lines
Limit lines to 120 characters
Place newline before opening brace (except variable assignments)
Place one newline after opening brace
Place two newlines after closing brace (one if followed by another brace or continuation)
Use single quotes unless variable expansion is needed: 'text' vs "text $variable"
For single-line arrays use: @('one', 'two', 'three')
For multi-line arrays: place each element on separate line with proper indentation
Do not use the unary comma operator (,) in return statements to force an array
For empty hashtables use: @{}
For hashtables: place each property on separate line with proper indentation and use PascalCase for property names
Single-line comments: use # Comment format (capitalized, on own line)
Multi-line comments: use <# Comment #> format (opening and closing brackets on own line with indented text)
No commented-out code
Always add comment-based help to all functions and scripts with SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, and EXAMPLE sections before function/class
Comment-based help indentation: keywords 4 spaces, text 8 spaces
Include examples in comment-based help for all parameter sets and combinations
INPUTS section in comment-based help: List each pipeline-accepted type as inline code with a 1-line description, repeat keyword for each input type, specify None. if there are no inp...

Files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
**

⚙️ CodeRabbit configuration file

**: # DSC Community Guidelines

Terminology

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

Build & Test Workflow Requirements

  • Run PowerShell script files from repository root
  • Setup build and test environment (once per pwsh session): ./build.ps1 -Tasks noop
  • Build project before running tests: ./build.ps1 -Tasks build
  • Always run tests in new pwsh session: Invoke-Pester -Path @({test paths}) -Output Detailed

File Organization

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

Requirements

  • Follow instructions over existing code patterns
  • Follow PowerShell style and test guideline instructions strictly
  • Always update CHANGELOG.md Unreleased section
  • Localize all strings using string keys; remove any orphaned string keys
  • Check DscResource.Common before creating private functions
  • Separate reusable logic into private functions
  • DSC resources should always be created as class-based resources
  • Add unit tests for all commands/functions/resources
  • Add integration tests for all public commands and resources

Files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Stubs/SMO.cs
{**/*.ps1,**/*.psm1,**/*.psd1}

⚙️ CodeRabbit configuration file

{**/*.ps1,**/*.psm1,**/*.psd1}: # 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:

File naming

  • Class files: ###.ClassName.ps1 format (e.g. 001.SqlReason.ps1, 004.StartupParameters.ps1)

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: @{}
  • 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 as inline code with a 1‑line description...

Files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
🧠 Learnings (14)
📚 Learning: 2025-11-27T17:58:02.422Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: Applies to **/tests/**/*.tests.ps1 : When unit tests test classes or commands containing SMO types like `[Microsoft.SqlServer.Management.Smo.*]`, ensure they are properly stubbed in SMO.cs

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Stubs/SMO.cs
📚 Learning: 2025-11-27T17:58:02.422Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: Applies to **/tests/**/*.tests.ps1 : In unit tests: use SMO stub types from SMO.cs, never mock SMO types

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Stubs/SMO.cs
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Mocking in `BeforeAll` (`BeforeEach` only when required)

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
📚 Learning: 2025-11-27T17:58:02.422Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: Applies to **/tests/**/*.tests.ps1 : Add `$env:SqlServerDscCI = $true` in `BeforeAll` block and remove in `AfterAll` block of unit tests

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
📚 Learning: 2025-11-27T17:58:02.422Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: After changing SMO stub types in SMO.cs, run tests in a new PowerShell session for changes to take effect

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Stubs/SMO.cs
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Mock variables prefix: 'mock'

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Never use `Mock` inside `InModuleScope`-block

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
📚 Learning: 2025-11-27T18:00:20.934Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-11-27T18:00:20.934Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : Mock files using the `$TestDrive` variable (path to the test drive)

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Omit `-MockWith` when returning `$null`

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
📚 Learning: 2025-08-17T10:13:30.079Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 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/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Stubs/SMO.cs
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Set `$PSDefaultParameterValues` for `Mock:ModuleName`, `Should:ModuleName`, `InModuleScope:ModuleName`

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Never add an empty `-MockWith` block

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Never use `Assert-MockCalled`, use `Should -Invoke` instead

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
📚 Learning: 2025-11-27T17:58:02.422Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: Applies to **/tests/Integration/**/*.ps1 : Integration tests: use `Connect-SqlDscDatabaseEngine` for SQL Server DB session with correct CI credentials, and always follow with `Disconnect-SqlDscDatabaseEngine`

Applied to files:

  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.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
🔇 Additional comments (11)
tests/Unit/Stubs/SMO.cs (2)

1366-1370: Connect/Disconnect method stubs look correct.

The technical implementation of these method stubs follows the correct pattern (empty void methods matching other stubs in the file). However, the same verification concern from the previous comment applies regarding their necessity for this PR.

Based on learnings: After these SMO stub changes are confirmed as needed, remember to run tests in a new PowerShell session for the changes to take effect.


1347-1361: Verify necessity of ServerConnection stub additions for this PR.

These ServerConnection stub additions (connection properties like ServerInstance, ConnectTimeout, LoginSecure, etc.) appear unrelated to the PR objective of expanding environment variables in Report Server setup action path parameters. The SMO.cs comments explicitly indicate ServerConnection is used by SqlAGDatabase, Invoke-SqlDscScalarQuery, and Connect-SQL—not Invoke-ReportServerSetupAction.

Confirm whether:

  1. These changes are intentionally bundled or accidentally included from another branch
  2. Any new unit tests for ServerConnection were added that depend on these stub properties
tests/Unit/Classes/SqlPermission.Tests.ps1 (3)

922-943: Set() desired-state: GetCurrentState mock is consistent with desired configuration

Returning Name, InstanceName, and the full ServerPermission[] set that matches the desired state is exactly what the base Get()/Set() path expects, and chaining via -PassThru into the Compare mock keeps the setup clean. Looks good and matches the existing GetCurrentState mocking pattern in this file.


1043-1065: Test() desired-state: GetCurrentState mock makes the $true result well-founded

The new GetCurrentState hashtable mirrors the desired Name, InstanceName, and Permission set, and Compare returning $null cleanly models "no drift", so the Test() path returning $true is well justified and aligned with other resource tests.


1082-1103: Test() non-desired state: mocked GetCurrentState/Compare pairing is coherent

Here GetCurrentState provides the current Permission set and the Compare mock reports the missing AlterAnyEndpoint grant, giving a clear reason for Test() to return $false. The shape of the hashtables and the states used are consistent with the rest of the SqlPermission tests.

tests/Unit/Classes/SqlAudit.Tests.ps1 (3)

263-279: Set() desired-state: GetCurrentState mock correctly models an already-correct File audit

The mocked GetCurrentState returning Name, InstanceName, and Path 'C:\Temp' matches the constructed instance, and with Compare returning $null this gives a clean "no-op" scenario for Set() where Modify() should not be called.


341-357: Test() desired-state: GetCurrentState + Compare mocks give a solid $true outcome

For the Test() happy path, the GetCurrentState hashtable matches the desired Name/InstanceName/Path, and Compare returning $null keeps the semantics clear: no differences => Test() returns $true. This mirrors the Set() desired-state setup.


370-395: Test() non-desired state: mocked drift on Path is clearly expressed

The GetCurrentState mock returning Path = 'C:\WrongFolder' combined with Compare yielding a single diff entry for Path (expected 'C:\Temp', actual 'C:\WrongFolder') cleanly explains why Test() returns $false. The structure of the diff object matches how other tests in this file assert Reasons/drift.

tests/Unit/Classes/SqlDatabasePermission.Tests.ps1 (3)

944-966: Set() desired-state: GetCurrentState mock matches desired DB permissions

The mocked GetCurrentState now returns Name, DatabaseName, InstanceName, and a DatabasePermission[] identical to the desired state, and Compare returns $null, so the base Set() path correctly sees “no changes required” and leaves Modify() untouched. This is consistent with the SqlPermission pattern.


1068-1090: Test() desired-state: GetCurrentState mock underpins the $true result

The new GetCurrentState hashtable mirrors the desired Name/DatabaseName/InstanceName and permission array, and with Compare returning $null the Test() implementation has a solid basis for returning $true. This aligns with the updated Set() desired-state setup.


1108-1130: Test() non-desired state: drift on Permission is modeled consistently

For the non-desired Test() scenario, GetCurrentState again provides the current Permission snapshot, and the Compare mock returns an Expected/Actual pair that adds 'Update' to the expected grant set. That mirrors the Set() non-desired scenario and makes the $false outcome from Test() easy to reason about.

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

🧹 Nitpick comments (1)
CHANGELOG.md (1)

10-13: Clarify scope of Invoke-ReportServerSetupAction and consider section placement

The entry looks consistent with the existing changelog style, but two small tweaks would reduce ambiguity:

  1. Make it explicit that this is a private helper, not a new public command, e.g.:
Suggested wording tweak
- - `Invoke-ReportServerSetupAction`
-   - Now uses `Format-Path` with `-ExpandEnvironmentVariable` to expand environment
-     variables in all path parameters (`MediaPath`, `LogPath`, `InstallFolder`)
-     ([issue #2085](https://github.com/dsccommunity/SqlServerDsc/issues/2085)).
+ - `Invoke-ReportServerSetupAction` (private helper)
+   - Now uses `Format-Path` with `-ExpandEnvironmentVariable` to expand environment
+     variables in all path parameters (`MediaPath`, `LogPath`, `InstallFolder`)
+     ([issue #2085](https://github.com/dsccommunity/SqlServerDsc/issues/2085)).
  1. (Optional) Since this change fixes environment-variable expansion for existing parameters rather than introducing a new feature, you may want to move this bullet under the Unreleased Fixed section instead of Added, to better match Keep a Changelog semantics.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 124fc78 and e539fc7.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
🧰 Additional context used
📓 Path-based instructions (11)
**/*.ps1

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

**/*.ps1: Format public commands as {Verb}-SqlDsc{Noun} following PowerShell naming conventions
Format private functions as {Verb}-{Noun} following PowerShell naming conventions

Files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
**/*.[Tt]ests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-pester.instructions.md)

**/*.[Tt]ests.ps1: 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
Test code only inside Describe blocks
Assertions only in It blocks
Never test verbose messages, debug messages or parameter binding behavior
Pass all mandatory parameters to avoid prompts
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
Avoid try-catch-finally for cleanup, use AfterAll or AfterEach
Avoid unnecessary remove/recreate cycles
One Describe block per file matching the tested entity name
Context descriptions start with 'When'
It descriptions start with 'Should', must not contain 'when'
Mock variables prefix: 'mock'
Public commands: Never use InModuleScope (unless retrieving localized strings or creating an object using an internal class)
Private functions/class resources: Always use InModuleScope
Each class method = separate Context block
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
Spacing between blocks, arrange, act, and assert for readability
PascalCase: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
Use -BeTrue/-BeFalse never -Be $true/-Be $false
Never use Assert-MockCalled, use Should -Invoke instead
No Should -Not -Throw - invoke commands directly
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
Never use Mock inside InModuleScope-block
Never use param() inside -MockWith scriptblock...

Files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.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
  • Test code only inside Describe blocks
  • Assertions only in It blocks
  • Never test verbose messages, debug messages or parameter binding behavior
  • Pass all mandatory parameters to avoid prompts

Requirements

  • 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
  • Avoid try-catch-finally for cleanup, use AfterAll or AfterEach
  • Avoid unnecessary remove/recreate cycles

Naming

  • One Describe block per file matching the tested entity name
  • Context descriptions start with 'When'
  • It descriptions start with 'Should', must not contain 'when'
  • Mock variables prefix: 'mock'

Structure & Scope

  • Public commands: Never use InModuleScope (unless retrieving localized strings or creating an object using an internal class)
  • Private functions/class resources: Always use InModuleScope
  • Each class method = separate Context block
  • 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
  • Spacing between blocks, arrange, act, and assert for readability

Syntax Rules

  • PascalCase: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
  • Use -BeTrue/-BeFalse never -Be $true/-Be $false
  • Never use Assert-MockCalled, use Should -Invoke instead
  • No Should -Not -Throw - invoke commands directly
  • Never add an empty -MockWith block
  • Omit -MockWith when returning $null
  • Set $PSDefaultParameterValues for Mock:ModuleName, Should:ModuleName, `...

Files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
tests/Unit/Classes/*.[Tt]ests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-pester.instructions.md)

Class resources: tests/Unit/Classes/{Name}.Tests.ps1

Files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
tests/Unit/**/*.Tests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines.instructions.md)

Unit tests should be located in tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1

Files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
**/*.{ps1,psm1,psd1}

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-powershell.instructions.md)

**/*.{ps1,psm1,psd1}: Use descriptive names (3+ characters, no abbreviations) for functions, parameters, variables, and classes
Functions: Use PascalCase with Verb-Noun format using approved verbs
Parameters: Use PascalCase naming
Variables: Use camelCase naming
Keywords: Use lower-case
Classes: Use PascalCase naming
Include scope for script/global/environment variables: $script:, $global:, $env:
Use 4 spaces for indentation (no tabs)
Use one space around operators: $a = 1 + 2
Use one space between type and variable: [String] $name
Use one space between keyword and parenthesis: if ($condition)
No spaces on empty lines
Limit lines to 120 characters
Place newline before opening brace (except variable assignments)
Place one newline after opening brace
Place two newlines after closing brace (one if followed by another brace or continuation)
Use single quotes unless variable expansion is needed: 'text' vs "text $variable"
For single-line arrays use: @('one', 'two', 'three')
For multi-line arrays: place each element on separate line with proper indentation
Do not use the unary comma operator (,) in return statements to force an array
For empty hashtables use: @{}
For hashtables: place each property on separate line with proper indentation and use PascalCase for property names
Single-line comments: use # Comment format (capitalized, on own line)
Multi-line comments: use <# Comment #> format (opening and closing brackets on own line with indented text)
No commented-out code
Always add comment-based help to all functions and scripts with SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, and EXAMPLE sections before function/class
Comment-based help indentation: keywords 4 spaces, text 8 spaces
Include examples in comment-based help for all parameter sets and combinations
INPUTS section in comment-based help: List each pipeline-accepted type as inline code with a 1-line description, repeat keyword for each input type, specify None. if there are no inp...

Files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
tests/[Uu]nit/**/*.[Tt]ests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md)

tests/[Uu]nit/**/*.[Tt]ests.ps1: Test with localized strings using InModuleScope -ScriptBlock { $script:localizedData.Key } in Pester unit tests
Mock files using the $TestDrive variable (path to the test drive) in Pester unit tests
All public commands require parameter set validation tests in unit tests
Use the exact Pester test setup block with BeforeDiscovery, BeforeAll, and AfterAll blocks before Describe in unit tests, including DscResource.Test module import and PSDefaultParameterValues configuration
Use parameter set validation test template with Get-Command and ParameterSets property, supporting both single and multiple parameter sets via -ForEach array in Pester unit tests
Use parameter properties test template with Get-Command to validate individual parameter attributes (e.g., Mandatory flag) in Pester unit tests

Files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1

⚙️ CodeRabbit configuration file

tests/[Uu]nit/**/*.[Tt]ests.ps1: # Unit Tests Guidelines

  • Test with localized strings: Use InModuleScope -ScriptBlock { $script:localizedData.Key }
  • Mock files: Use $TestDrive variable (path to the test drive)
  • All public commands require parameter set validation tests
  • After modifying classes, always run tests in new session (for changes to take effect)

Test Setup Requirements

Use this exact setup block before Describe:

[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 noop" first.'
    }
}

BeforeAll {
    $script:moduleName = '{MyModuleName}'

    Import-Module -Name $script:moduleName -ErrorAction 'Stop'

    $PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:moduleName
    $PSDefaultParameterValues['Mock:ModuleName'] = $script:moduleName
    $PSDefaultParameterValues['Should:ModuleName'] = $script:moduleName
}

AfterAll {
    $PSDefaultParameterValues.Remove('InModuleScope:ModuleName')
    $PSDefaultParameterValues.Remove('Mock:ModuleName')
   ...

Files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
**

⚙️ CodeRabbit configuration file

**: # DSC Community Guidelines

Terminology

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

Build & Test Workflow Requirements

  • Run PowerShell script files from repository root
  • Setup build and test environment (once per pwsh session): ./build.ps1 -Tasks noop
  • Build project before running tests: ./build.ps1 -Tasks build
  • Always run tests in new pwsh session: Invoke-Pester -Path @({test paths}) -Output Detailed

File Organization

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

Requirements

  • Follow instructions over existing code patterns
  • Follow PowerShell style and test guideline instructions strictly
  • Always update CHANGELOG.md Unreleased section
  • Localize all strings using string keys; remove any orphaned string keys
  • Check DscResource.Common before creating private functions
  • Separate reusable logic into private functions
  • DSC resources should always be created as class-based resources
  • Add unit tests for all commands/functions/resources
  • Add integration tests for all public commands and resources

Files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • CHANGELOG.md
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
{**/*.ps1,**/*.psm1,**/*.psd1}

⚙️ CodeRabbit configuration file

{**/*.ps1,**/*.psm1,**/*.psd1}: # 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:

File naming

  • Class files: ###.ClassName.ps1 format (e.g. 001.SqlReason.ps1, 004.StartupParameters.ps1)

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: @{}
  • 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 as inline code with a 1‑line description...

Files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
CHANGELOG.md

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-changelog.instructions.md)

CHANGELOG.md: Always update the Unreleased section in CHANGELOG.md
Use Keep a Changelog format in CHANGELOG.md
Describe notable changes briefly in CHANGELOG.md, ≤2 items per change type
Reference issues using format issue #<issue_number> in CHANGELOG.md
No empty lines between list items in same section of CHANGELOG.md
Skip adding entry if same change already exists in Unreleased section of CHANGELOG.md
No duplicate sections or items in Unreleased section of CHANGELOG.md

Always update CHANGELOG.md Unreleased section

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 #<issue_number>
  • No empty lines between list items in same section
  • Skip adding entry if same change already exists in Unreleased section
  • No duplicate sections or items in Unreleased section

Files:

  • CHANGELOG.md
**/*.md

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-markdown.instructions.md)

**/*.md: Wrap lines at word boundaries when over 80 characters (except tables/code blocks)
Use 2 spaces for indentation in Markdown files
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)
Escape backslashes in file paths only (not in code blocks)
Code blocks must specify language identifiers
Format parameters using bold in Markdown documentation
Format values and literals using inline code in Markdown documentation
Format resource/module/product names using italic in Markdown documentation
Format commands/files/paths using inline code in Markdown documentation

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)
  • Escape backslashes in file paths only (not in code blocks)
  • 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
tests/Unit/Private/*.[Tt]ests.ps1

📄 CodeRabbit inference engine (.github/instructions/dsc-community-style-guidelines-pester.instructions.md)

Private functions: tests/Unit/Private/{Name}.Tests.ps1

Files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
🧠 Learnings (25)
📚 Learning: 2025-11-27T17:58:02.422Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: Applies to **/tests/**/*.tests.ps1 : When unit tests test classes or commands containing SMO types like `[Microsoft.SqlServer.Management.Smo.*]`, ensure they are properly stubbed in SMO.cs

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-11-27T17:58:02.422Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: Applies to **/tests/**/*.tests.ps1 : In unit tests: use SMO stub types from SMO.cs, never mock SMO types

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Mocking in `BeforeAll` (`BeforeEach` only when required)

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-11-27T17:58:02.422Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: Applies to **/tests/**/*.tests.ps1 : Add `$env:SqlServerDscCI = $true` in `BeforeAll` block and remove in `AfterAll` block of unit tests

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-11-27T17:58:02.422Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: After changing SMO stub types in SMO.cs, run tests in a new PowerShell session for changes to take effect

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Mock variables prefix: 'mock'

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-08-17T10:13:30.079Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 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/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
📚 Learning: 2025-11-27T17:58:02.422Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: Applies to **/tests/Integration/**/*.ps1 : Integration tests: use `Connect-SqlDscDatabaseEngine` for SQL Server DB session with correct CI credentials, and always follow with `Disconnect-SqlDscDatabaseEngine`

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Omit `-MockWith` when returning `$null`

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
📚 Learning: 2025-12-30T15:15:36.065Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-12-30T15:15:36.065Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : Mock files using the `$TestDrive` variable (path to the test drive) in Pester unit tests

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Never use `Mock` inside `InModuleScope`-block

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Never add an empty `-MockWith` block

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Set `$PSDefaultParameterValues` for `Mock:ModuleName`, `Should:ModuleName`, `InModuleScope:ModuleName`

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Never use `Assert-MockCalled`, use `Should -Invoke` instead

Applied to files:

  • tests/Unit/Classes/SqlAudit.Tests.ps1
  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to tests/Unit/Private/*.[Tt]ests.ps1 : Private functions: `tests/Unit/Private/{Name}.Tests.ps1`

Applied to files:

  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-12-30T15:15:25.252Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-12-30T15:15:25.252Z
Learning: Applies to tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1 : Integration tests must use real environment only - no mocking allowed

Applied to files:

  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Never use `param()` inside `-MockWith` scriptblocks, parameters are auto-bound

Applied to files:

  • tests/Unit/Classes/SqlDatabasePermission.Tests.ps1
  • tests/Unit/Classes/SqlPermission.Tests.ps1
📚 Learning: 2025-11-27T17:58:02.422Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: Applies to **/*.ps1 : Format public commands as `{Verb}-SqlDsc{Noun}` following PowerShell naming conventions

Applied to files:

  • CHANGELOG.md
📚 Learning: 2025-11-27T17:58:02.422Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.422Z
Learning: Applies to **/resources/**/*.ps1 : Add `InstanceName`, `ServerName`, and `Credential` to `$this.ExcludeDscProperties` in Database Engine resources

Applied to files:

  • CHANGELOG.md
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Use nested `Context` blocks for complex scenarios

Applied to files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Cover all scenarios and code paths

Applied to files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Each scenario = separate `Context` block

Applied to files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : `Context` descriptions start with 'When'

Applied to files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-08-17T10:15:48.194Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 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/Private/Invoke-ReportServerSetupAction.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.205Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-11-27T17:59:27.205Z
Learning: Applies to **/*.[Tt]ests.ps1 : Avoid unnecessary remove/recreate cycles

Applied to files:

  • tests/Unit/Private/Invoke-ReportServerSetupAction.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 (18)
tests/Unit/Classes/SqlPermission.Tests.ps1 (4)

930-950: LGTM!

The GetCurrentState mock correctly returns a state that matches the desired Permission property, which is appropriate for the "system is in the desired state" scenario. Combined with the Compare() mock returning $null, this ensures Modify() is not invoked.


971-991: LGTM! Test expectation corrected.

The GetCurrentState mock is properly added to support the base class flow. Notably, line 1013 now correctly expects Modify() to be called (mockMethodModifyCallCount | Should -Be 1) when the system is not in the desired state—this is the correct behavior.

Also applies to: 1013-1018


1059-1079: LGTM!

The GetCurrentState mock is correctly configured to return the expected permission state for the "system is in the desired state" scenario, ensuring Test() returns $true.


1098-1118: LGTM!

The GetCurrentState mock is properly configured, and the Compare() mock returns a non-null difference object to simulate drift. The test correctly expects Test() to return $false.

tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1 (7)

433-470: Well-structured test setup.

The mock definitions correctly use ParameterFilter to distinguish between different path parameter scenarios, and the expanded path values are appropriate for verification. This follows the established patterns in the test file.


472-483: LGTM!

The test correctly verifies that Format-Path is invoked for MediaPath with all the expected flags including ExpandEnvironmentVariable.


485-499: LGTM!

The test correctly verifies that Format-Path is called for the optional LogPath parameter when specified, with the appropriate expansion flags.


501-515: LGTM!

The test correctly verifies that Format-Path is called for the optional InstallFolder parameter when specified.


517-525: LGTM!

The test correctly verifies that the expanded path is passed to Start-SqlSetupProcess, confirming the environment variable expansion occurs before process invocation.


527-541: LGTM!

The test correctly verifies that the expanded LogPath value appears in the ArgumentList passed to the setup process.


543-558: LGTM!

The test correctly verifies that the expanded InstallFolder value appears in the ArgumentList passed to the setup process. The complete test context provides good coverage for the environment variable expansion feature across all three path parameters.

tests/Unit/Classes/SqlAudit.Tests.ps1 (4)

271-278: LGTM! GetCurrentState() mock appropriately added for desired state scenario.

The mock correctly returns current state matching desired state (Path = 'C:\Temp'), enabling proper testing of Set() when no changes are needed.


302-318: LGTM! Excellent alignment between GetCurrentState() and Compare() mocks.

The GetCurrentState() mock appropriately returns 'C:\CurrentPath' (current state) while Compare() expects 'C:\Temp' (desired state). The added comments clearly explain the relationship between ExpectedValue and ActualValue, improving test maintainability.


359-366: LGTM! GetCurrentState() mock properly added for Test() desired state scenario.

The mock correctly returns current state matching desired state, enabling Test() to return $true as expected.


388-395: LGTM! GetCurrentState() mock correctly simulates out-of-compliance state.

The mock returns 'C:\WrongFolder' for current state while desired state is 'C:\Temp', properly enabling Test() to detect drift and return $false.

tests/Unit/Classes/SqlDatabasePermission.Tests.ps1 (3)

1038-1038: Good fix: Test description now matches expected behavior.

The test description correctly states "Should call method Modify()" which aligns with:

  • Context: "When the system is not in the desired state"
  • Assertion: $script:mockMethodModifyCallCount | Should -Be 1

This change fixes what appears to have been an incorrect test description.


953-1147: LGTM: Consistent mocking pattern across test methods.

The addition of GetCurrentState() mocks to Set() and Test() method tests follows the established pattern already present in Get() method tests. The mocks appropriately return:

  • Current state matching desired state in "desired state" contexts
  • Current state differing from desired state in "not in desired state" contexts

This provides consistent test coverage across all base class methods (Get(), Set(), Test()).


953-974: SqlDatabasePermission.Tests.ps1 should not be modified in this PR.

The CHANGELOG confirms this PR is about expanding environment variables in Invoke-ReportServerSetupAction and other features (Get-SqlDscServerProtocolTcpIp, SqlResourceBase changes, etc.), with no mention of SqlDatabasePermission test changes. The SqlDatabasePermission class is unrelated to Invoke-ReportServerSetupAction or path parameter handling. Remove this file from the PR or update the CHANGELOG to document why these test changes are necessary.

The changes shown (GetCurrentState() mocks and test description fix) are technically correct and follow Pester guidelines, but they do not belong in a PR scoped to Invoke-ReportServerSetupAction.

Copy link
Member Author

@johlju johlju left a comment

Choose a reason for hiding this comment

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

:lgtm:

@johlju reviewed 7 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @johlju).

Copy link
Member Author

@johlju johlju left a comment

Choose a reason for hiding this comment

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

@johlju reviewed 1 file and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @johlju).

@johlju johlju merged commit 5c65e63 into dsccommunity:main Dec 31, 2025
49 checks passed
@johlju johlju deleted the f/issue-#2085 branch December 31, 2025 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invoke-ReportServerSetupAction: Improve to use expanded environment variables

1 participant

Comments