Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 29, 2025

Pull Request (PR) description

Adds validation to ensure each DSC_DatabaseObjectPermission instance only contains a single permission name. Previously, passing comma-separated permissions (e.g., 'DELETE,INSERT,SELECT') caused a confusing ReferenceObject is null error during Test-TargetResource. Now, a clear and descriptive error message is thrown.

Changes:

  • Added validation in Assert-PermissionEnsureProperty function to check if permission value matches ^\w+$ pattern
  • Added localized error message (SDOP0012) for invalid permission values
  • Updated "Known issues" section in resource README with the new error message and incorrect/correct usage examples
  • Added unit tests for the new validation
  • Updated CHANGELOG entry

New error message:

The permission value 'DELETE,INSERT,SELECT' is invalid. Each DSC_DatabaseObjectPermission instance can only contain a single permission name. Specify each permission in a separate DSC_DatabaseObjectPermission instance.

Incorrect usage:

DSC_DatabaseObjectPermission {
    State      = 'Grant'
    Permission = 'DELETE,INSERT,SELECT' # Fails with descriptive error
}

Correct usage:

DSC_DatabaseObjectPermission {
    State      = 'Grant'
    Permission = 'DELETE'
}
DSC_DatabaseObjectPermission {
    State      = 'Grant'
    Permission = 'INSERT'
}

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.
Original prompt

This section details on the original issue you should resolve

<issue_title>SqlDatabaseObjectPermission - ReferenceObject is null</issue_title>
<issue_description>### Problem description

The SqlDatabaseObjectPermission Resource is throwing an error during the Test-TargetResource functionality if the DSC_DatabaseObjectPermission block contains a set of Permissions in it.
For example:
instance of DSC_DatabaseObjectPermission as $DSC_DatabaseObjectPermission10ref
{
State = "Grant";
Permission = "DELETE,INSERT,REFERENCES,SELECT,UPDATE";
};

Verbose logs

Cannot bind argument to parameter 'ReferenceObject' because it is null.
The PowerShell DSC resource '[SqlDatabaseObjectPermission]DBObjectPerm_XXX' with SourceInfo 'D:\a\1\s\Configurations\SqlServer_Permissions.ps1::216::13::SqlDatabaseObjectPermission' threw one or more non-terminating errors while running the Test-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. Refer to this channel for more details.

DSC configuration

SqlDatabaseObjectPermission ("DBObjectPerm_XXX") {
                Name         = $objPerm.Principal
                DatabaseName = $objPerm.DatabaseName
                SchemaName   = $objPerm.SchemaName
                ObjectName   = $objPerm.ObjectName
                ObjectType   = $objPerm.ObjectType
                Permission   = @(
                    DSC_DatabaseObjectPermission {
                        State      = 'Grant'
                        Permission = $grantPermissions 
                    }
                    DSC_DatabaseObjectPermission {
                        State      = 'Deny'
                        Permission = $denyPermissions 
                    }
                    DSC_DatabaseObjectPermission {
                        State      = 'GrantWithGrant'
                        Permission = $grantWithGrantPermissions 
                    }
                )
                ServerName   = $Node.NodeName
                InstanceName = $Node.InstanceName
                DependsOn    = $dependencies
            }

Suggested solution

To resolve this issue, it is required to create a separate DSC_DatabaseObjectPermission block per permission. This should be added to the documentation and there should be a check to not allow such a configuration.

SqlDatabaseObjectPermission ("DBObjectPerm_XXX") {
                Name         = $objPerm.Principal
                DatabaseName = $objPerm.DatabaseName
                SchemaName   = $objPerm.SchemaName
                ObjectName   = $objPerm.ObjectName
                ObjectType   = $objPerm.ObjectType
                Permission   = @(
                    foreach ($perm in $grantPermissions) {
                        DSC_DatabaseObjectPermission {
                            State      = 'Grant'
                            Permission = $perm 
                        }
                    }
                    foreach ($perm in $denyPermissions) {
                        DSC_DatabaseObjectPermission {
                            State      = 'Deny'
                            Permission = $perm 
                        }
                    }
                    foreach ($perm in $grantWithGrantPermissions) {
                        DSC_DatabaseObjectPermission {
                            State      = 'GrantWithGrant'
                            Permission = $perm 
                        }
                    }
                )
                ServerName   = $Node.NodeName
                InstanceName = $Node.InstanceName
                DependsOn    = $dependencies
            }

SQL Server edition and version

2016, 2022

SQL Server PowerShell modules

22.4.5.1

Operating system

Windows Server 2016, 2022

PowerShell version

5

SqlServerDsc version

17.2.0
```</issue_description>

<agent_instructions>Document this limitation mentioned in this issue in the MOF-based resource's README: source/DSCResources/DSC_SqlDatabaseObjectPermission/README.md</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@johlju</author><body>
I wonder if it possible to make this an array of strings instead:

https://github.com/dsccommunity/SqlServerDsc/blob/ed34b01fcb76445dc70ab46e74a05cbcd62c4926/source/DSCResources/DSC_SqlDatabaseObjectPermission/DSC_SqlDatabaseObjectPermission.schema.mof#L19</body></comment_new>
<comment_new><author>@johlju</author><body>
No it does not as a now realized it is a key 🙂 This might be improved once the MOF-based resource is converted into a class-based resource similar to `DatabasePermission`.</body></comment_new>
</comments>


</details>

- Fixes dsccommunity/SqlServerDsc#2345

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for you](https://github.com/dsccommunity/SqlServerDsc/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.

<!-- Reviewable:start -->
- - -
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/dsccommunity/SqlServerDsc/2353)
<!-- Reviewable:end -->

@coderabbitai
Copy link

coderabbitai bot commented Nov 29, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Runtime validation was added to SqlDatabaseObjectPermission to enforce single permission-per-instance configuration. When multiple comma-separated permissions are detected, a descriptive localized error is raised. Documentation was updated to describe this constraint and provide correct usage examples. Unit tests validate both valid and invalid permission formats.

Changes

Cohort / File(s) Summary
Core Validation Logic
source/DSCResources/DSC_SqlDatabaseObjectPermission/DSC_SqlDatabaseObjectPermission.psm1
Added input validation in Assert-PermissionEnsureProperty function to ensure each Permission entry contains only single word characters. Raises ArgumentException with localized message if comma-separated or space-separated permissions are detected.
Localization & Documentation
source/DSCResources/DSC_SqlDatabaseObjectPermission/en-US/DSC_SqlDatabaseObjectPermission.strings.psd1, source/DSCResources/DSC_SqlDatabaseObjectPermission/README.md, CHANGELOG.md
Added new InvalidPermissionValue localization string and documented the single-permission-per-instance requirement in README Known Issues section with examples of incorrect and correct usage patterns.
Unit Tests
tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1
Introduced new test suite SqlDatabaseObjectPermission\Assert-PermissionEnsureProperty covering valid single permissions and invalid comma/space-separated permission formats, verifying error message propagation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Validation logic is straightforward (single word character check)
  • Cohesive changes across validation, tests, documentation, and localization
  • Good test coverage for both valid and invalid cases
  • Verify regex/validation pattern matches intended behavior and error messaging consistency

Pre-merge checks

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding validation to ensure each DSC_DatabaseObjectPermission instance contains only a single permission name.
Description check ✅ Passed The description is well-structured and directly related to the changeset, explaining the problem, solution, changes made, and providing usage examples.
Linked Issues check ✅ Passed The PR successfully addresses issue #2345 by adding validation to prevent comma-separated permissions, updating documentation, adding localized error messages, and including unit tests.
Out of Scope Changes check ✅ Passed All changes are directly scoped to addressing issue #2345: validation logic, documentation updates, localization strings, tests, and changelog entries are all related to the single permission requirement.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

Copilot AI changed the title [WIP] Fix null reference issue in SqlDatabaseObjectPermission SqlDatabaseObjectPermission: Document single permission per DSC_DatabaseObjectPermission instance limitation Nov 29, 2025
Copilot AI requested a review from johlju November 29, 2025 07:50
Copilot finished work on behalf of johlju November 29, 2025 07:50
@johlju
Copy link
Member

johlju commented Nov 29, 2025

@copilot can we add logic to the MOF-based resource so that it check the Permission property of the CIM instance and if it -notmatch '^\w+$' it throws an localized error. I think adding to this function might work as it is called by Get-, Set-, and Test-TargetResource:

<#
.SYNOPSIS
Asserts that if Ensure property is not set, then the Ensure property is
set to 'Present' (which is the default).
.PARAMETER Permission
Specifies array of permission CIM instances.
#>
function Assert-PermissionEnsureProperty
{
[CmdletBinding()]
[OutputType([Microsoft.Management.Infrastructure.CimInstance[]])]
param
(
[Parameter(Mandatory = $true)]
[Microsoft.Management.Infrastructure.CimInstance[]]
$Permission
)
foreach ($desiredPermission in $Permission)
{
if (-not $desiredPermission.Ensure)
{
$desiredPermission.Ensure = 'Present'
}
}
return $Permission
}

Also update the MOF-based resource's README as this change would change what the error message will be.

Copy link
Contributor Author

Copilot AI commented Nov 29, 2025

@copilot can we add logic to the MOF-based resource so that it check the Permission property of the CIM instance and if it -notmatch '^\w+$' it throws an localized error. I think adding to this func...

Added validation in commit 084afb9. The ^\w+$ pattern is appropriate because SQL Server ObjectPermissionSet property names (like 'Select', 'Insert', 'Delete', 'Update', 'ViewDefinition', etc.) all consist only of word characters. This pattern correctly rejects comma-separated lists like 'DELETE,INSERT,SELECT' or space-separated values which cause the 'ReferenceObject is null' error. Also added localized error message, updated documentation with the new error message, and added unit tests.

@johlju
Copy link
Member

johlju commented Nov 29, 2025

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Nov 29, 2025

✅ Actions performed

Review triggered.

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

Copilot AI changed the title SqlDatabaseObjectPermission: Document single permission per DSC_DatabaseObjectPermission instance limitation SqlDatabaseObjectPermission: Add validation for single permission per DSC_DatabaseObjectPermission instance Nov 29, 2025
Copilot finished work on behalf of johlju November 29, 2025 08:13
@johlju johlju marked this pull request as ready for review November 29, 2025 08:14
@johlju johlju requested a review from a team as a code owner November 29, 2025 08:14
@johlju johlju added the needs review The pull request needs a code review. label Nov 29, 2025
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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ed34b01 and 084afb9.

📒 Files selected for processing (5)
  • CHANGELOG.md (1 hunks)
  • source/DSCResources/DSC_SqlDatabaseObjectPermission/DSC_SqlDatabaseObjectPermission.psm1 (1 hunks)
  • source/DSCResources/DSC_SqlDatabaseObjectPermission/README.md (1 hunks)
  • source/DSCResources/DSC_SqlDatabaseObjectPermission/en-US/DSC_SqlDatabaseObjectPermission.strings.psd1 (1 hunks)
  • tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1 (1 hunks)
🧰 Additional context used
📓 Path-based instructions (12)
source/DSCResources/**/*.psm1

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

source/DSCResources/**/*.psm1: Every DSC resource must define the three required functions: Get-TargetResource, Set-TargetResource, and Test-TargetResource
Export functions using the *-TargetResource pattern
Get-TargetResource function must return a hashtable with all resource properties
Test-TargetResource function must return a boolean value ($true or $false)
Set-TargetResource function must not return anything (void)
Get-TargetResource should only include parameters needed to retrieve actual current state values
Get-TargetResource should remove non-mandatory parameters that are never used
Set-TargetResource and Test-TargetResource must have identical parameters
Unused mandatory parameters in Set-TargetResource and Test-TargetResource should include "Not used in <function_name>" in the help comment
Each DSC resource function must include at least one Write-Verbose statement
Get-TargetResource verbose messages must start with "Getting the current state of..."
Set-TargetResource verbose messages must start with "Setting the desired state of..."
Test-TargetResource verbose messages must start with "Determining the current state of..."
Use localized strings for all messages including Write-Verbose, Write-Error, and other messaging commands
Import localized strings using Get-LocalizedData at the module top level
Use try/catch blocks to handle exceptions in MOF-based DSC resources
Use New-InvalidDataException for invalid data errors instead of throw in MOF-based DSC resources
Use New-ArgumentException for argument-related errors instead of throw in MOF-based DSC resources
Use New-InvalidOperationException for invalid operation errors instead of throw in MOF-based DSC resources
Use New-ObjectNotFoundException for object not found errors instead of throw in MOF-based DSC resources
Use New-InvalidResultException for invalid result errors instead of throw in MOF-based DSC resources
Use New-NotImplementedException...

Files:

  • source/DSCResources/DSC_SqlDatabaseObjectPermission/DSC_SqlDatabaseObjectPermission.psm1

⚙️ CodeRabbit configuration file

source/DSCResources/**/*.psm1: # MOF-based Desired State Configuration (DSC) Resources Guidelines

Required Functions

  • Every DSC resource must define: Get-TargetResource, Set-TargetResource, Test-TargetResource
  • Export using *-TargetResource pattern

Function Return Types

  • Get-TargetResource: Must return hashtable with all resource properties
  • Test-TargetResource: Must return boolean ($true/$false)
  • Set-TargetResource: Must not return anything (void)

Parameter Guidelines

  • Get-TargetResource: Only include parameters needed to retrieve actual current state values
  • Get-TargetResource: Remove non-mandatory parameters that are never used
  • Set-TargetResource and Test-TargetResource: Must have identical parameters
  • Set-TargetResource and Test-TargetResource: Unused mandatory parameters: Add "Not used in <function_name>" to help comment

Required Elements

  • Each function must include Write-Verbose at least once
    • Get-TargetResource: Use verbose message starting with "Getting the current state of..."
    • Set-TargetResource: Use verbose message starting with "Setting the desired state of..."
    • Test-TargetResource: Use verbose message starting with "Determining the current state of..."
  • Use localized strings for all messages (Write-Verbose, Write-Error, etc.)
  • Import localized strings using Get-LocalizedData at module top

Error Handling

Files:

  • source/DSCResources/DSC_SqlDatabaseObjectPermission/DSC_SqlDatabaseObjectPermission.psm1
**/*.{ps1,psm1,psd1}

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

**/*.{ps1,psm1,psd1}: Use descriptive names with 3+ characters and no abbreviations for functions, variables, and identifiers
Functions: Use PascalCase with Verb-Noun format using approved verbs
Parameters: Use PascalCase
Variables: Use camelCase
Keywords: Use lower-case
Classes: Use PascalCase
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
Try to limit lines to 120 characters
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)
Use single quotes unless variable expansion is needed: 'text' vs "text $variable"
Single-line arrays: @('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
Empty hashtables: @{}; each property on separate line with proper indentation; use PascalCase for properties
Single-line comments: # Comment (capitalized, on own line); multi-line: <# Comment #> format with opening/closing brackets on own line
Do not include commented-out code
Always add comment-based help to all functions and scripts with SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, and EXAMPLE sections
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 (one per line) with 1-line description, repeat keyword for each input type
OUTPUTS section in comment-based help: list each return type (one per line) with 1-line description, repeat keyword for each output type; must match both [OutputType()] and actual ret...

Files:

  • source/DSCResources/DSC_SqlDatabaseObjectPermission/DSC_SqlDatabaseObjectPermission.psm1
  • source/DSCResources/DSC_SqlDatabaseObjectPermission/en-US/DSC_SqlDatabaseObjectPermission.strings.psd1
  • tests/Unit/DSC_SqlDatabaseObjectPermission.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:

  • source/DSCResources/DSC_SqlDatabaseObjectPermission/DSC_SqlDatabaseObjectPermission.psm1
  • source/DSCResources/DSC_SqlDatabaseObjectPermission/README.md
  • source/DSCResources/DSC_SqlDatabaseObjectPermission/en-US/DSC_SqlDatabaseObjectPermission.strings.psd1
  • tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.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 (one per line) with a 1‑line description...

Files:

  • source/DSCResources/DSC_SqlDatabaseObjectPermission/DSC_SqlDatabaseObjectPermission.psm1
  • source/DSCResources/DSC_SqlDatabaseObjectPermission/en-US/DSC_SqlDatabaseObjectPermission.strings.psd1
  • tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1
**/*.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:

  • source/DSCResources/DSC_SqlDatabaseObjectPermission/README.md
  • 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:

  • source/DSCResources/DSC_SqlDatabaseObjectPermission/README.md
  • CHANGELOG.md
source/DSCResources/**/en-US/DSC_*.strings.psd1

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

source/DSCResources/**/en-US/DSC_*.strings.psd1: Name localized strings file as DSC_<ResourceName>.strings.psd1 in the en-US folder
In .strings.psd1 files, use underscores as word separators in localized string key names for multi-word keys

Files:

  • source/DSCResources/DSC_SqlDatabaseObjectPermission/en-US/DSC_SqlDatabaseObjectPermission.strings.psd1
**/*.psd1

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

Don't use NestedModules for shared commands without RootModule in module manifest

Files:

  • source/DSCResources/DSC_SqlDatabaseObjectPermission/en-US/DSC_SqlDatabaseObjectPermission.strings.psd1
**/*.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/DSC_SqlDatabaseObjectPermission.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/DSC_SqlDatabaseObjectPermission.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/DSC_SqlDatabaseObjectPermission.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/DSC_SqlDatabaseObjectPermission.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/DSC_SqlDatabaseObjectPermission.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/DSC_SqlDatabaseObjectPermission.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
🧠 Learnings (30)
📚 Learning: 2025-08-28T17:10:34.765Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 2150
File: source/Classes/020.SqlAgentAlert.ps1:198-217
Timestamp: 2025-08-28T17:10:34.765Z
Learning: DSC properties with default values (e.g., `$Ensure = 'Present'`) are always present in the properties hashtable passed to validation methods, even when not explicitly specified by the user.

Applied to files:

  • source/DSCResources/DSC_SqlDatabaseObjectPermission/DSC_SqlDatabaseObjectPermission.psm1
📚 Learning: 2025-11-27T17:58:20.390Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-class-resource.instructions.md:0-0
Timestamp: 2025-11-27T17:58:20.390Z
Learning: Applies to source/[cC]lasses/**/*.ps1 : DSC class-based resources may optionally implement methods: `AssertProperties()` and `NormalizeProperties()` following the specified pattern

Applied to files:

  • source/DSCResources/DSC_SqlDatabaseObjectPermission/DSC_SqlDatabaseObjectPermission.psm1
  • tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1
📚 Learning: 2025-08-16T13:22:15.230Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 2134
File: tests/Unit/Public/Get-SqlDscLogin.Tests.ps1:78-93
Timestamp: 2025-08-16T13:22:15.230Z
Learning: In PowerShell unit tests for parameter validation in SqlServerDsc, accessing parameter attributes directly like `$cmd.Parameters['ParameterName'].Attributes.Mandatory` works correctly because PowerShell automatically iterates through the array and returns the property values. Additional filtering to ParameterAttribute is not necessary when the parameter structure is known and controlled.

Applied to files:

  • source/DSCResources/DSC_SqlDatabaseObjectPermission/DSC_SqlDatabaseObjectPermission.psm1
  • tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1
📚 Learning: 2025-08-28T15:42:41.195Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 2150
File: source/Classes/020.SqlAgentAlert.ps1:0-0
Timestamp: 2025-08-28T15:42:41.195Z
Learning: Assert-BoundParameter now supports AtLeastOneList parameter (resolved in commit 809953f367ee903969a43e44a5b78e902ef46948) which can be used alongside MutuallyExclusiveList to enforce "exactly one required" validation in DSC resources.

Applied to files:

  • source/DSCResources/DSC_SqlDatabaseObjectPermission/DSC_SqlDatabaseObjectPermission.psm1
📚 Learning: 2025-11-27T18:00:11.915Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-11-27T18:00:11.915Z
Learning: Applies to **/*.{ps1,psm1,psd1} : `$PSCmdlet.ShouldProcess` must use required pattern: localized messages for description, confirmation, and caption

Applied to files:

  • source/DSCResources/DSC_SqlDatabaseObjectPermission/DSC_SqlDatabaseObjectPermission.psm1
📚 Learning: 2025-11-22T17:36:09.703Z
Learnt from: johlju
Repo: dsccommunity/SqlServerDsc PR: 2343
File: source/Classes/004.DatabaseFileGroupSpec.ps1:5-34
Timestamp: 2025-11-22T17:36:09.703Z
Learning: The comment-based help requirements for ## Requirements and ## Known issues sections only apply to class-based DSC resources (classes decorated with [DscResource(...)]) in source/Classes/**/*.ps1, not to regular helper classes, DTO classes, or specification classes in the same directory.

Applied to files:

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

Applied to files:

  • source/DSCResources/DSC_SqlDatabaseObjectPermission/README.md
📚 Learning: 2025-09-28T13:49:31.541Z
Learnt from: dan-hughes
Repo: dsccommunity/DhcpServerDsc PR: 96
File: source/Modules/DhcpServerDsc.Common/Public/Get-ValidTimeSpan.ps1:36-39
Timestamp: 2025-09-28T13:49:31.541Z
Learning: In DSC Community guidelines, ErrorId parameters in New-TerminatingError calls are identifier strings that do not need localization - only the ErrorMessage parameter should use localized strings from $script:localizedData.

Applied to files:

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

Applied to files:

  • source/DSCResources/DSC_SqlDatabaseObjectPermission/en-US/DSC_SqlDatabaseObjectPermission.strings.psd1
📚 Learning: 2025-11-27T17:59:01.498Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-11-27T17:59:01.498Z
Learning: Applies to source/DSCResources/**/*.psm1 : Use localized strings for all messages including Write-Verbose, Write-Error, and other messaging commands

Applied to files:

  • source/DSCResources/DSC_SqlDatabaseObjectPermission/en-US/DSC_SqlDatabaseObjectPermission.strings.psd1
📚 Learning: 2025-10-04T21:33:23.022Z
Learnt from: dan-hughes
Repo: dsccommunity/UpdateServicesDsc PR: 85
File: source/en-US/UpdateServicesDsc.strings.psd1:1-2
Timestamp: 2025-10-04T21:33:23.022Z
Learning: In UpdateServicesDsc (and similar DSC modules), the module-level localization file (source/en-US/<ModuleName>.strings.psd1) can be empty when DSC resources have their own localization files in source/DSCResources/<ResourceName>/en-US/DSC_<ResourceName>.strings.psd1. Automated tests verify localization completeness for resources. Don't flag empty module-level localization files as issues when resources have separate localization.

Applied to files:

  • source/DSCResources/DSC_SqlDatabaseObjectPermission/en-US/DSC_SqlDatabaseObjectPermission.strings.psd1
📚 Learning: 2025-11-27T17:59:01.498Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-11-27T17:59:01.498Z
Learning: Applies to source/DSCResources/**/*.psm1 : Use `New-InvalidDataException` for invalid data errors instead of `throw` in MOF-based DSC resources

Applied to files:

  • source/DSCResources/DSC_SqlDatabaseObjectPermission/en-US/DSC_SqlDatabaseObjectPermission.strings.psd1
📚 Learning: 2025-11-27T17:59:01.498Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-11-27T17:59:01.498Z
Learning: Applies to source/DSCResources/**/*.psm1 : Use `New-InvalidOperationException` for invalid operation errors instead of `throw` in MOF-based DSC resources

Applied to files:

  • source/DSCResources/DSC_SqlDatabaseObjectPermission/en-US/DSC_SqlDatabaseObjectPermission.strings.psd1
📚 Learning: 2025-11-27T17:58:42.320Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-localization.instructions.md:0-0
Timestamp: 2025-11-27T17:58:42.320Z
Learning: Applies to source/en-US/*.strings.psd1 : Use Key Naming Pattern format: Verb_FunctionName_Action with underscore separators (e.g., Get_Database_ConnectingToDatabase)

Applied to files:

  • source/DSCResources/DSC_SqlDatabaseObjectPermission/en-US/DSC_SqlDatabaseObjectPermission.strings.psd1
📚 Learning: 2025-11-27T17:58:42.320Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-localization.instructions.md:0-0
Timestamp: 2025-11-27T17:58:42.320Z
Learning: Applies to source/**/*.ps1 : Use localized string keys from $script:localizedData, not hardcoded strings, in diagnostic messages

Applied to files:

  • source/DSCResources/DSC_SqlDatabaseObjectPermission/en-US/DSC_SqlDatabaseObjectPermission.strings.psd1
📚 Learning: 2025-11-27T17:58:02.402Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.402Z
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/DSC_SqlDatabaseObjectPermission.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.192Z
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.192Z
Learning: Applies to **/*.[Tt]ests.ps1 : PascalCase: `Describe`, `Context`, `It`, `Should`, `BeforeAll`, `BeforeEach`, `AfterAll`, `AfterEach`

Applied to files:

  • tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1
📚 Learning: 2025-11-27T17:58:02.402Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.402Z
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/DSC_SqlDatabaseObjectPermission.Tests.ps1
📚 Learning: 2025-11-27T18:00:20.925Z
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.925Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : Parameter set validation tests should use Get-Command with Where-Object filtering and Should assertions to verify ParameterSetName and ParameterListAsString

Applied to files:

  • tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1
📚 Learning: 2025-11-27T18:00:20.925Z
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.925Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : Parameter property tests should verify mandatory parameter attributes using Get-Command Parameters and Should -BeTrue assertions

Applied to files:

  • tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1
📚 Learning: 2025-11-27T18:00:20.925Z
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.925Z
Learning: Applies to tests/[Uu]nit/**/*.[Tt]ests.ps1 : All public commands require parameter set validation tests

Applied to files:

  • tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.192Z
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.192Z
Learning: Applies to **/*.[Tt]ests.ps1 : One `Describe` block per file matching the tested entity name

Applied to files:

  • tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1
📚 Learning: 2025-11-27T17:58:02.402Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T17:58:02.402Z
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/DSC_SqlDatabaseObjectPermission.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.192Z
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.192Z
Learning: Applies to **/*.[Tt]ests.ps1 : Test code only inside `Describe` blocks

Applied to files:

  • tests/Unit/DSC_SqlDatabaseObjectPermission.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/DSC_SqlDatabaseObjectPermission.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.192Z
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.192Z
Learning: Applies to **/*.[Tt]ests.ps1 : Assertions only in `It` blocks

Applied to files:

  • tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1
📚 Learning: 2025-11-27T18:00:35.054Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines.instructions.md:0-0
Timestamp: 2025-11-27T18:00:35.054Z
Learning: Follow PowerShell style and test guideline instructions strictly

Applied to files:

  • tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.192Z
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.192Z
Learning: Applies to **/*.[Tt]ests.ps1 : Never use `Assert-MockCalled`, use `Should -Invoke` instead

Applied to files:

  • tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1
📚 Learning: 2025-11-27T17:59:27.192Z
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.192Z
Learning: Applies to **/*.[Tt]ests.ps1 : Each scenario = separate `Context` block

Applied to files:

  • tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1
📚 Learning: 2025-11-27T17:58:08.875Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-changelog.instructions.md:0-0
Timestamp: 2025-11-27T17:58:08.875Z
Learning: Applies to CHANGELOG.md : Describe notable changes briefly in CHANGELOG.md, ≤2 items per change type

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). (4)
  • GitHub Check: PSScriptAnalyzer
  • GitHub Check: PSScriptAnalyzer
  • GitHub Check: PSScriptAnalyzer
  • GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
🔇 Additional comments (4)
source/DSCResources/DSC_SqlDatabaseObjectPermission/en-US/DSC_SqlDatabaseObjectPermission.strings.psd1 (1)

15-15: Localized error string matches behavior and documentation

InvalidPermissionValue is well‑phrased, consistent with existing keys, and matches the README and expected validation behavior. No changes needed.

source/DSCResources/DSC_SqlDatabaseObjectPermission/README.md (1)

23-68: Known-issues documentation and examples are clear and consistent

The new “Only one permission per DSC_DatabaseObjectPermission instance” section accurately documents the limitation, shows concrete incorrect/correct examples, and aligns with the localized error message and planned validation. Reads well and follows the markdown guidelines.

source/DSCResources/DSC_SqlDatabaseObjectPermission/DSC_SqlDatabaseObjectPermission.psm1 (1)

911-917: LGTM! Validation correctly enforces single permission per instance.

The regex pattern ^\w+$ properly rejects comma-separated and space-separated permission values, and the error handling follows MOF resource guidelines by using New-ArgumentException with a localized message.

tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1 (1)

2795-2856: LGTM! Comprehensive test coverage for validation logic.

The test suite correctly covers both valid and invalid permission formats using proper Pester v5 syntax and InModuleScope for testing the private function. The tests validate that:

  • Single permission names pass validation
  • Comma-separated permissions are rejected
  • Space-separated permissions are rejected

The error message assertions using -ExpectedMessage with wildcards appropriately verify that the invalid permission value appears in the error.

@johlju
Copy link
Member

johlju commented Nov 29, 2025

@copilot In CHANGELOG.md around lines 179 to 183, the bullet for
SqlDatabaseObjectPermission links to issue #2020 but this PR fixes #2345;
update the issue reference so the changelog points to the correct tracked issue
(replace or augment the existing link with
https://github.com/dsccommunity/SqlServerDsc/issues/2345, so the release notes accurately
reflect the bug being fixed.

Copy link
Contributor Author

Copilot AI commented Nov 29, 2025

@copilot In CHANGELOG.md around lines 179 to 183, the bullet for
SqlDatabaseObjectPermission links to issue #2020 but this PR fixes #2345;
update the issue reference so the changelog points to the...

Fixed in commit c3d64b4. Updated the CHANGELOG to reference issue #2345 instead of #2020.

Copilot finished work on behalf of johlju November 29, 2025 08:26
@codecov
Copy link

codecov bot commented Nov 29, 2025

Codecov Report

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

Additional details and impacted files

Impacted file tree graph

@@         Coverage Diff          @@
##           main   #2353   +/-   ##
====================================
  Coverage    94%     94%           
====================================
  Files       164     164           
  Lines      9560    9563    +3     
====================================
+ Hits       9067    9070    +3     
  Misses      493     493           
Flag Coverage Δ
unit 94% <100%> (+<1%) ⬆️
Files with missing lines Coverage Δ
...ectPermission/DSC_SqlDatabaseObjectPermission.psm1 100% <100%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@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 3 of 5 files at r1, 2 of 2 files at r2, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @copilot)

@johlju johlju merged commit 752efb6 into main Nov 29, 2025
50 checks passed
@johlju johlju deleted the copilot/fix-sqldatabaseobjectpermission-error branch November 29, 2025 17:53
@johlju johlju removed the needs review The pull request needs a code review. label Nov 29, 2025
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.

SqlDatabaseObjectPermission - ReferenceObject is null

2 participants