Skip to content

Conversation

@newhook
Copy link
Owner

@newhook newhook commented Jan 30, 2026

Summary

This PR extracts interfaces and refactors the control package to enable unit testing without external dependencies (CLI tools, services, file system operations).

Changes

  • Created ControlPlane struct with dependency injection (internal/control/plane.go)

    • Accepts interfaces for: git.Operations, worktree.Operations, zellij.SessionManager, mise.Operations, feedback.Processor
    • Added OrchestratorSpawner and WorkDestroyer interfaces for additional abstraction
    • Provides NewControlPlane() constructor with production defaults
    • Provides NewControlPlaneWithDeps() constructor for testing with mock dependencies
    • Moved all handler methods to be methods on ControlPlane
  • Extracted feedback.Processor interface (internal/feedback/interface.go)

    • Defines ProcessPRFeedback() method for abstracting PR feedback processing
    • Created DefaultProcessor implementation that wraps existing ProcessPRFeedbackQuiet() function
  • Updated control loop (internal/control/loop.go)

    • Added RunControlPlaneLoopWithControlPlane() for testing with injected dependencies
    • Added ProcessAllDueTasksWithControlPlane() for testing
    • Task handlers are now retrieved from ControlPlane.GetTaskHandlers()
  • Removed orphaned handler files

    • handler_create_worktree.go - now ControlPlane.HandleCreateWorktreeTask()
    • handler_spawn_orchestrator.go - now ControlPlane.HandleSpawnOrchestratorTask()
    • handler_pr_feedback.go - now ControlPlane.HandlePRFeedbackTask()
    • handler_git_push.go - now ControlPlane.HandleGitPushTask()
    • handler_destroy_worktree.go - now ControlPlane.HandleDestroyWorktreeTask()

Issues Resolved

  • ac-a7av: Extract interfaces for testability in control and orchestration packages (epic)
  • ac-a7av.1: Create ControlPlane struct with dependency injection
  • ac-a7av.2: Extract feedback.Processor interface
  • ac-a7av.3: Remove orphaned handler files from control package

Breaking Changes

None. The public API remains unchanged - RunControlPlaneLoop() and ProcessAllDueTasks() continue to work with default production dependencies.

Test Plan

  • Verify go build succeeds
  • Run existing integration tests with go test ./...
  • Future: Add unit tests using mock implementations of the extracted interfaces

🤖 Generated with Claude Code

newhook and others added 4 commits January 29, 2026 22:19
- Create feedback.Processor interface in internal/feedback/interface.go
  with DefaultProcessor implementation wrapping ProcessPRFeedbackQuiet
- Create ControlPlane struct in internal/control/plane.go with:
  - git.Operations, worktree.Operations, zellij.SessionManager
  - mise.Operations factory, feedback.Processor
  - OrchestratorSpawner and WorkDestroyer interfaces
  - NewControlPlane() with defaults, NewControlPlaneWithDeps() for testing
- Update loop.go to use ControlPlane with RunControlPlaneLoopWithControlPlane
  and ProcessAllDueTasksWithControlPlane for testing

This enables unit testing of control plane tasks without external
dependencies (CLI tools, services, file system operations).

Closes: ac-a7av, ac-a7av.1, ac-a7av.2

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Delete standalone handler functions that are now implemented as methods
on ControlPlane in plane.go:
- handler_create_worktree.go
- handler_spawn_orchestrator.go
- handler_pr_feedback.go
- handler_git_push.go
- handler_destroy_worktree.go

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Keep handlers in their original files to minimize PR diff churn.
The handlers are now methods on ControlPlane using injected
dependencies instead of standalone functions creating instances.

Also make processPRFeedbackQuiet internal since it's only used
within the feedback package.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Revert unnecessary variable renames and comment changes to keep
the diff focused on the actual interface extraction changes.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@newhook newhook merged commit 17804dc into main Jan 30, 2026
3 checks passed
@newhook newhook deleted the feat/extract-interfaces-for-testability-in-control-and branch January 30, 2026 04:52
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