Skip to content
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4d5b237
`SqlAgentAlert`: Refactor to class-bases resource
johlju Aug 24, 2025
4897a08
Fix typo in DSC class resource guidelines for ExcludeDscProperties co…
johlju Aug 25, 2025
11a2f00
Remove unit tests for DSC_SqlAgentAlert resource
johlju Aug 26, 2025
e62febd
Update SqlServerDsc guidelines to clarify resource inheritance and pr…
johlju Aug 26, 2025
4dfbc14
Update ExcludeDscProperties in SqlAgentAlert constructor to include I…
johlju Aug 26, 2025
642a742
Remove unnecessary blank lines from DSC_SqlAgentAlert_Remove_Config c…
johlju Aug 26, 2025
d74eedd
Update integration test to verify resource name against Configuration…
johlju Aug 26, 2025
9398b1d
Update AssertProperties method to validate Severity and MessageId par…
johlju Aug 26, 2025
9a5cba3
Fix AssertProperties method to validate Ensure property from input pa…
johlju Aug 26, 2025
017f3a8
Enhance SqlAgentAlert to restrict Severity and MessageId when Ensure …
johlju Aug 26, 2025
0afbd30
Clarify guideline on nullable property types in DSC class-based resou…
johlju Aug 26, 2025
c4050a5
Clarify guidelines for nullable property types in DSC class-based res…
johlju Aug 26, 2025
207ce9c
Add support for MessageId in SqlAgentAlert configuration and tests
johlju Aug 26, 2025
5856af5
Update module name placeholders in integration, localization, and uni…
johlju Aug 26, 2025
1c74791
Refactor AI instructions header to generalize project guidance
johlju Aug 26, 2025
670f853
Clarify hashtable formatting guideline for multi-line properties
johlju Aug 26, 2025
6d1226d
Add "RAISERROR" to cSpell words list in settings.json
johlju Aug 26, 2025
d75a5da
Enhance SQL Agent alert configurations to utilize MessageId with RAIS…
johlju Aug 26, 2025
2d0a7da
Add optional encryption parameter to SQL Agent alert configurations
johlju Aug 26, 2025
8a08ce4
Enhance PowerShell guidelines with output stream usage and backtick l…
johlju Aug 26, 2025
c4263f1
Correct capitalization in PowerShell guidelines for Write-Verbose usage
johlju Aug 26, 2025
54a02bf
Fix variable name in BeforeAll block for consistency in integration t…
johlju Aug 27, 2025
b3a7de8
Fix variable name in BeforeAll block for consistency in unit test gui…
johlju Aug 27, 2025
8fceb2a
Refactor naming section in Pester guidelines for clarity and consistency
johlju Aug 27, 2025
809953f
Enhance SqlAgentAlert validation logic in AssertProperties method and…
johlju Aug 28, 2025
05fe912
Update SqlAgentAlert documentation and adjust validation ranges for S…
johlju Aug 28, 2025
cd6e952
Update SqlAgentAlert parameter documentation to correct valid ranges …
johlju Aug 28, 2025
b60438e
Fix constructor definition in DSC class guidelines to include $PSScri…
johlju Aug 28, 2025
f898566
Update SqlServerDsc guidelines to clarify resource inheritance and co…
johlju Aug 28, 2025
51175ed
Refine documentation for SqlAgentAlert to improve clarity on alert ty…
johlju Aug 28, 2025
3354094
Refactor SqlAgentAlert to streamline absence validation for Severity …
johlju Aug 28, 2025
5c97552
Fix formatting in changelog guidelines for issue references
johlju Aug 28, 2025
0a2fba5
Add assertion for bound parameters in SqlAgentAlert Set method
johlju Aug 28, 2025
a245ba2
Add tests for Modify() method in SqlAgentAlert to validate alert updates
johlju Aug 29, 2025
250b7f0
Update build and test workflow instructions for clarity and consistency
johlju Aug 29, 2025
87fec7e
Refactor test descriptions in SqlAgentAlert.Tests.ps1 for clarity and…
johlju Aug 29, 2025
2f86af9
Refactor test assertions in SqlAgentAlert.Tests.ps1 to use assignment…
johlju Aug 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# AI Instructions for SqlServerDsc
# AI Instructions

This file provides AI agent guidance for the SqlServerDsc project. Each
instruction file below targets specific file glob patterns and use cases.
This file provides AI agent guidance for the project. Each instruction file below
targets specific file glob patterns and use cases.

## Instructions Overview

Expand Down
11 changes: 7 additions & 4 deletions .github/instructions/SqlServerDsc-guidelines.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ applyTo: "**"

## Resources
- Database Engine resources: inherit `SqlResourceBase`
- `SqlResourceBase` provides: `InstanceName`, `ServerName`, `Credential`, `Reasons`, `GetServerObject()`
- Add `InstanceName`, `ServerName`, and `Credential` to `$this.ExcludeDscProperties`
- `SqlResourceBase` provides: `InstanceName`, `ServerName`, `Credential`, `Reasons`, `GetServerObject()`
- Constructor: `MyResourceName() : base () { }` (no $PSScriptRoot parameter)

## SQL Server Interaction
- Always prefer SMO over T-SQL
Expand All @@ -34,6 +36,7 @@ applyTo: "**"
- Choose the appropriate group number based on the required dependencies

## Unit tests
- When unit test uses SMO types, ensure they are properly stubbed in SMO.cs
- Load stub types from SMO.cs in unit test files, e.g. `Add-Type -Path "$PSScriptRoot/../Stubs/SMO.cs"`
- After changing SMO stub types, run tests in a new PowerShell session for changes to take effect.
- When unit test tests classes or commands that contain SMO types, e.g. `[Microsoft.SqlServer.Management.Smo.*]`
- Ensure they are properly stubbed in SMO.cs
- Load SMO stub types from SMO.cs in unit test files, e.g. `Add-Type -Path "$PSScriptRoot/../Stubs/SMO.cs"`
- After changing SMO stub types, run tests in a new PowerShell session for changes to take effect.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ applyTo: "CHANGELOG.md"
- Always update the Unreleased section in CHANGELOG.md
- Use Keep a Changelog format
- Describe notable changes briefly, ≤2 items per change type
- Reference issues using format [#<issue_number>](https://github.com/<owner>/<repo>/issues/<issue_number>)
- Reference issues using format [issue #<issue_number>](https://github.com/<owner>/<repo>/issues/<issue_number>)
- No empty lines between list items in same section
- Do not add item if there are already an existing item for the same change
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ applyTo: "source/[cC]lasses/**/*.ps1"
- Decoration: `[DscResource(RunAsCredential = 'Optional')]` (replace with `'Mandatory'` if required)
- Inheritance: Must inherit `ResourceBase` (part of module DscResource.Base)
- `$this.localizedData` hashtable auto-populated by `ResourceBase` from localization file
- value-type properties: Use `[Nullable[{FullTypeName}]]` (e.g., `[Nullable[System.Int32]]`)

## Required constructor

```powershell
MyResourceName () : base ($PSScriptRoot)
{
# Property names where state cannot be enforced, e.g Ensure
# Property names where state cannot be enforced, e.g. IsSingleInstance, Force
$this.ExcludeDscProperties = @()
}
```
Expand Down Expand Up @@ -78,3 +79,19 @@ hidden [void] NormalizeProperties([System.Collections.Hashtable] $properties)
# Normalize user-provided properties, $properties contains user assigned values
}
```

## Required comment-based help

Add to .DESCRIPTION section:
- `## Requirements`: List minimum requirements
- `## Known issues`: Critical issues + pattern: `All issues are not listed here, see [all open issues](https://github.com/{owner}/{repo}/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+{ResourceName}).`

## Error Handling
- Use `try/catch` blocks to handle exceptions
- Do not use `throw` for terminating errors, use `New-*Exception` commands:
- [`New‑InvalidDataException`](https://github.com/dsccommunity/DscResource.Common/wiki/New%E2%80%91InvalidDataException)
- [`New-ArgumentException`](https://github.com/dsccommunity/DscResource.Common/wiki/New%E2%80%91ArgumentException)
- [`New-InvalidOperationException`](https://github.com/dsccommunity/DscResource.Common/wiki/New%E2%80%91InvalidOperationException)
- [`New-ObjectNotFoundException`](https://github.com/dsccommunity/DscResource.Common/wiki/New%E2%80%91ObjectNotFoundException)
- [`New-InvalidResultException`](https://github.com/dsccommunity/DscResource.Common/wiki/New%E2%80%91InvalidResultException)
- [`New-NotImplementedException`](https://github.com/dsccommunity/DscResource.Common/wiki/New%E2%80%91NotImplementedException)
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ BeforeDiscovery {
}

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

Import-Module -Name $script:dscModuleName -Force -ErrorAction 'Stop'
Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ applyTo: "source/**/*.ps1"
- Assume `$script:localizedData` is available

## String Files
- Commands/functions: `source/en-US/SqlServerDsc.strings.psd1`
- 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_SqlDscDatabase_ConnectingToDatabase`
- Format: `Verb_FunctionName_Action` (underscore separators), e.g. `Get_Database_ConnectingToDatabase`

## String Format
```powershell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,36 @@ applyTo: "**/*.[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
- One `Describe` block per file matching the tested entity name
- 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

## 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)
- 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

## Syntax Rules
- PascalCase: `Describe`, `Context`, `It`, `Should`, `BeforeAll`, `BeforeEach`, `AfterAll`, `AfterEach`
- `Context` descriptions start with 'When'
- `It` descriptions start with 'Should', must not contain 'when'
- Mock variables prefix: 'mock'
- Prefer `-BeTrue`/`-BeFalse` over `-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

## File Organization
- Class resources: `tests/Unit/Classes/{Name}.Tests.ps1`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ applyTo: "**/*.ps?(m|d)1"
### Hashtables

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

### Comments
Expand Down Expand Up @@ -79,14 +79,18 @@ applyTo: "**/*.ps?(m|d)1"
- For state-changing functions, use `SupportsShouldProcess`
- Place ShouldProcess check immediately before each state-change
- `$PSCmdlet.ShouldProcess` must use required pattern
- Use `$PSCmdlet.ThrowTerminatingError()` for terminating errors, use relevant error category
- Use `Write-Error` for non-terminating errors, use relevant error category
- Use `Write-Warning` for warnings
- Use `Write-Debug` for debugging information
- Use `Write-Verbose` for actionable information
- Use `Write-Information` for informational messages.
- Never use backtick as line continuation in production code.

## Output streams

- Never output sensitive data/secrets
- Use `Write-Debug` for: Internal diagnostics; Variable values/traces; Developer-focused details
- Use `Write-Verbose` for: High-level execution flow only; User-actionable information
- Use `Write-Information` for: User-facing status updates; Important operational messages; Non-error state changes
- Use `Write-Warning` for: Non-fatal issues requiring attention; Deprecated functionality usage; Configuration problems that don't block execution
- Use `$PSCmdlet.ThrowTerminatingError()` for terminating errors (except for classes), use relevant error category
- Use `Write-Error` for non-terminating errors, use relevant error category

## ShouldProcess Required Pattern

- Ensure `$descriptionMessage` explains what will happen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ BeforeDiscovery {
}

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

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

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

AfterAll {
Expand All @@ -57,7 +57,7 @@ AfterAll {
$PSDefaultParameterValues.Remove('Should:ModuleName')

# Unload the module being tested so that it doesn't impact any other tests.
Get-Module -Name $script:dscModuleName -All | Remove-Module -Force
Get-Module -Name $script:moduleName -All | Remove-Module -Force
}
```

Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
"wsfc",
"SOURCEBRANCH",
"SOURCEBRANCHNAME",
"setvariable"
"setvariable",
"RAISERROR"
],
"cSpell.ignorePaths": [
".git"
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added setup workflow for GitHub Copilot.
- Switch the workflow to use Linux.
- Attempt to unshallow the Copilot branch
- `SqlAgentAlert`
- Added new DSC resource to manage SQL Server Agent alerts.
- Improved AI instructions.
- Enhanced workflow with proper environment variable configuration and DSCv3 verification.
- Fixed environment variable persistence by using $GITHUB_ENV instead of
Expand Down
Loading
Loading