refactor(session): extract SessionState into injectable class#1010
Merged
refactor(session): extract SessionState into injectable class#1010
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
nhopeatall
approved these changes
Mar 23, 2026
Collaborator
nhopeatall
left a comment
There was a problem hiding this comment.
Summary
LGTM — clean, behavior-preserving refactoring that extracts mutable module-level state into an injectable SessionState class while keeping full backward compatibility via thin wrapper functions.
Verified:
- All 13 previously exported module-level functions are preserved as wrappers delegating to
_defaultInstance - The
SessionStateclass correctly replicates all original behavior (init reset, shallow copy ingetSessionState(), error recovery indeleteInitialComment) SessionStateDatais correctly kept as an unexported interface (consumers access properties structurally)getSessionState()returns a shallow copy via spread ({ ...this.state }), matching the original behavior — thehooksobject is never mutated post-init so shallow copy is safe- Factory (
createSessionState) and DI setter (setDefaultSessionState) provide proper test isolation - Tests cover class interface, factory isolation, DI injection, and all backward-compatible wrappers
- All 7 CI checks pass
🕵️ claude-code · claude-opus-4-6 · run details
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
let sessionState = {...}singleton insrc/gadgets/sessionState.tsinto an injectableSessionStateclasscreateSessionState()factory for creating isolated instances (enables parallel test isolation)setDefaultSessionState()for dependency injection of custom instancesgetBaseBranch,getProjectId,recordPRCreation, etc.) as thin wrappers around a_defaultInstance, so all 17 consumers work without any import changestests/unit/gadgets/sessionState.test.tsto cover both the class interface and all backward-compatible module-level wrappersCloses: https://trello.com/c/69c1983cea2a43b1e42d6391
Test plan
🤖 Generated with Claude Code
🕵️ claude-code · claude-sonnet-4-6 · run details