fix(registry-restore): continue restoring remaining keys when one fails (#837)

Co-authored-by: Jeffrey <9938813+Raphire@users.noreply.github.com>
This commit is contained in:
Ahmad Z. Shatnawi
2026-11-08 23:59:47 +01:00
committed by GitHub
co-authored by Jeffrey
parent e6184a2597
commit f39885f6f2
16 changed files with 103 additions and 5 deletions
+29
View File
@@ -195,6 +195,35 @@ Describe 'Restore-RegistryBackupState' {
Should -Invoke Restore-RegistryKeySnapshot -Times 0 -Exactly
}
It 'continues restoring remaining snapshots when one fails, then reports the failure' {
Mock Write-Warning {}
Mock Restore-RegistryKeySnapshot { throw 'access denied' } -ParameterFilter { $Snapshot.Path -eq 'HKEY_CURRENT_USER\Software\One' }
{ Restore-RegistryBackupState -Backup $script:backup } |
Should -Throw 'Registry restore finished with 1 failed key(s). See console for details.'
Should -Invoke Restore-RegistryKeySnapshot -Times 2 -Exactly
Should -Invoke Restore-RegistryKeySnapshot -Times 1 -Exactly -ParameterFilter { $Snapshot.Path -eq 'HKEY_CURRENT_USER\Software\Two' }
}
It 'rejects a malformed backup before restoring any snapshot' {
$script:backup.RegistryKeys = @(
[PSCustomObject]@{ Path = 'HKEY_CURRENT_USER\Software\One'; Exists = $true; Values = @(); SubKeys = @() }
[PSCustomObject]@{
Path = 'HKEY_CURRENT_USER\Software\Two'; Exists = $true; Values = @()
SubKeys = @(
[PSCustomObject]@{ Path = 'HKEY_CURRENT_USER\Software\Two\Child'; Exists = $true; Values = @(); SubKeys = @() }
[PSCustomObject]@{ Path = 'HKEY_CURRENT_USER\Software\Two\Child'; Exists = $true; Values = @(); SubKeys = @() }
)
}
)
{ Restore-RegistryBackupState -Backup $script:backup } |
Should -Throw '*duplicate or unsupported registry child path*'
Should -Invoke Restore-RegistryKeySnapshot -Times 0 -Exactly
}
}
Describe 'Restore executable warning dialog' {