Skip to content

Conversation

@newhook
Copy link
Owner

@newhook newhook commented Jan 29, 2026

Summary

This PR extracts interfaces from packages that directly call external CLIs or HTTP APIs, enabling unit testing without external dependencies. Callers explicitly create instances via constructors and pass them as parameters for dependency injection.

Changes

internal/worktree/worktree.go

  • Define Operations interface with methods: Create, CreateFromExisting, RemoveForce, List, ExistsPath
  • Create CLIOperations struct implementing the interface
  • Add NewOperations() constructor for creating instances
  • Callers create operations and pass them through the call chain

internal/git/git.go

  • Define Operations interface with methods: PushSetUpstream, Pull, Clone, FetchBranch, BranchExists, ValidateExistingBranch, ListBranches
  • Create CLIOperations struct implementing the interface
  • Add NewOperations() constructor for creating instances
  • Callers create operations and pass them through the call chain

internal/claude/inline.go

  • Define Runner interface with Run method
  • Create CLIRunner struct implementing the interface
  • Add NewRunner() constructor for creating instances
  • processTask and executeTask accept Runner parameter for injection

internal/linear/client.go

  • Define ClientInterface with methods: GetIssue, SearchIssues, ListIssues, GetIssueComments
  • Add compile-time check that Client implements ClientInterface

internal/linear/fetcher.go

  • Change Fetcher.client field type from *Client to ClientInterface
  • Add NewFetcherWithClient constructor for injecting mock clients in tests

Design Decisions

  • No global state: removed Default variables and package-level convenience functions
  • Explicit dependency injection: callers create instances and pass them as parameters
  • All interfaces include compile-time checks: var _ Interface = (*impl)(nil)
  • Constructors return interface types for flexibility

Issues Resolved

  • Closes ac-ynyu: Extract interfaces for testability (epic)
  • Closes ac-naao: Extract Runner interface from claude package
  • Closes ac-nn90: Extract ClientInterface from linear package
  • Closes ac-woty: Extract Operations interface from worktree package

Test Plan

  • Code compiles successfully
  • Existing tests pass
  • Integration tests can now mock these interfaces for isolated testing

🤖 Generated with Claude Code

newhook and others added 5 commits January 29, 2026 09:24
- Add worktree.Operations interface with cliOperations implementation
- Add claude.Runner interface with cliRunner implementation
- Add linear.ClientInterface with compile-time check
- Add NewFetcherWithClient constructor for testing with mock clients
- All interfaces follow established patterns from git.go, mise.go, zellij.go
- Backwards compatible: package-level functions delegate to Default

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Replace global Default variable and Run convenience function with explicit
NewRunner() constructor. Callers now create Runner instances directly,
eliminating hidden global state and making dependencies clearer.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Pass claude.Runner as a parameter to processTask and executeTask functions,
enabling mock injection for testing. Runner is created once at the entry
point and passed down the call chain.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
…ages

Replace global Default variables and convenience functions with explicit
NewOperations() constructors. Callers now create Operations instances
directly, eliminating hidden global state.

- git: Remove Default, PushSetUpstreamInDir, PullInDir, Clone, FetchBranch,
  BranchExists, ValidateExistingBranch, ListBranches convenience functions
- worktree: Remove Default, Create, CreateFromExisting, RemoveForce, List,
  ExistsPath convenience functions
- Update all callers to use NewOperations() pattern

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Explicitly ignore errors from wtOps.RemoveForce cleanup operations
- Fixes errcheck linter violations at lines 320, 340, 359, and 366
- Uses _ = pattern to indicate intentional error ignoring
@newhook newhook merged commit 8044199 into main Jan 29, 2026
3 checks passed
@newhook newhook deleted the feat/extract-interfaces-for-testability-2 branch January 29, 2026 15:43
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