Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Added a Test
Checks if the ResourceId ends with the [<ResourceName>]<Resourcename to prevent `DependsOn` Issues with the DSCWorkshop Framework.
Comment on lines +10 to +11
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix the documented ResourceID suffix example.

[<ResourceName>]<Resourcename is malformed and does not match the pattern the new test is asserting, so the changelog entry is misleading as written.

Suggested wording
-- Added a Test
-  Checks if the ResourceId ends with the [<ResourceName>]<Resourcename to prevent `DependsOn` Issues with the DSCWorkshop Framework.
+- Added a test that verifies composite `ResourceID` values end with `::[<ResourceName>]<ResourceName>` to prevent `DependsOn` issues in the DSCWorkshop framework.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@CHANGELOG.md` around lines 10 - 11, The changelog entry contains a malformed
example suffix "[<ResourceName>]<Resourcename" that doesn't match the test's
asserted pattern for ResourceId; update the text so the example uses the correct
casing and bracketed pattern that the test validates (e.g., use
"[<ResourceName>]<ResourceName>" or the exact pattern your test asserts), and
ensure the entry references the ResourceId, ResourceName, DependsOn and
DSCWorkshop Framework consistently so the documented example matches the
implemented assertion.


## [0.12.0] - 2026-02-24

### Changed
Expand Down
13 changes: 13 additions & 0 deletions tests/Unit/DSCResources/DscResources.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,19 @@ configuration "Config_$dscResourceName" {
$mofFile | Should -BeOfType System.IO.FileInfo
}

It "'<DscResourceName>' has ResourceIDs ending with [<DscResourceName>]<DscResourceName>" -TestCases $testCases {
if ($Skip)
{
Set-ItResult -Skipped -Because "Tests for '$DscResourceName' are skipped"
}
$mofContent = Get-Content -Raw -Path "$($OutputDirectory)\localhost_$dscResourceName.mof"
$selectString = Select-String -InputObject $mofContent -Pattern 'ResourceID = ".+' -AllMatches
foreach ($value in $selectString.Matches | Select-Object -ExpandProperty Value)
{
$value | Should -Match -RegularExpression "(ResourceID = `".*)(:{2}\[$DscResourceName\]$DscResourceName`";)"
Comment on lines +231 to +234
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

In Pester v5, is Should -Match -RegularExpression ""valid syntax, or must the regex be passed positionally asShould -Match ""?

💡 Result:

Yes—Should -Match -RegularExpression "<pattern>" is valid Pester v5 syntax; -RegularExpression is a named parameter for the -Match assertion. The regex can also be passed positionally as Should -Match "<pattern>" (equivalent). [1], [2]


🏁 Script executed:

#!/bin/bash

# Test Select-String behavior when no matches are found
pwsh -NoProfile -Command @'
# Simulate content with no matching ResourceID pattern
$content = "Some other content without ResourceID"
$selectString = Select-String -InputObject $content -Pattern 'ResourceID = ".+' -AllMatches
Write-Host "selectString result: $selectString"
Write-Host "selectString is null: $($selectString -eq $null)"

if ($selectString) {
    $matches = $selectString.Matches | Select-Object -ExpandProperty Value
    Write-Host "matches: $matches"
    Write-Host "matches count: $($matches.Count)"
    $runCount = 0
    foreach ($value in $matches) {
        $runCount++
    }
    Write-Host "foreach executed $runCount times"
} else {
    Write-Host "selectString is falsy, foreach would not run"
}

Write-Host ""
Write-Host "Testing with actual matches:"
# Simulate content WITH matching ResourceID pattern
$content2 = 'ResourceID = "something"'
$selectString2 = Select-String -InputObject $content2 -Pattern 'ResourceID = ".+' -AllMatches
Write-Host "selectString2 result: $selectString2"
Write-Host "selectString2 matches count: $($selectString2.Matches.Count)"
foreach ($value in $selectString2.Matches | Select-Object -ExpandProperty Value) {
    Write-Host "Found: $value"
}
'@

Repository: dsccommunity/CommonTasks

Length of output: 237


🏁 Script executed:

#!/bin/bash
pwsh -NoProfile << 'EOF'
# Test Select-String behavior when no matches are found
$content = "Some other content without ResourceID"
$selectString = Select-String -InputObject $content -Pattern 'ResourceID = ".+' -AllMatches
Write-Host "selectString result: $selectString"
Write-Host "selectString is null: $($null -eq $selectString)"

if ($selectString) {
    $matches = $selectString.Matches | Select-Object -ExpandProperty Value
    Write-Host "matches: $matches"
    Write-Host "matches count: $($matches.Count)"
} else {
    Write-Host "selectString is null/falsy, foreach would not execute"
}

Write-Host ""
Write-Host "Testing with actual matches:"
# Simulate content WITH matching ResourceID pattern
$content2 = 'ResourceID = "something"'
$selectString2 = Select-String -InputObject $content2 -Pattern 'ResourceID = ".+' -AllMatches
Write-Host "selectString2 result: $selectString2"
Write-Host "selectString2 matches count: $($selectString2.Matches.Count)"
foreach ($value in $selectString2.Matches | Select-Object -ExpandProperty Value) {
    Write-Host "Found: $value"
}
EOF

Repository: dsccommunity/CommonTasks

Length of output: 1726


Add a check to ensure at least one ResourceID match exists before the foreach loop.

The foreach loop will not execute if Select-String returns $null (no matches found), causing the test to pass without validating any ResourceID lines. Add $selectString.Matches.Count | Should -BeGreaterThan 0 or equivalent after the Select-String call and before the loop.

Note: The -RegularExpression parameter is valid Pester v5 syntax and does not need to be removed.

🧰 Tools
🪛 PSScriptAnalyzer (1.24.0)

[warning] Missing BOM encoding for non-ASCII encoded file 'DscResources.Tests.ps1'

(PSUseBOMForUnicodeEncodedFile)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/Unit/DSCResources/DscResources.Tests.ps1` around lines 231 - 234, Add
an explicit assertion that Select-String found matches before iterating: after
the $selectString = Select-String -InputObject $mofContent -Pattern 'ResourceID
= ".+' call and before the foreach ($value in $selectString.Matches ...) loop,
assert that $selectString.Matches.Count | Should -BeGreaterThan 0 (or
equivalent) so the test fails when no ResourceID lines are present; reference
the $selectString variable, the Select-String invocation, and the foreach loop
when making the change.

}
}

AfterAll {
Remove-Item -Path C:\Temp\JeaRoleTest.ps1
if (-not $tempExists)
Expand Down
Loading