From 825fc5d3f07fdda2c7337f4c30a8a12d2942c91e Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Fri, 16 Oct 2026 13:53:30 +0200 Subject: [PATCH] Fix manifest arrays and WinGet result handling --- src/Manifest.psm1 | 19 ++++++++++++------- src/Packages.psm1 | 2 +- tests/Configs.Tests.ps1 | 11 ++++++----- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Manifest.psm1 b/src/Manifest.psm1 index 79ed98a..86f13bb 100644 --- a/src/Manifest.psm1 +++ b/src/Manifest.psm1 @@ -93,7 +93,8 @@ function Read-ManifestFile { if ([string]::IsNullOrWhiteSpace([string](Get-OptionalProperty $manifest 'name'))) { throw "Manifest name is required in '$Path'." } if ($manifest.name -notmatch '^[a-z0-9][a-z0-9-]*$') { throw "Invalid manifest name '$($manifest.name)'." } if ($Kind -eq 'machine') { - $profiles = Get-OptionalProperty $manifest 'profiles' + $profilesProperty = $manifest.PSObject.Properties['profiles'] + $profiles = if ($null -ne $profilesProperty) { $profilesProperty.Value } else { $null } if ($profiles -isnot [System.Array] -or $profiles.Count -eq 0) { throw "Machine '$($manifest.name)' requires at least one profile." } $uniqueProfiles = [System.Collections.Generic.HashSet[string]]::new([System.StringComparer]::OrdinalIgnoreCase) foreach ($profile in $profiles) { @@ -102,8 +103,12 @@ function Read-ManifestFile { } } } - Assert-ItemList (Get-OptionalProperty $manifest 'packages' @()) package "$Path.packages" - Assert-ItemList (Get-OptionalProperty $manifest 'configs' @()) config "$Path.configs" + foreach ($listName in @('packages', 'configs')) { + $listProperty = $manifest.PSObject.Properties[$listName] + if ($null -ne $listProperty -and $listProperty.Value -isnot [System.Array]) { throw "$Path.$listName must be an array." } + } + Assert-ItemList -Items @(Get-OptionalProperty $manifest 'packages' @()) -Kind package -Location "$Path.packages" + Assert-ItemList -Items @(Get-OptionalProperty $manifest 'configs' @()) -Kind config -Location "$Path.configs" return $manifest } @@ -147,11 +152,11 @@ function Resolve-MachineManifest { $profilePath = Join-Path $RepositoryRoot "profiles/$profileName.json" $profile = Read-ManifestFile $profilePath profile if ($profile.name -ne $profileName) { throw "Profile filename and manifest name do not match for '$profileName'." } - Add-ManifestItems $packages (Get-OptionalProperty $profile 'packages' @()) package - Add-ManifestItems $configs (Get-OptionalProperty $profile 'configs' @()) config + Add-ManifestItems -Target $packages -Items @(Get-OptionalProperty $profile 'packages' @()) -Kind package + Add-ManifestItems -Target $configs -Items @(Get-OptionalProperty $profile 'configs' @()) -Kind config } - Add-ManifestItems $packages (Get-OptionalProperty $machineManifest 'packages' @()) package - Add-ManifestItems $configs (Get-OptionalProperty $machineManifest 'configs' @()) config + Add-ManifestItems -Target $packages -Items @(Get-OptionalProperty $machineManifest 'packages' @()) -Kind package + Add-ManifestItems -Target $configs -Items @(Get-OptionalProperty $machineManifest 'configs' @()) -Kind config $destinations = [System.Collections.Generic.HashSet[string]]::new([System.StringComparer]::OrdinalIgnoreCase) foreach ($config in $configs.Values) { diff --git a/src/Packages.psm1 b/src/Packages.psm1 index e2bdcd3..ba996ae 100644 --- a/src/Packages.psm1 +++ b/src/Packages.psm1 @@ -1,6 +1,6 @@ Set-StrictMode -Version Latest -$script:WingetNoApplicableUpgrade = [uint32]0x8A15002B +$script:WingetNoApplicableUpgrade = [Convert]::ToUInt32('8A15002B', 16) function Test-VersionGreaterThan { param([string]$Left, [string]$Right) diff --git a/tests/Configs.Tests.ps1 b/tests/Configs.Tests.ps1 index ed01134..344ae37 100644 --- a/tests/Configs.Tests.ps1 +++ b/tests/Configs.Tests.ps1 @@ -5,12 +5,13 @@ BeforeAll { Describe 'Configuration deployment' { BeforeEach { - $script:repo = Join-Path $TestDrive 'repo' - $script:data = Join-Path $TestDrive 'data' - $script:destination = Join-Path $TestDrive 'user/config.txt' + $caseRoot = Join-Path $TestDrive ([guid]::NewGuid().ToString('N')) + $script:repo = Join-Path $caseRoot 'repo' + $script:data = Join-Path $caseRoot 'data' + $script:destination = Join-Path $caseRoot 'user/config.txt' New-Item -ItemType Directory "$repo/configs" -Force | Out-Null 'version one' | Set-Content "$repo/configs/config.txt" -NoNewline - $script:settings = @{ userPaths = @{ APPDATA = $TestDrive; LOCALAPPDATA = $TestDrive; USERPROFILE = $TestDrive; PROGRAMDATA = $TestDrive } } + $script:settings = @{ userPaths = @{ APPDATA = $caseRoot; LOCALAPPDATA = $caseRoot; USERPROFILE = $caseRoot; PROGRAMDATA = $caseRoot } } $script:state = @{ schemaVersion = 1; configs = @{} } $script:paths = Get-ConfigCentralPaths -DataRoot $data Initialize-ConfigCentralData $paths @@ -52,7 +53,7 @@ Describe 'Configuration deployment' { } It 'handles spaces and non-ASCII target names' { - $configs[0].target = Join-Path $TestDrive 'Données utilisateur/a file.txt' + $configs[0].target = Join-Path (Split-Path -Parent $repo) 'Données utilisateur/a file.txt' $plan = Get-ConfigPlan -Configs $configs -RepositoryRoot $repo -State $state -Settings $settings (Invoke-ConfigOperation -Operation $plan[0] -Paths $paths -State $state).status | Should -Be 'Succeeded' Test-Path -LiteralPath $configs[0].target | Should -BeTrue