Roll back the modules' registry writes on a failed apply (Scope B) - #52
Merged
Merged
Conversation
Automatic rollback already reverted the modules' non-registry state (Scope A: services, firewall, HOSTS, tasks, SMB1) but reported their imperative registry writes as "not restored". This closes that gap for the three registry-writing modules: SecurityHardening, ExtendedAIPurge, GamingMode. Each module now declares the exact (Path, Name) targets it writes as data via Get-<Module>RegistryTargets, so the snapshot cannot drift from the apply. Before applying, BackupModuleState captures each target's current value and type (or records that it did not exist); on rollback it writes the original back with its type, or removes a value the module created. Restoring all captured targets is safe even for a module that did not run, because they were captured pre-apply. One-way operations (Recall component removal) and the powercfg power-plan change stay reported as not restored. GamingMode's per-interface Nagle values are enumerated at capture time. Tests: Scope B restore paths, provider contents, and an AST drift guard that asserts every Set-ItemProperty name in each module is declared by its provider. Also wired Test-ModuleRollback and Test-ConfigConsistency into CI; both existed but were never run there.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Completes full-module rollback. Scope A (merged in #45) reverted the modules' non-registry state on a failed apply but reported their imperative registry writes as "not restored". Scope B closes that gap for the three registry-writing modules: SecurityHardening, ExtendedAIPurge, GamingMode.
Design (as agreed: expose write targets as data so the snapshot can't drift)
Get-<Module>RegistryTargetsreturning the exact(Path, Name)values it writes.BackupModuleStatesnapshots each target's current value and type before apply (or records absence).powercfgpower-plan change stay reported as not restored. GamingMode's per-interface Nagle values are enumerated at capture time.Validation
Tests\Invoke-StaticValidation.ps1 -RequirePSScriptAnalyzerclean (122 files).Set-ItemPropertyname in each module is declared by its provider.Test-ModuleRollback.ps1andTest-ConfigConsistency.ps1into CI — both existed but were never run there.Not run here (mutating, needs Sandbox): the live capture-apply-fail-restore cycle against the real registry. The snapshot/restore logic and the real read path are covered as above.