Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unpin ably-cocoa #215

Merged
merged 3 commits into from
Jan 20, 2025
Merged

Unpin ably-cocoa #215

merged 3 commits into from
Jan 20, 2025

Conversation

lawrence-forooghian
Copy link
Collaborator

@lawrence-forooghian lawrence-forooghian commented Jan 16, 2025

This reverts b261155. See commit messages for more details.

Summary by CodeRabbit

Release Notes

  • Dependencies

    • Updated ably-cocoa package from version 1.2.36 to 1.2.37
  • Type System

    • Introduced more flexible type handling for channel-related protocols using existential types
    • Added new RealtimePresenceProtocol to enhance presence management capabilities
  • Mocking

    • Enhanced mock implementations for testing real-time channel and presence features
    • Added MockRealtimePresence class to simulate presence management in tests

These changes improve the library's type flexibility and testing infrastructure while updating a core dependency.

We won't be able to do this; see message of ably-cocoa commit e216ae5.
The approach currently taken by the Chat SDK (adding these properties
and methods onto its own Swift protocol that uses associated types) is
the one that we should continue.
Copy link

coderabbitai bot commented Jan 16, 2025

Walkthrough

This pull request introduces several significant changes to the AblyChat project, primarily focusing on dependency updates and type system modifications. The main updates include upgrading the ably-cocoa package from version 1.2.36 to 1.2.37, and changing multiple protocol and property declarations to use existential types (using any RealtimeChannelProtocol). Additionally, a new RealtimePresenceProtocol has been introduced, and mock implementations for presence-related functionality have been added to support testing and development.

Changes

File Change Summary
AblyChat.xcworkspace/xcshareddata/swiftpm/Package.resolved, Package.resolved, Package.swift Updated ably-cocoa dependency from 1.2.36 to 1.2.37 and modified versioning strategy to allow future updates.
Sources/AblyChat/Dependencies.swift Added RealtimePresenceProtocol and updated RealtimeChannelProtocol with presence-related associated type.
Example/AblyChatExample/Mocks/MockClients.swift, Example/AblyChatExample/Mocks/MockRealtime.swift, Tests/AblyChatTests/Mocks/MockFeatureChannel.swift, Tests/AblyChatTests/Mocks/MockRealtimeChannel.swift, Tests/AblyChatTests/Mocks/MockRealtimePresence.swift, Sources/AblyChat/Messages.swift, Sources/AblyChat/Occupancy.swift, Sources/AblyChat/Room.swift, Sources/AblyChat/RoomFeature.swift, Sources/AblyChat/RoomReactions.swift, Sources/AblyChat/Typing.swift Changed channel property type from RealtimeChannelProtocol to any RealtimeChannelProtocol in multiple classes and protocols.
MockRealtime.swift, MockRealtimePresence.swift Added mock implementations for presence-related functionality.

Suggested reviewers

  • umair-ably
  • maratal

Possibly related PRs

Poem

🐰 Hop, hop, through code so bright,
Existential types take flight!
Presence mocked with playful glee,
Ably's dance of version spree
Coding rabbits rejoice tonight! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot temporarily deployed to staging/pull/215/AblyChat January 16, 2025 18:40 Inactive
@lawrence-forooghian lawrence-forooghian marked this pull request as ready for review January 20, 2025 12:59
@github-actions github-actions bot temporarily deployed to staging/pull/215/AblyChat January 20, 2025 13:00 Inactive
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
Tests/AblyChatTests/Mocks/MockRealtimePresence.swift (1)

4-98: Add documentation for the mock class.

Consider adding documentation that explains:

  • The purpose of this mock class
  • When and how it should be used in tests
  • Why methods are intentionally unimplemented

Add documentation like this:

+/// A mock implementation of `RealtimePresenceProtocol` for testing purposes.
+/// All methods intentionally throw `fatalError` to ensure tests properly mock
+/// only the methods they need.
 final class MockRealtimePresence: RealtimePresenceProtocol {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fb70b2e and effd502.

📒 Files selected for processing (16)
  • AblyChat.xcworkspace/xcshareddata/swiftpm/Package.resolved (1 hunks)
  • Example/AblyChatExample/Mocks/MockClients.swift (4 hunks)
  • Example/AblyChatExample/Mocks/MockRealtime.swift (2 hunks)
  • Package.resolved (1 hunks)
  • Package.swift (1 hunks)
  • Sources/AblyChat/AblyCocoaExtensions/Ably+Dependencies.swift (1 hunks)
  • Sources/AblyChat/Dependencies.swift (1 hunks)
  • Sources/AblyChat/Messages.swift (1 hunks)
  • Sources/AblyChat/Occupancy.swift (1 hunks)
  • Sources/AblyChat/Room.swift (1 hunks)
  • Sources/AblyChat/RoomFeature.swift (2 hunks)
  • Sources/AblyChat/RoomReactions.swift (1 hunks)
  • Sources/AblyChat/Typing.swift (1 hunks)
  • Tests/AblyChatTests/Mocks/MockFeatureChannel.swift (1 hunks)
  • Tests/AblyChatTests/Mocks/MockRealtimeChannel.swift (1 hunks)
  • Tests/AblyChatTests/Mocks/MockRealtimePresence.swift (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Package.resolved
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: Example app, tvOS (Xcode 16)
  • GitHub Check: Example app, iOS (Xcode 16)
  • GitHub Check: Xcode, release configuration, tvOS (Xcode 16)
  • GitHub Check: Xcode, tvOS (Xcode 16)
  • GitHub Check: Example app, macOS (Xcode 16)
  • GitHub Check: Xcode, release configuration, iOS (Xcode 16)
  • GitHub Check: Xcode, iOS (Xcode 16)
  • GitHub Check: Xcode, release configuration, macOS (Xcode 16)
  • GitHub Check: SPM (Xcode 16)
  • GitHub Check: Xcode, macOS (Xcode 16)
  • GitHub Check: SPM, release configuration (Xcode 16)
🔇 Additional comments (15)
Package.swift (1)

23-23: Verify the impact of unpinning ably-cocoa dependency.

While unpinning the dependency allows for easier updates, we should verify:

  1. Breaking changes between 1.2.36 and 1.2.37
  2. Known issues with newer versions
✅ Verification successful

✅ Safe to unpin ably-cocoa dependency to 1.2.37+

Version 1.2.37 actually reverts a breaking change by moving presence back to ARTRealtime, making it more stable. Recent version history shows careful maintenance with no concerning changes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for breaking changes and issues in ably-cocoa

# Get the changelog between versions
gh api repos/ably/ably-cocoa/releases | jq -r '.[] | select(.tag_name | contains("1.2.3")) | .body'

# Check for open issues affecting version range
gh api repos/ably/ably-cocoa/issues --jq '.[] | select(.labels[].name | contains("bug")) | {title: .title, url: .html_url, labels: [.labels[].name]}'

Length of output: 5340

Sources/AblyChat/AblyCocoaExtensions/Ably+Dependencies.swift (1)

9-10: LGTM! Protocol conformance follows established patterns.

The extension follows the same pattern as other protocol conformances in this file, maintaining consistency.

Tests/AblyChatTests/Mocks/MockFeatureChannel.swift (1)

5-5: Type system changes align with Swift's direction.

The shift to existential types (any RealtimeChannelProtocol) is consistent with Swift's evolution. However, be aware that this might affect:

  1. Type inference in dependent code
  2. Compile-time protocol conformance checks

Also applies to: 10-10

✅ Verification successful

Change to use existential types is consistent with codebase patterns.

The modification to use any RealtimeChannelProtocol in MockFeatureChannel.swift aligns with the existing usage pattern throughout the codebase, where protocol conformance is consistently handled using existential types.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other usages that might need similar updates

# Find other RealtimeChannelProtocol usages that might need updating
rg "RealtimeChannelProtocol" --type swift -l | xargs rg ":" -A 1 --type swift

Length of output: 106046

Sources/AblyChat/Occupancy.swift (1)

37-37: LGTM! Consistent with project-wide type system changes.

The update to use any RealtimeChannelProtocol maintains consistency with similar changes across the codebase.

AblyChat.xcworkspace/xcshareddata/swiftpm/Package.resolved (1)

9-10: Verify ably-cocoa version 1.2.37 for compatibility and security.

The dependency upgrade from 1.2.36 to 1.2.37 appears to be a minor patch version increment.

Let's verify the version and check for any security advisories:

✅ Verification successful

Version 1.2.37 verified successfully

The version exists in the official repository and no security vulnerabilities were found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the version exists in the repository
gh api \
  -H "Accept: application/vnd.github+json" \
  repos/ably/ably-cocoa/git/refs/tags/v1.2.37

# Check for security advisories
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: COCOAPODS, package: "Ably") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
      firstPatchedVersion {
        identifier
      }
    }
  }
}'

Length of output: 1030


Script:

#!/bin/bash
# List recent tags
gh api \
  -H "Accept: application/vnd.github+json" \
  repos/ably/ably-cocoa/tags?per_page=5

# Check security advisories with correct ecosystem value
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: SWIFT, package: "Ably") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
      firstPatchedVersion {
        identifier
      }
    }
  }
}'

Length of output: 2540

Sources/AblyChat/Typing.swift (1)

57-57: LGTM! Good use of existential type.

The change to any RealtimeChannelProtocol aligns with modern Swift best practices for protocol conformance.

Sources/AblyChat/Dependencies.swift (2)

22-26: LGTM! Well-structured protocol hierarchy.

The addition of the presence-related associated type and property to RealtimeChannelProtocol follows good protocol-oriented design principles.


28-29: LGTM! Good protocol design.

The new RealtimePresenceProtocol properly extends ARTRealtimePresenceProtocol with Sendable conformance for thread safety.

Sources/AblyChat/RoomReactions.swift (1)

25-25: LGTM! Good use of explicit existential types.

The change to any RealtimeChannelProtocol aligns with modern Swift best practices for protocol usage. This makes the existential type usage explicit and clearer.

Sources/AblyChat/RoomFeature.swift (1)

49-49: LGTM! Consistent type system updates.

The changes to use any RealtimeChannelProtocol in both the protocol and implementation are consistent with the codebase-wide update to explicit existential types.

Also applies to: 65-65

Tests/AblyChatTests/Mocks/MockRealtimeChannel.swift (1)

5-5: LGTM! Enhanced test coverage with mock presence implementation.

Replacing the unimplemented presence feature with a concrete MockRealtimePresence implementation improves the testing capabilities of the codebase.

Sources/AblyChat/Messages.swift (1)

54-54: LGTM! Consistent type system update.

The change to use any RealtimeChannelProtocol maintains consistency with the codebase-wide update to explicit existential types.

Example/AblyChatExample/Mocks/MockRealtime.swift (1)

108-108: LGTM! Improved mock implementation.

The change replaces a fatalError implementation with a proper mock instance, which is a better approach for testing.

Example/AblyChatExample/Mocks/MockClients.swift (1)

91-91: LGTM! Improved type safety with explicit existential types.

The changes from RealtimeChannelProtocol to any RealtimeChannelProtocol align with Swift's best practices for explicit protocol type usage.

Also applies to: 149-149, 196-196, 359-359

Sources/AblyChat/Room.swift (1)

303-303: LGTM! Consistent use of explicit existential types.

The change from RealtimeChannelProtocol to any RealtimeChannelProtocol maintains consistency with similar changes across the codebase.

Tests/AblyChatTests/Mocks/MockRealtimePresence.swift Outdated Show resolved Hide resolved
This reverts b261155.

Handle ably-cocoa's new commit e216ae5, which reverted the backwards
compatibility-breaking commit 26d9bf7. To handle e216ae5, we need to add
the realtime client's `presence` member to our requirements.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
Example/AblyChatExample/Mocks/MockRealtime.swift (1)

251-345: 🛠️ Refactor suggestion

Enhance mock implementations in RealtimePresence

The RealtimePresence class methods currently raise fatalError("Not implemented"), except for the history(_:) method, which has an empty implementation. This inconsistency could lead to unexpected behavior during testing. Consider providing basic mock implementations for these methods to support more effective testing scenarios.

🧹 Nitpick comments (1)
Tests/AblyChatTests/Mocks/MockRealtimeChannel.swift (1)

Line range hint 1-4: Consider adding documentation for mock usage patterns.

While the implementation is solid, consider adding:

  1. Class-level documentation explaining which methods are implemented vs unimplemented
  2. Usage examples in comments
  3. Explanation of thread-safety decisions
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between effd502 and a339784.

📒 Files selected for processing (16)
  • AblyChat.xcworkspace/xcshareddata/swiftpm/Package.resolved (1 hunks)
  • Example/AblyChatExample/Mocks/MockClients.swift (4 hunks)
  • Example/AblyChatExample/Mocks/MockRealtime.swift (2 hunks)
  • Package.resolved (1 hunks)
  • Package.swift (1 hunks)
  • Sources/AblyChat/AblyCocoaExtensions/Ably+Dependencies.swift (1 hunks)
  • Sources/AblyChat/Dependencies.swift (1 hunks)
  • Sources/AblyChat/Messages.swift (1 hunks)
  • Sources/AblyChat/Occupancy.swift (1 hunks)
  • Sources/AblyChat/Room.swift (1 hunks)
  • Sources/AblyChat/RoomFeature.swift (2 hunks)
  • Sources/AblyChat/RoomReactions.swift (1 hunks)
  • Sources/AblyChat/Typing.swift (1 hunks)
  • Tests/AblyChatTests/Mocks/MockFeatureChannel.swift (1 hunks)
  • Tests/AblyChatTests/Mocks/MockRealtimeChannel.swift (1 hunks)
  • Tests/AblyChatTests/Mocks/MockRealtimePresence.swift (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (14)
  • Sources/AblyChat/AblyCocoaExtensions/Ably+Dependencies.swift
  • Sources/AblyChat/Occupancy.swift
  • Sources/AblyChat/Messages.swift
  • Package.swift
  • Sources/AblyChat/RoomReactions.swift
  • Sources/AblyChat/Typing.swift
  • Sources/AblyChat/Room.swift
  • Sources/AblyChat/RoomFeature.swift
  • Sources/AblyChat/Dependencies.swift
  • Tests/AblyChatTests/Mocks/MockFeatureChannel.swift
  • AblyChat.xcworkspace/xcshareddata/swiftpm/Package.resolved
  • Example/AblyChatExample/Mocks/MockClients.swift
  • Package.resolved
  • Tests/AblyChatTests/Mocks/MockRealtimePresence.swift
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: Example app, tvOS (Xcode 16)
  • GitHub Check: Xcode, release configuration, tvOS (Xcode 16)
  • GitHub Check: Example app, iOS (Xcode 16)
  • GitHub Check: Xcode, release configuration, iOS (Xcode 16)
  • GitHub Check: Example app, macOS (Xcode 16)
  • GitHub Check: Xcode, release configuration, macOS (Xcode 16)
  • GitHub Check: Xcode, tvOS (Xcode 16)
  • GitHub Check: SPM, release configuration (Xcode 16)
  • GitHub Check: Xcode, iOS (Xcode 16)
  • GitHub Check: SPM (Xcode 16)
  • GitHub Check: Xcode, macOS (Xcode 16)
  • GitHub Check: check-documentation
🔇 Additional comments (6)
Example/AblyChatExample/Mocks/MockRealtime.swift (1)

108-108: Presence property correctly initialized

The presence property in the Channel class is now initialized with an instance of RealtimePresence(), which aligns with the protocol requirements and enhances functionality.

Tests/AblyChatTests/Mocks/MockRealtimeChannel.swift (5)

Line range hint 14-16: Review thread-safety implications of nonisolated(unsafe).

While the comment suggests that nonisolated(unsafe) is acceptable for tests, consider using a thread-safe approach (like the Counter class implementation) to prevent potential race conditions in concurrent test scenarios.


Line range hint 91-104: LGTM! Improved error handling in attach method.

The guard statement provides better error messaging and maintains the mock's contract by ensuring attachResult is set before use.


Line range hint 111-121: LGTM! Consistent error handling pattern in detach method.

The implementation follows the same pattern as attach, maintaining consistency in the mock's behavior.


Line range hint 209-213: LGTM! Clear implementation for tracking published messages.

The method effectively captures message details for verification in tests.


Line range hint 19-26: Address TODO comment about @unchecked Sendable.

The TODO comment indicates that the @unchecked Sendable usage needs review. Consider prioritizing the type tightening work referenced in issue #195 to ensure proper concurrency safety.

Run this script to check the status of the referenced issue:

✅ Verification successful

The @unchecked Sendable TODO is correctly tracked in issue #195 and represents a known technical debt item

This is part of a broader pattern of manual concurrency handling in the codebase, with similar @unchecked Sendable usage found in other mock objects and even some production code. The issue remains open and acknowledges the need for type tightening work.

  • The TODO comment in MockRealtimeChannel.swift explicitly links to issue Improve testing for messages functionality #195
  • Similar patterns are found in other mock objects using manual synchronization
  • There's a related discussion about concurrency concerns in DefaultConnection.swift
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if issue #195 is still open
gh issue view 195 --json state,title,body

Length of output: 903


Script:

#!/bin/bash
# Search for @unchecked Sendable usage and TODO comments
echo "=== Searching for @unchecked Sendable usage ==="
rg "@unchecked\s+Sendable" -A 2

echo -e "\n=== Searching for TODO comments about Sendable or concurrency ==="
rg -i "todo.*sendable|todo.*concurrency" -A 2

Length of output: 5962

@lawrence-forooghian lawrence-forooghian merged commit 330ab40 into main Jan 20, 2025
17 checks passed
@lawrence-forooghian lawrence-forooghian deleted the unpin-ably-cocoa branch January 20, 2025 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants