@@ -156,4 +156,61 @@ Describe 'Discover extension tests' {
156156 $env: DSC_RESOURCE_PATH = $null
157157 }
158158 }
159+
160+ It ' Invalid manifest from extension discovery should not fail overall discovery' {
161+ $invalidManifest = @'
162+ {
163+ "$schema": "https://aka.ms/dsc/schemas/v3/bundled/resource/manifest.json",
164+ "type": "Test/InvalidManifest",
165+ "version": "0.1.0",
166+ "get": {
167+ "executable": "dsctest",
168+ "unexpectedField": "This field is not expected in the get section and should be ignored by the discovery process"
169+ },
170+ "newProperty": "This property is not expected in the manifest and should be ignored by the discovery process"
171+ }
172+ '@
173+ $resourceScript = @'
174+ $resource = @{
175+ manifestPath = "$env:TestDrive" + [System.IO.Path]::DirectorySeparatorChar + 'invalidManifest.dsc.resource.json'
176+ }
177+ $resource | ConvertTo-Json -Compress
178+ '@
179+ $extensionManifest = @'
180+ {
181+ "$schema": "https://aka.ms/dsc/schemas/v3/bundled/resource/manifest.json",
182+ "type": "Test/DiscoverInvalid",
183+ "version": "0.1.0",
184+ "description": "Test discover resource, this is a really long description to test that the table can be rendered without truncating the description text from this extension.",
185+ "discover": {
186+ "executable": "pwsh",
187+ "args": [
188+ "-NoLogo",
189+ "-NonInteractive",
190+ "-NoProfile",
191+ "-Command",
192+ "./discover.ps1"
193+ ]
194+ }
195+ }
196+ '@
197+
198+ Set-Content - Path " $TestDrive /invalidManifest.dsc.resource.json" - Value $invalidManifest
199+ Set-Content - Path " $TestDrive /discover.ps1" - Value $resourceScript
200+ Set-Content - Path " $TestDrive /extension.dsc.extension.json" - Value $extensionManifest
201+ try {
202+ $env: DSC_RESOURCE_PATH = $TestDrive + [System.IO.Path ]::PathSeparator + $env: PATH
203+ $env: TestDrive = $TestDrive
204+ $out = dsc - l info resource list 2> $TestDrive / error.log | ConvertFrom-Json
205+ $LASTEXITCODE | Should - Be 0 - Because (Get-Content - Path " $TestDrive /error.log" - Raw | Out-String )
206+ # The invalid manifest should be skipped and not included in the discovered resources
207+ foreach ($resource in $out ) {
208+ $resource.type | Should -Not - Be ' Test/InvalidManifest'
209+ }
210+ (Get-Content - Path " $TestDrive /error.log" - Raw) | Should - BeLike " *INFO Extension 'Test/DiscoverInvalid' failed to load manifest: Invalid manifest for resource '*invalidManifest.dsc.resource.json'*" - Because (Get-Content - Path " $TestDrive /error.log" - Raw | Out-String )
211+ } finally {
212+ $env: DSC_RESOURCE_PATH = $null
213+ $env: TestDrive = $null
214+ }
215+ }
159216}
0 commit comments