-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Problem Statement
WorktreeCreator violates Single Responsibility Principle with 9 private methods handling URL parsing, git operations, external tools, file I/O, and user interaction. 490 lines makes it difficult to test, maintain, and extend.
Current Responsibilities
- URL parsing and validation (
_parse_github_url) - Git remote detection (
_detect_git_remote) - Branch name generation (
_generate_branch_name,_sanitize_title) - Branch conflict handling (
_check_branch_conflict) - Worktree creation (
_create_worktree) - File writing (
_write_task_file) - Editor opening (
_open_shuvcode) - Orchestration (
create_from_github_url)
Proposed Solution
Split into focused classes with single responsibilities using dependency injection.
Implementation Steps:
- Create
url_parser.pywith URL parsing logic - Create
branch_namer.pywith branch name generation - Create
worktree_manager.pywith worktree management interface - Create
workmux_manager.pyimplementing worktree manager - Refactor
WorktreeCreatorto pure orchestrator (~150 lines) - Implement dependency injection for all services
- Add unit tests for each new class
- Update integration tests for refactored structure
Alternative Approaches
- Use dependency injection container (e.g.,
dependency-injector) - Implement builder pattern for complex initialization
- Use composition over inheritance for flexibility
Area
- Refactoring
Estimated Effort
- Medium (1-2d)
Acceptance Criteria
- WorktreeCreator reduced to < 200 lines (from 490)
- Each new class has single responsibility (< 150 lines)
- All existing tests pass after refactoring
- New classes have proper unit tests
- Dependency injection allows easy testing
- Interfaces/protocols enable alternative implementations
Related Issues
None
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels