Skip to content

refactor(session): extract SessionState into injectable class#1010

Merged
aaight merged 1 commit intodevfrom
feature/session-state-injectable-class
Mar 23, 2026
Merged

refactor(session): extract SessionState into injectable class#1010
aaight merged 1 commit intodevfrom
feature/session-state-injectable-class

Conversation

@aaight
Copy link
Copy Markdown
Collaborator

@aaight aaight commented Mar 23, 2026

Summary

  • Extracts the mutable module-level let sessionState = {...} singleton in src/gadgets/sessionState.ts into an injectable SessionState class
  • Adds createSessionState() factory for creating isolated instances (enables parallel test isolation)
  • Adds setDefaultSessionState() for dependency injection of custom instances
  • Preserves all existing exported functions (getBaseBranch, getProjectId, recordPRCreation, etc.) as thin wrappers around a _defaultInstance, so all 17 consumers work without any import changes
  • Updates tests/unit/gadgets/sessionState.test.ts to cover both the class interface and all backward-compatible module-level wrappers

Closes: https://trello.com/c/69c1983cea2a43b1e42d6391

Test plan

  • All 52 sessionState tests pass (24 original + 28 new class/factory/DI tests)
  • Full unit test suite passes (6577 tests, 0 regressions)
  • TypeScript type check passes (0 errors)
  • Biome lint passes (0 errors)

🤖 Generated with Claude Code

🕵️ claude-code · claude-sonnet-4-6 · run details

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 99.09091% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/gadgets/sessionState.ts 99.09% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Collaborator

@nhopeatall nhopeatall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 SessionState class correctly replicates all original behavior (init reset, shallow copy in getSessionState(), error recovery in deleteInitialComment)
  • SessionStateData is correctly kept as an unexported interface (consumers access properties structurally)
  • getSessionState() returns a shallow copy via spread ({ ...this.state }), matching the original behavior — the hooks object 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

@aaight aaight merged commit ef22e53 into dev Mar 23, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants