diff --git a/adapters/powershell/Tests/TestAdapter/testadapter.resource.ps1 b/adapters/powershell/Tests/TestAdapter/testadapter.resource.ps1 index 4dae5e0ac..85d5de051 100644 --- a/adapters/powershell/Tests/TestAdapter/testadapter.resource.ps1 +++ b/adapters/powershell/Tests/TestAdapter/testadapter.resource.ps1 @@ -64,6 +64,15 @@ switch ($Operation) { )} | ConvertTo-Json -Depth 10 -Compress } 'Validate' { - @{ valid = $true } | ConvertTo-Json + # Test validation with reason field + if ($inputobj.resources[0].properties.TestCaseId -eq 99) { + @{ + valid = $false + reason = "TestCaseId 99 is not allowed for testing purposes" + } | ConvertTo-Json + } + else { + @{ valid = $true } | ConvertTo-Json + } } } diff --git a/adapters/powershell/Tests/powershellgroup.resource.tests.ps1 b/adapters/powershell/Tests/powershellgroup.resource.tests.ps1 index 9efd22a72..a85cb4076 100644 --- a/adapters/powershell/Tests/powershellgroup.resource.tests.ps1 +++ b/adapters/powershell/Tests/powershellgroup.resource.tests.ps1 @@ -315,6 +315,23 @@ Describe 'PowerShell adapter resource tests' { } } + It 'Verify validate operation shows reason on adapted resource' { + $oldPath = $env:PATH + try { + $adapterPath = Join-Path $PSScriptRoot 'TestAdapter' + $env:PATH += [System.IO.Path]::PathSeparator + $adapterPath + + # Test with invalid TestCaseId that should trigger validation failure with reason + $r = '{"TestCaseId": 99}' | dsc resource get -r 'Test/TestCase' -f - 2>&1 + $LASTEXITCODE | Should -Not -Be 0 + $errorOutput = $r | Out-String + $errorOutput | Should -Match "TestCaseId 99 is not allowed for testing purposes" + } + finally { + $env:PATH = $oldPath + } + } + It 'Dsc can process large resource output' -Pending { try { $env:TestClassResourceResultCount = 5000 # with sync resource invocations this was not possible diff --git a/lib/dsc-lib/src/dscresources/command_resource.rs b/lib/dsc-lib/src/dscresources/command_resource.rs index 8d7001c03..4ccac3985 100644 --- a/lib/dsc-lib/src/dscresources/command_resource.rs +++ b/lib/dsc-lib/src/dscresources/command_resource.rs @@ -866,7 +866,8 @@ fn verify_json(resource: &ResourceManifest, cwd: &Path, json: &str) -> Result<() return Ok(()); } - return Err(DscError::Validation(t!("dscresources.commandResource.resourceInvalidJson").to_string())); + let reason = result.reason.unwrap_or_else(|| t!("dscresources.commandResource.resourceInvalidJson").to_string()); + return Err(DscError::Validation(reason)); } // otherwise, use schema validation