Add a preset library and validate presets before use - #29
Merged
Conversation
Four presets alongside gaming-rig: privacy-max, minimal-workstation, htpc and dev-box. The loader needed work first. A preset switch that did not match a feature was added to the parameter table and then dropped by the apply phase without a word, so one typo produced a run that applied nothing and still exited 0. A missing preset file only printed a warning and carried on. Neither is acceptable for a library people copy and edit. Import-PresetSwitches now throws for a preset that cannot be found or read, names a switch that does not exist, lists the same switch twice, names none at all, or selects two values from one mutually exclusive group. A missing preset lists the ones that do exist. Mutual exclusion comes from the UiGroups block already in Features.json rather than a list kept in step by hand. Nine groups are declared there, covering the taskbar, Explorer location, drive letters, alt-tab and the Start menu views. -Preset now takes a bare name, so -Preset htpc works where it used to need the full path to the json. Explicit paths still work. Six switches are dispatched by their own blocks in WinSwift.ps1 rather than through Features.json, and gaming-rig has always relied on them being accepted, so validation allows them. Presets read through LoadJsonFile, which reads UTF8, so a preset with non-ASCII in its description no longer depends on the ANSI codepage. Found while composing privacy-max: -DisableSearchHistory and -DisableSearchHighlights are declared as parameters and have both apply and undo reg files, but no Features.json entry and no handler, so passing either does nothing. Left out of the presets and reported separately rather than fixed here.
Set-Preset was declared in the Context body, which Pester executes during discovery, so the function did not exist by the time the tests ran. All six tests that called it failed in CI while everything else passed. Moved into BeforeAll, which shares the run-phase scope.
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.
Four presets alongside
gaming-rig, plus the loader work that had to come first.The loader would have shipped broken presets silently
Proved before changing anything: a preset switch that does not match a feature is added to the parameter table and then dropped by the apply phase without a word. One typo produced a run that applied nothing and exited 0. A missing preset file printed a warning and carried on. Neither is acceptable for a library people will copy and edit.
Import-PresetSwitchesnow throws for a preset that cannot be found or read, names a switch that does not exist, lists a switch twice, names none, or selects two values from one mutually exclusive group. A missing preset lists the ones that do exist:Mutual exclusion comes from the
UiGroupsblock already shipped inFeatures.json- nine declared groups - rather than a hand-maintained list. And-Preset htpcnow works; it used to require the full path.Six switches (
EnablePerformanceTweaks,DisableWindowsAds,EnableCompetitiveGaming,DisableMemoryIntegrity,DisableSettingsAds,DisableWidgetsDeep) are dispatched by explicit blocks rather thanFeatures.json;gaming-righas always relied on them, so validation accepts them. Verifiedgaming-rigpasses the new validation unchanged.The presets
privacy-maxminimal-workstationhtpcdev-boxEvery switch in every preset validated against the real catalogue: no unknowns, no duplicates, no exclusive-group conflicts. The Pester suite loads each shipped preset, so a future preset with a typo fails CI rather than shipping.
Found while composing privacy-max
-DisableSearchHistoryand-DisableSearchHighlightsare declared as parameters and have both apply and undo reg files - but noFeatures.jsonentry and no handler block. Passing either does nothing, silently. They are the only two of 145 parameters in that state (checked all of them). Left out of the presets; wiring them up is a small separate change since all four reg files already exist.Verification
All five presets load through the new path, name resolution covers bare name, name.json and explicit path, and each validation failure throws with the message shown above. 12 new Pester tests wired into CI. Static validation passes (114 files, up from 112); standalone rebuilt and parse-checked.
Not verified end to end: applying a preset needs elevation, and the mutating integration suite still needs Sandbox.