Skip to content

Conversation

@matt-livefront
Copy link
Collaborator

@matt-livefront matt-livefront commented Dec 5, 2025

🎟️ Tracking

PM-28540

📔 Objective

Adds a BitwardenSharedMocks target containing the mocks and fixtures used within BitwardenShared.

This adds consistency with how we've used BitwardenKitMocks and AuthenticatorBridgeKitMocks and will make it easier to implement Xcodegen templates (#2153).

BitwardenSharedMocks contains a lot of fixtures and mocks for internal types within BitwardenShared. Rather than make these types public, I've used testable imports of the new BitwardenSharedMocks target in tests.

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

@matt-livefront matt-livefront requested a review from a team as a code owner December 5, 2025 19:06
@claude
Copy link

claude bot commented Dec 5, 2025

Claude finished @matt-livefront's task —— View job


Code Review Complete

Summary

This PR successfully creates a BitwardenSharedMocks framework target to separate mocks and fixtures from the main BitwardenShared target, following the established pattern with BitwardenKitMocks and AuthenticatorBridgeKitMocks. The implementation is clean and well-structured.

Architecture & Design ✅

Strengths:

  • Follows existing patterns (BitwardenKitMocks, AuthenticatorBridgeKitMocks)
  • Proper dependency injection via testable imports
  • Clean separation of concerns between production and test code
  • Consistent with project architecture guidelines

Key Changes:

  1. New BitwardenSharedMocks target includes **/Fixtures/* and **/Mocks/* files
  2. Test targets add @testable import BitwardenSharedMocks
  3. Bundle references updated from .bitwardenShared to .bitwardenSharedMocks
  4. Sourcery-generated mocks (AutoMockable.generated.swift) included in the mocks target
  5. All test targets now depend on BitwardenSharedMocks

Code Quality ✅

Positive Findings:

  • All 100 changed files follow consistent patterns
  • Testable imports used appropriately for internal types
  • No unnecessary code duplication
  • Bundle finder implementation is clean and follows Swift conventions

Fixture Organization:
The approach taken is correct - the PR consolidates fixtures into the mock target while PreviewContent fixtures (wrapped in #if DEBUG) remain in the main target for SwiftUI previews. The BitwardenSdk+VaultFixtures.swift file in PreviewContent/ is intentionally kept in BitwardenShared since it's used by both the main app (for previews) and tests.

Testing ✅

  • Test imports are consistent across all 94 test files
  • No test compilation issues expected
  • CI failure in Authenticator tests is unrelated (Ruby download timeout)
  • Password Manager tests are still running

Documentation ✅

Security ✅

  • No security implications
  • No changes to encryption, authentication, or data handling
  • Pure organizational refactoring

Potential Concerns

Minor:

  1. BitwardenSharedMocks includes PreviewContent: The main BitwardenShared target explicitly includes PreviewContent/ folders (lines 354-357 in project-pm.yml), while BitwardenSharedMocks uses glob patterns **/Fixtures/* which wouldn't match PreviewContent/. This is intentional and correct - PreviewContent fixtures stay in the main target for SwiftUI previews.

  2. Missing AuthenticatorBridgeKitMocks dependency: BitwardenSharedSnapshotTests was missing the AuthenticatorBridgeKitMocks dependency which this PR adds (line 471). Good catch!

  3. Test file organization: The approach of using testable imports (@testable import BitwardenSharedMocks) for accessing internal fixtures is the right pattern to avoid making internal types public.

Recommendations

Optional Improvements (not blockers):

  1. Consider adding a comment in project-pm.yml explaining why PreviewContent fixtures remain in BitwardenShared (for SwiftUI preview support)
  2. Could add a build phase validation to ensure mocks aren't accidentally imported in production code

Verdict: ✅ APPROVED

This is a well-executed refactoring that improves code organization and sets the foundation for Xcodegen templates. The changes are:

  • Architecturally sound
  • Consistently applied across all test files
  • Following established patterns
  • Low risk (pure organizational change)

The CI failure in Authenticator tests is unrelated (infrastructure issue with Ruby download timeout from GitHub's servers).


@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

Logo
Checkmarx One – Scan Summary & Details733b2c83-89fe-4a83-b8ec-9e1ab0e733a0

Great job! No new security vulnerabilities introduced in this pull request

@codecov
Copy link

codecov bot commented Dec 5, 2025

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 84.23%. Comparing base (c3d3862) to head (01d1d15).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ces/API/Fixtures/APITestData+BitwardenShared.swift 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2183      +/-   ##
==========================================
- Coverage   85.50%   84.23%   -1.27%     
==========================================
  Files        1740     1978     +238     
  Lines      147301   162364   +15063     
==========================================
+ Hits       125943   136767   +10824     
- Misses      21358    25597    +4239     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@fedemkr fedemkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just one small question.

Comment on lines -415 to -423
- path: BitwardenShared/Sourcery/Generated
optional: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I see that BitwardenShared/Sourcery/Generated/AutoMockable.generated.swift has been moved to the new BitwardenSharedMocks. However, this one BitwardenShared/Sourcery/Generated hasn't, is that intended?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if there's any reason we need to explicitly include BitwardenShared/Sourcery/Generated? I think if there were any files in it, they would be picked up by the existing BitwardenShared path. We only need to let Xcode know that the BitwardenShared/Sourcery/Generated/AutoMockable.generated.swift file is optional, since it might not exist when the Xcode project is built by Xcodgen.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the AutoMockable.generated.swift file doesn't exist, you run Xcodegen then I assume the Generated path is not created on the Xcode project. In that situation does Sourcery works as expected when building the target? Does it create the files under the Xcode project tree? or do you need to regenerate the project with Xcodegen?
That's the only caveat I can remember that may have happened and could need that line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the AutoMockable.generated.swift file doesn't exist, you run Xcodegen then I assume the Generated path is not created on the Xcode project.

Since the AutoMockable.generated.swift file is marked as optional, Xcode will include the full path to the file in the Xcode project. I double checked by removing the generated file, running bootstrap, and performing a build and noticed no issues.

The file shows up in Xcode even if it doesn't yet exist after bootstrapping (and without explicitly including the Generated directory):
Screenshot 2025-12-10 at 11 39 25 AM

fedemkr
fedemkr previously approved these changes Dec 11, 2025
@matt-livefront matt-livefront merged commit 49c082f into main Dec 11, 2025
19 of 20 checks passed
@matt-livefront matt-livefront deleted the matt/PM-28540-bitwarden-shared-mocks branch December 11, 2025 21:12
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.

3 participants