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: BitwardenSharedMocks Target

Overall Assessment: ✅ APPROVE

This PR successfully implements the BitwardenSharedMocks target following established patterns in the codebase. The changes are well-structured, maintain consistency with existing mock targets, and properly separate test-only code from production code.


👍 Strengths

  1. Pattern Consistency: Mirrors the existing BitwardenKitMocks and AuthenticatorBridgeKitMocks structure perfectly
  2. Clean Separation: Test-only code is properly isolated in a dedicated framework
  3. Proper Dependencies: All test targets correctly depend on the new mocks framework
  4. Fixture Deduplication: Removes redundant CipherListView, Fido2CredentialListView, and LoginListView fixtures that duplicated PreviewContent fixtures
  5. Bundle Organization: JSON fixtures correctly loaded from .bitwardenSharedMocks bundle via renamed bundle finder

✅ Architecture Compliance

The new BitwardenSharedMocks target follows established patterns:

  • Framework type with ENABLE_TESTING_SEARCH_PATHS: YES
  • Includes **/Fixtures/* and **/Mocks/* patterns
  • Depends on BitwardenShared and BitwardenShared/TestHelpers
  • Uses GENERATE_INFOPLIST_FILE: YES (consistent with BitwardenKitMocks)

Reference: project-pm.yml:394-410


✅ Code Organization

The target structure is clean and follows conventions:

  • Fixtures and mocks properly separated into their own framework
  • Source includes correct: **/Fixtures/* and **/Mocks/*
  • Includes Sourcery-generated mocks: BitwardenShared/Sourcery/Generated/AutoMockable.generated.swift
  • All public extensions properly marked with // swiftlint:disable missing_docs

Reference: project-pm.yml:401-407


✅ Import Strategy

The testable import approach is appropriate:

  • Test files add @testable import BitwardenSharedMocks alongside @testable import BitwardenShared
  • This avoids making internal types public just for testing
  • TestHelper files that need mock types also import BitwardenSharedMocks

Example: BitwardenShared/Core/Auth/Services/API/Auth/Fixtures/APITestData+Auth.swift:3-8


✅ Bundle Finder Pattern

The bundle finder was properly migrated:

  • Deleted: BitwardenSharedBundleFinder.swift
  • Added: BitwardenSharedMocksBundleFinder.swift
  • Updated all APITestData extensions to use .bitwardenSharedMocks bundle
  • Ensures JSON test fixtures load from the correct bundle

Reference: BitwardenShared/Core/Platform/Services/API/Fixtures/BitwardenSharedMocksBundleFinder.swift:1-10


✅ Testing Impact

All test targets properly configured:

  • BitwardenSharedTests, BitwardenSharedSnapshotTests, BitwardenSharedViewInspectorTests depend on BitwardenSharedMocks
  • The second commit (94f41965c) correctly adds missing dependencies:
    • BitwardenKit/TestHelpers for BitwardenSharedMocks
    • BitwardenKit/AuthenticatorBridgeKitMocks for snapshot and view inspector test targets
  • Test targets no longer directly include **/Fixtures/* in sources (now via dependency)

Reference: project-pm.yml:434 and project-pm.yml:461-462


ℹ️ Fixture File Deletions

Three fixture files were removed from BitwardenShared/Core/Vault/Models/Domain/Fixtures/:

  • CipherListView+Fixtures.swift (104 lines)
  • Fido2CredentialListView+Fixtures.swift (21 lines)
  • LoginListView+Fixtures.swift (21 lines)

These duplicate fixtures already defined in BitwardenShared/UI/Vault/PreviewContent/BitwardenSdk+VaultFixtures.swift. The PreviewContent fixtures are wrapped in #if DEBUG, which is appropriate since:

  • Tests run in Debug configuration by default
  • Fixtures accessible via @testable import BitwardenShared
  • Prevents fixture bloat in Release builds

Reference: BitwardenShared/UI/Vault/PreviewContent/BitwardenSdk+VaultFixtures.swift:7-140


✅ Build Configuration

The project-pm.yml configuration is correct:

  • Proper dependency chain: Tests → BitwardenSharedMocks → BitwardenShared
  • Test targets cleaned up (no longer include fixtures/mocks directly)
  • Sourcery-generated mocks included in BitwardenSharedMocks (not test targets)

Reference: project-pm.yml:424-440


✅ Security Considerations

No security implications identified:

  • No changes to encryption, authentication, or sensitive data handling
  • Fixture data is test-only and contains no real credentials
  • TestHelpers dependency appropriate for test-only framework

📋 Summary

This PR is ready to merge. It successfully adds the BitwardenSharedMocks target with clean separation of concerns, proper dependency management, and consistency with established patterns. The implementation will make Xcodegen templates easier to implement (as noted in PR #2153) and maintains architectural best practices.

The approach of using testable imports instead of making internal types public is the right choice - it maintains proper encapsulation while enabling comprehensive testing.


@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

Logo
Checkmarx One – Scan Summary & Detailsf182cf62-cc1c-4db2-8e36-f2e796e4e287

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.15%. Comparing base (e9c25c9) to head (94f4196).
⚠️ Report is 2 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.42%   84.15%   -1.27%     
==========================================
  Files        1734     1982     +248     
  Lines      146203   161527   +15324     
==========================================
+ Hits       124895   135935   +11040     
- Misses      21308    25592    +4284     

☔ 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 -416
- 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.

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