Skip to content

Give each CreateManager(dataDirectory) its own profiles and commands [patch] - #147

Merged
matt-edmondson merged 2 commits into
mainfrom
fix/factory-fresh-state-114
Sep 29, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
fix/factory-fresh-state-114

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #114

Problem

When a service provider was present, KeybindingManagerFactory.CreateManager(dataDirectory) reused the singleton ICommandRegistry and IProfileManager. 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 its profiles.json.

Change

  • CreateManager(dataDirectory) now always returns new 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 saves user-a in dirA, then initialises and saves dirB, and asserts that dirB neither sees nor persists user-a.
  • DoesNotReuseSingletonState: asserts that the manager's Profiles and Commands are not the DI singletons.

Both tests fail on main (Expected condition to be false, and Both 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

…[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
Comment thread Keybinding.Test/KeybindingManagerFactoryTests.cs Fixed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UnqwfbU2boDDiUoqRZSY2D
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 1d3d127 into main Sep 29, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the fix/factory-fresh-state-114 branch September 29, 2026 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants