Fix manifest arrays and WinGet result handling

This commit is contained in:
Dandaedre 2026-10-16 13:53:30 +02:00
parent 99aaa17e69
commit 825fc5d3f0
3 changed files with 19 additions and 13 deletions

View File

@ -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) {

View File

@ -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)

View File

@ -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