[PM-35680] chore: Allow Sourcery to generate BitwardenSdk mocks#2581
Conversation
…gedTokens to AutoMockable
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2581 +/- ##
==========================================
- Coverage 87.17% 86.08% -1.09%
==========================================
Files 1886 2114 +228
Lines 166723 181654 +14931
==========================================
+ Hits 145335 156380 +11045
- Misses 21388 25274 +3886 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| associatedtype Action: Sendable | ||
| associatedtype Effect: Sendable | ||
| associatedtype State: Sendable | ||
| associatedtype Action | ||
| associatedtype Effect | ||
| associatedtype State |
There was a problem hiding this comment.
🤔 Is it safe to remove Sendable here?
There was a problem hiding this comment.
These types are ultimately constrained by Store (typealias HandlerStore = Store<State, Action, Effect>) which requires that they are Sendable, so I don't think there's any downside:
|
This looks awesome Matt, kudos on making this work with BitwardenSdk mocks! |
Bitwarden Claude Code ReviewOverall Assessment: APPROVE This is a tooling/test-infrastructure PR that introduces a Code Review Details
|
| ```bash | ||
| # Mock generation | ||
| mint run sourcery --config BitwardenShared/Sourcery/sourcery.yml | ||
| mint run sourcery --config AuthenticatorShared/Sourcery/sourcery.yml | ||
| mint run sourcery --config BitwardenKit/Sourcery/sourcery.yml | ||
| # Mock generation — run from an Xcode build phase (BUILD_DIR is set automatically by Xcode) | ||
| # To run standalone, supply BUILD_DIR manually — see the script header for the one-liner | ||
| ./Scripts/generate-mocks.sh BitwardenShared # default if argument omitted | ||
| ./Scripts/generate-mocks.sh AuthenticatorShared | ||
| ./Scripts/generate-mocks.sh BitwardenKit |
There was a problem hiding this comment.
♻️ DEBT: Sibling Sourcery docs still reference the old mint run sourcery --config ... command, which will no longer work standalone after this PR.
Details
After this PR, BitwardenShared/Sourcery/sourcery.yml and AuthenticatorShared/Sourcery/sourcery.yml reference ${BITWARDEN_SDK_PATH}, which is only set by Scripts/generate-mocks.sh. Two skill docs still tell users to invoke Sourcery directly and would now produce broken or empty SDK source resolution:
.claude/skills/testing-ios-code/references/mock-generation.mdlines 23, 26 (BitwardenShared, AuthenticatorShared configs).claude/skills/testing-ios-code/SKILL.mdline 141
Consider updating these to point at ./Scripts/generate-mocks.sh <framework> for consistency with the build-test-verify SKILL.md change in this PR.
The BitwardenKit and AuthenticatorBridgeKit references in those docs continue to work since their configs don't reference ${BITWARDEN_SDK_PATH}.
There was a problem hiding this comment.
Yes, I will follow-up with a fix for this.
|
Great job! No new security vulnerabilities introduced in this pull request |

🎟️ Tracking
PM-35680
📔 Objective
Sourcery cannot annotate types defined in external modules, so mocks for BitwardenSdk types had to be written and maintained by hand. This PR eliminates those manual mocks by:
BitwardenSdkMocksframework that declares empty extensions of SDK types annotated with// sourcery:file: AutoMockable, allowing Sourcery to generate the mocks automatically. This allows the mocks to be shared by Bitwarden and Authenticator.Scripts/generate-mocks.sh, which derivesBITWARDEN_SDK_PATHfrom Xcode'sBUILD_DIRso Sourcery can resolve SDK source files when generating mocks. Sourcery needs access to the SPM checkout atBITWARDEN_SDK_PATHto be able to inspect the SDK source.AccountTokenProvider,AccountTokenProviderDelegate, andClientManagedTokenstoAutoMockableand deleting their manual mock implementations.BitwardenSharedandAuthenticatorSharedsourcery configs to include the SDK and Networking source paths so Sourcery can fully resolve inherited protocol APIs.To mock a type from the SDK:
BitwardenSdkMocks/Sourcery/Generated/AutoMockable.generated.swift.BitwardenSdkMocksis imported in the test target.Note
I ran into a Sourcery issue when generating the mocks initially, where
MockAccountTokenProviderincluded unrelated types from theStatestruct. I was able to workaround this by removing the Sendable constraints on the associated types inSearchHandler. e270595More details here: krzysztofzablocki/Sourcery#1458