Give each CreateManager(dataDirectory) its own profiles and commands [patch] - #147
Merged
Merged
Conversation
…[patch] With a service provider, CreateManager(dataDirectory) reused the singleton ICommandRegistry and IProfileManager, so managers for different directories shared profiles and saving one wrote another directory's profiles into it. It now always builds a fresh KeybindingManager for the directory. The parameterless CreateManager() doc now says it returns the DI-registered manager when there is one, rather than claiming a new instance. Fixes #114 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UnqwfbU2boDDiUoqRZSY2D
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UnqwfbU2boDDiUoqRZSY2D
|
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.



Fixes #114
Problem
When a service provider was present,
KeybindingManagerFactory.CreateManager(dataDirectory)reused the singletonICommandRegistryandIProfileManager. Only the repository was new for each directory. So two managers for different directories shared one set of profiles, and saving one wrote the other directory's profiles into itsprofiles.json.Change
CreateManager(dataDirectory)now always returnsnew KeybindingManager(dataDirectory), so every manager gets its own command registry and profile manager. This is the fix the triage comment recommended.CreateManager()keeps its current behaviour. Its doc now says it returns the DI-registered manager when there is one, instead of claiming a new instance. That avoids a behaviour change for DI consumers who rely on the singleton.Tests
New file:
Keybinding.Test/KeybindingManagerFactoryTests.cs.KeepsDirectoriesSeparate: runs the issue's reproduction. It savesuser-ain dirA, then initialises and saves dirB, and asserts that dirB neither sees nor persistsuser-a.DoesNotReuseSingletonState: asserts that the manager'sProfilesandCommandsare not the DI singletons.Both tests fail on
main(Expected condition to be false, andBoth values refer to the same object) and pass with the fix. The full suite passes: 128 of 128.🤖 Generated with Claude Code
https://claude.ai/code/session_01UnqwfbU2boDDiUoqRZSY2D
Generated by Claude Code