Skip to content

Commit a9e618e

Browse files
authored
Merge branch 'main' into implement-powershell-import-extension
2 parents 0682b39 + 197064c commit a9e618e

15 files changed

+435
-357
lines changed

build.ps1

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ param(
2626
$env:RUSTC_LOG=$null
2727
$env:RUSTFLAGS='-Dwarnings'
2828

29+
trap {
30+
Write-Error "An error occurred: $($_ | Out-String)"
31+
exit 1
32+
}
33+
2934
if ($Verbose) {
3035
$env:RUSTC_LOG='rustc_codegen_ssa::back::link=info'
3136
}
@@ -574,11 +579,7 @@ if ($Test) {
574579
(Get-Module -Name Pester -ListAvailable).Path
575580
}
576581

577-
try {
578-
Invoke-Pester -ErrorAction Stop
579-
} catch {
580-
throw "Pester had unexpected error: $($_.Exception.Message)"
581-
}
582+
Invoke-Pester -Output Detailed -ErrorAction Stop
582583
}
583584

584585
function Find-MakeAppx() {

dsc/tests/dsc_extension_discover.tests.ps1

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33

4+
BeforeDiscovery {
5+
try {
6+
$windowWidth = [Console]::WindowWidth
7+
} catch {
8+
$consoleUnavailable = $true
9+
}
10+
}
11+
412
Describe 'Discover extension tests' {
513
BeforeAll {
614
$oldPath = $env:PATH
@@ -15,15 +23,31 @@ Describe 'Discover extension tests' {
1523
It 'Discover extensions' {
1624
$out = dsc extension list | ConvertFrom-Json
1725
$LASTEXITCODE | Should -Be 0
18-
$out.Count | Should -Be 2 -Because ($out | Out-String)
19-
$out[0].type | Should -Be 'Microsoft.DSC.Extension/Bicep'
20-
$out[0].version | Should -Be '0.1.0'
21-
$out[0].capabilities | Should -BeExactly @('import')
22-
$out[0].manifest | Should -Not -BeNullOrEmpty
23-
$out[1].type | Should -BeExactly 'Test/Discover'
24-
$out[1].version | Should -BeExactly '0.1.0'
25-
$out[1].capabilities | Should -BeExactly @('discover')
26-
$out[1].manifest | Should -Not -BeNullOrEmpty
26+
if ($IsWindows) {
27+
$out.Count | Should -Be 3 -Because ($out | Out-String)
28+
$out[0].type | Should -Be 'Microsoft.DSC.Extension/Bicep'
29+
$out[0].version | Should -Be '0.1.0'
30+
$out[0].capabilities | Should -BeExactly @('import')
31+
$out[0].manifest | Should -Not -BeNullOrEmpty
32+
$out[1].type | Should -Be 'Microsoft.Windows.Appx/Discover'
33+
$out[1].version | Should -Be '0.1.0'
34+
$out[1].capabilities | Should -BeExactly @('discover')
35+
$out[1].manifest | Should -Not -BeNullOrEmpty
36+
$out[2].type | Should -BeExactly 'Test/Discover'
37+
$out[2].version | Should -BeExactly '0.1.0'
38+
$out[2].capabilities | Should -BeExactly @('discover')
39+
$out[2].manifest | Should -Not -BeNullOrEmpty
40+
} else {
41+
$out.Count | Should -Be 2 -Because ($out | Out-String)
42+
$out[0].type | Should -Be 'Microsoft.DSC.Extension/Bicep'
43+
$out[0].version | Should -Be '0.1.0'
44+
$out[0].capabilities | Should -BeExactly @('import')
45+
$out[0].manifest | Should -Not -BeNullOrEmpty
46+
$out[1].type | Should -BeExactly 'Test/Discover'
47+
$out[1].version | Should -BeExactly '0.1.0'
48+
$out[1].capabilities | Should -BeExactly @('discover')
49+
$out[1].manifest | Should -Not -BeNullOrEmpty
50+
}
2751
}
2852

2953
It 'Filtering works for extension discovered resources' {
@@ -94,12 +118,12 @@ Describe 'Discover extension tests' {
94118
}
95119
}
96120

97-
It 'Table can be not truncated' {
121+
It 'Table can be not truncated' -Skip:($consoleUnavailable) {
98122
$output = dsc extension list --output-format table-no-truncate
99123
$LASTEXITCODE | Should -Be 0
100124
$foundWideLine = $false
101125
foreach ($line in $output) {
102-
if ($line.Length -gt [Console]::WindowWidth) {
126+
if ($line.Length -gt $windowWidth) {
103127
$foundWideLine = $true
104128
}
105129
}

dsc/tests/dsc_resource_list.tests.ps1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33

4+
BeforeDiscovery {
5+
try {
6+
$windowWidth = [Console]::WindowWidth
7+
} catch {
8+
$consoleUnavailable = $true
9+
}
10+
}
11+
412
Describe 'Tests for listing resources' {
513
It 'dsc resource list' {
614
$resources = dsc resource list | ConvertFrom-Json -Depth 10
@@ -89,12 +97,12 @@ Describe 'Tests for listing resources' {
8997
$out | Should -BeLike "*ERROR*Adapter not found: foo`*"
9098
}
9199

92-
It 'Table is not truncated' {
100+
It 'Table is not truncated' -Skip:($consoleUnavailable) {
93101
$output = dsc resource list --output-format table-no-truncate
94102
$LASTEXITCODE | Should -Be 0
95103
$foundWideLine = $false
96104
foreach ($line in $output) {
97-
if ($line.Length -gt [Console]::WindowWidth) {
105+
if ($line.Length -gt $windowWidth) {
98106
$foundWideLine = $true
99107
break
100108
}

dsc_lib/locales/en-us.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ processChildExit = "Process '%{executable}' id %{id} exited with code %{code}"
135135
processChildTerminated = "Process '%{executable}' id %{id} terminated by signal"
136136
processTerminated = "Process terminated by signal"
137137
commandInvoke = "Invoking command '%{executable}' with args %{args}"
138+
commandCwd = "Current working directory: %{cwd}"
138139
noArgs = "No args to process"
139140
parseAsEnvVars = "Parsing input as environment variables"
140141
parseAsStdin = "Parsing input as stdin"

dsc_lib/src/discovery/command_discovery.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,10 @@ impl ResourceDiscovery for CommandDiscovery {
286286
if manifest.kind == Some(Kind::Adapter) {
287287
trace!("{}", t!("discovery.commandDiscovery.adapterFound", adapter = resource.type_name));
288288
insert_resource(&mut adapters, &resource, true);
289-
} else {
290-
trace!("{}", t!("discovery.commandDiscovery.resourceFound", resource = resource.type_name));
291-
insert_resource(&mut resources, &resource, true);
292289
}
290+
// also make sure to add adapters as a resource as well
291+
trace!("{}", t!("discovery.commandDiscovery.resourceFound", resource = resource.type_name));
292+
insert_resource(&mut resources, &resource, true);
293293
}
294294
}
295295
}
@@ -563,27 +563,20 @@ impl ResourceDiscovery for CommandDiscovery {
563563

564564
// TODO: This should be a BTreeMap of the resource name and a BTreeMap of the version and DscResource, this keeps it version sorted more efficiently
565565
fn insert_resource(resources: &mut BTreeMap<String, Vec<DscResource>>, resource: &DscResource, skip_duplicate_version: bool) {
566-
if resources.contains_key(&resource.type_name) {
567-
let Some(resource_versions) = resources.get_mut(&resource.type_name) else {
568-
resources.insert(resource.type_name.clone(), vec![resource.clone()]);
569-
return;
570-
};
566+
if let Some(resource_versions) = resources.get_mut(&resource.type_name) {
567+
debug!("Resource '{}' already exists, checking versions", resource.type_name);
571568
// compare the resource versions and insert newest to oldest using semver
572569
let mut insert_index = resource_versions.len();
573570
for (index, resource_instance) in resource_versions.iter().enumerate() {
574571
let resource_instance_version = match Version::parse(&resource_instance.version) {
575572
Ok(v) => v,
576-
Err(err) => {
577-
// write as info since PowerShell resources tend to have invalid semver
578-
info!("Resource '{}' has invalid version: {err}", resource_instance.type_name);
573+
Err(_err) => {
579574
continue;
580575
},
581576
};
582577
let resource_version = match Version::parse(&resource.version) {
583578
Ok(v) => v,
584-
Err(err) => {
585-
// write as info since PowerShell resources tend to have invalid semver
586-
info!("Resource '{}' has invalid version: {err}", resource.type_name);
579+
Err(_err) => {
587580
continue;
588581
},
589582
};

dsc_lib/src/dscresources/command_resource.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,9 @@ async fn run_process_async(executable: &str, args: Option<Vec<String>>, input: O
697697
#[allow(clippy::implicit_hasher)]
698698
pub fn invoke_command(executable: &str, args: Option<Vec<String>>, input: Option<&str>, cwd: Option<&str>, env: Option<HashMap<String, String>>, exit_codes: Option<&HashMap<i32, String>>) -> Result<(i32, String, String), DscError> {
699699
debug!("{}", t!("dscresources.commandResource.commandInvoke", executable = executable, args = args : {:?}));
700+
if let Some(cwd) = cwd {
701+
debug!("{}", t!("dscresources.commandResource.commandCwd", cwd = cwd));
702+
}
700703

701704
tokio::runtime::Builder::new_multi_thread()
702705
.enable_all()

extensions/appx/appx.tests.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33

4-
Describe 'Tests for Appx resource discovery' -Skip:(!$IsWindows){
4+
BeforeDiscovery {
5+
$runningInCI = $null -ne $env:GITHUB_RUN_ID
6+
}
7+
8+
Describe 'Tests for Appx resource discovery' -Skip:(!$IsWindows -or $runningInCI) {
59
It 'Should find DSC appx resources' {
610
$out = dsc resource list | ConvertFrom-Json
711
$LASTEXITCODE | Should -Be 0
812
$found = $false
913
foreach ($resource in $out) {
10-
if ($resource.directory.StartsWith("$env:ProgramFiles\WindowsApps\Microsoft.DesiredStateConfiguration-Private")) {
14+
if ($resource.directory.StartsWith("$env:ProgramFiles\WindowsApps")) {
1115
$found = $true
1216
break
1317
}

extensions/bicep/bicep.tests.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Describe 'Bicep extension tests' -Skip:(!$foundBicep) {
1515
$out = dsc -l trace config get -f $bicepFile 2>$TestDrive/error.log | ConvertFrom-Json
1616
$LASTEXITCODE | Should -Be 0 -Because (Get-Content -Path $TestDrive/error.log -Raw | Out-String)
1717
$out.results[0].result.actualState.output | Should -BeExactly 'Hello, world!'
18+
$bicepFile = $bicepFile.ToString().Replace('\', '\\')
1819
(Get-Content -Path $TestDrive/error.log -Raw) | Should -Match "Importing file '$bicepFile' with extension 'Microsoft.DSC.Extension/Bicep'"
1920
}
2021

@@ -28,9 +29,10 @@ resource invalid 'Microsoft.DSC.Extension/Bicep:1.0' = {
2829
properties: {
2930
output: 'This is invalid'
3031
"@
31-
$out = dsc -l trace config get -f $bicepFile 2>$TestDrive/error.log | ConvertFrom-Json
32+
dsc -l trace config get -f $bicepFile 2>$TestDrive/error.log | ConvertFrom-Json
3233
$LASTEXITCODE | Should -Be 4 -Because (Get-Content -Path $TestDrive/error.log -Raw | Out-String)
3334
$content = (Get-Content -Path $TestDrive/error.log -Raw)
35+
$bicepFile = $bicepFile.ToString().Replace('\', '\\')
3436
$content | Should -Match "Importing file '$bicepFile' with extension 'Microsoft.DSC.Extension/Bicep'"
3537
$content | Should -Match "BCP033"
3638
}

powershell-adapter/Tests/powershellgroup.config.tests.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ Describe 'PowerShell adapter resource tests' {
1515
$cacheFilePath = Join-Path $env:LocalAppData "dsc" "PSAdapterCache.json"
1616
}
1717
}
18+
1819
AfterAll {
1920
$env:PSModulePath = $OldPSModulePath
2021
}
2122

2223
BeforeEach {
23-
Remove-Item -Force -ea SilentlyContinue -Path $cacheFilePath
24+
Remove-Item -Force -ErrorAction Ignore -Path $cacheFilePath
2425
}
2526

2627
It 'Get works on config with class-based resources' {

powershell-adapter/Tests/powershellgroup.resource.tests.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ Describe 'PowerShell adapter resource tests' {
1414
$cacheFilePath = Join-Path $env:LocalAppData "dsc" "PSAdapterCache.json"
1515
}
1616
}
17+
1718
AfterAll {
1819
$env:PSModulePath = $OldPSModulePath
1920
}
2021

2122
BeforeEach {
22-
Remove-Item -Force -ea SilentlyContinue -Path $cacheFilePath
23+
Remove-Item -Force -ErrorAction Ignore -Path $cacheFilePath
2324
}
2425

2526
It 'Discovery includes class-based resources' {
@@ -173,7 +174,7 @@ Describe 'PowerShell adapter resource tests' {
173174
# remove the module files
174175
Remove-Item -Recurse -Force -Path "$TestDrive/TestClassResource"
175176
# verify that cache rebuid happened
176-
dsc -l trace resource list '*' -a Microsoft.DSC/PowerShell 2> $TestDrive/tracing.txt
177+
$null = dsc -l trace resource list '*' -a Microsoft.DSC/PowerShell 2> $TestDrive/tracing.txt
177178

178179
$LASTEXITCODE | Should -Be 0
179180
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Detected non-existent cache entry'

0 commit comments

Comments
 (0)