Skip to content

[#241] Extract ShellRunning protocol for test mocking#277

Merged
bguidolim merged 2 commits intomainfrom
bruno/241-shell-running-protocol
Mar 23, 2026
Merged

[#241] Extract ShellRunning protocol for test mocking#277
bguidolim merged 2 commits intomainfrom
bruno/241-shell-running-protocol

Conversation

@bguidolim
Copy link
Copy Markdown
Collaborator

@bguidolim bguidolim commented Mar 23, 2026

Summary

Extracts a ShellRunning protocol from the concrete ShellRunner struct, enabling test mocks that avoid real process spawning. This eliminates flaky CI failures caused by 1Password SSH agent intercepting git signing in PackFetcherOperationTests, and adds mock-based coverage for LockfileOperations git checkout/retry logic.

Follows the same pattern established by the ClaudeCLI protocol extraction in PR #239.

Closes #241

Changes

  • Add protocol ShellRunning: Sendable in ShellRunner.swift with protocol extension for default parameter values; conform ShellRunner: ShellRunning
  • Change let shell: ShellRunnerlet shell: any ShellRunning across 16 production files (Core, ExternalPack, Install modules)
  • Add MockShellRunner in TestHelpers.swift following the MockClaudeCLI pattern (records calls, returns canned results via runResults/shellResults queues)
  • Replace real-git PackFetcherOperationTests with mock-based unit tests covering fetch, update, currentCommit, and retry logic
  • Add mock-based LockfileOperationsTests for checkoutLockedCommits git checkout/fetch retry paths
  • Extract shared makeTmpDir(label:), makeRegistryEntry, and makeLocalRegistryEntry test helpers to eliminate duplication across 8 test files

Test plan

  • swift test passes locally (806 tests, 0 failures)
  • swiftformat --lint . and swiftlint pass without violations
  • Affected commands verified with a real pack (e.g. mcs sync, mcs doctor)
Checklist for engine changes

Not applicable — no engine behavior changes, only type signature widening and test improvements.

- Add ShellRunning protocol with MockShellRunner, replacing real git
  in PackFetcherTests and adding mock-based LockfileOperations tests
- Change ShellRunner → any ShellRunning across 16 production files
- Extract shared makeTmpDir and makeRegistryEntry test helpers
- Record additionalEnvironment in MockShellRunner call structs
- Remove duplicate default parameter values from ShellRunner
- Extract makeUpdateFixture helper for PackFetcher update tests
- Add missing error-path tests: refNotFound and updateFailed
@bguidolim bguidolim merged commit 46ab1d5 into main Mar 23, 2026
4 checks passed
@bguidolim bguidolim deleted the bruno/241-shell-running-protocol branch March 23, 2026 01:06
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.

Extract ShellRunning protocol to enable test mocking of git operations

1 participant