Skip to content

Extract ShellRunning protocol to enable test mocking of git operations #241

@bguidolim

Description

@bguidolim

Context

PackFetcherOperationTests creates real local git repos as test fixtures, running actual git init, git commit, git clone etc. via ShellRunner. This causes flaky failures when environment tools (e.g. 1Password SSH agent) intercept git signing:

error: 1Password: agent returned an error
fatal: failed to write commit object

The root cause is that ShellRunner is a concrete struct with no protocol abstraction, making it impossible to inject a mock in tests.

Prior art

ClaudeCLI was already extracted into a protocol (ClaudeIntegration: ClaudeCLI) with MockClaudeCLI in TestHelpers.swift (PR #239). The same pattern should be applied to ShellRunner.

Proposed approach

  1. Extract a ShellRunning protocol from ShellRunner with the key methods (run, commandExists)
  2. Change all injection sites to accept any ShellRunning:
    • PackFetcher, LockfileOperations, Configurator, ComponentExecutor
    • ScriptRunner, PromptExecutor, GitignoreManager, Homebrew
  3. Create MockShellRunner in TestHelpers.swift that records calls and returns canned ShellResult values
  4. Rewrite PackFetcherOperationTests to use MockShellRunner instead of real git repos
  5. Enable testing of LockfileOperations git checkout/fetch retry logic (currently untestable — guard-path tests only)

Scope

~15+ files inject ShellRunner as a stored property. The protocol extraction itself is mechanical but touches many files.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions