fix: an added-then-deleted env variable in one session is now actually removed#1414
Merged
Conversation
…y removed ApplyChanges keeps two parallel maps: _baseline (drives the pending-change count) and _originals (the sole source for DeletedEntries()/registry deletion). The delete loop removed from both, but the add/edit loop updated only _baseline — so a freshly-added variable was never recorded in _originals. Deleting that variable later in the same session then showed '1 pending change' (RecomputePending reads _baseline) yet DeletedEntries (reads _originals) skipped it, so it was never removed from the registry and PendingChangeCount stuck at 1. A manual Refresh self-healed by reloading _originals. The apply loop now writes _originals[Key(v)] alongside _baseline[Key(v)] on a successful SetVariable, keeping the maps in lock-step. Fixes ultra-audit finding P2 #48. No unit test added: EnvironmentVariableService is a sealed concrete class with no interface seam and its SetVariable/DeleteVariable/ReadAll hit the real HKCU/HKLM Environment hive, so exercising ApplyChanges end-to-end would mutate the live user registry (forbidden by the no-system-deps unit-test rule). The fix is a symmetric one-line bookkeeping sync verifiable by inspection; a proper test is gated on the IEnvironmentVariableService seam tracked by the broader arch-seam findings.
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.
Summary
Fixes ultra-audit finding P2 #48.
EnvironmentVariablesViewModel.ApplyChangeskeeps two parallel bookkeeping maps:_baseline(Key → value) — drivesRecomputePending/ the pending-change count._originals(Key → (scope, name)) — the sole source forDeletedEntries()and the actual registry deletion.The delete loop removed the variable from both maps, but the add/edit loop updated only
_baseline— a freshly-added variable was never recorded in_originals, andApplyChangesnever re-runsLoad().Concrete failure (single session, no Refresh):
SetVariablewrites it to the registry,_baselinegets C,_originalsdoes not.RecomputePending(reads_baseline) counts C as a pending deletion → UI shows "1 pending change", butDeletedEntries(reads_originals) is empty →DeleteVariable(C)is never called. Status says "Applied 0 changes",PendingChangeCountstays stuck at 1, and C remains orphaned in the registry. (A manual Refresh self-heals by reloading_originals.)Fix
The apply loop now writes
_originals[Key(v)] = (v.Scope, v.Name)alongside_baseline[Key(v)] = v.Valueon a successfulSetVariable, keeping the two maps in lock-step (the exact invariant the existing code comment claims).Testing note
No unit test added:
EnvironmentVariableServiceis a sealed concrete class with no interface seam, and itsSetVariable/DeleteVariable/ReadAllhit the real HKCU/HKLMEnvironmenthive — exercisingApplyChangesend-to-end would mutate the live user registry, which the no-system-deps unit-test rule forbids. The fix is a symmetric one-line bookkeeping sync verifiable by inspection; a proper test is gated on introducingIEnvironmentVariableService(tracked by the broader arch-seam findings).Checks