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

Add NSCopying support to ART*ChannelOptions #2018

Merged
merged 1 commit into from
Jan 29, 2025

Conversation

lawrence-forooghian
Copy link
Collaborator

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

Will use in an upcoming commit, but it's also handy for users of the SDK (e.g. I had already found myself wanting it in Chat, when wishing to create a modified version of an options object received as an argument).

Summary by CodeRabbit

  • New Features

    • Added support for copying channel options with copyWithZone: method
    • Implemented NSCopying protocol for ARTChannelOptions
  • Tests

    • Added comprehensive test suite for channel options copying functionality
    • Verified copying behavior for both standard and frozen channel options
  • Improvements

    • Enhanced object management for channel and realtime channel options

Will use in an upcoming commit, but it's also handy for users of the SDK
(e.g. I had already found myself wanting it in Chat, when wishing to
create a modified version of an options object recevied as an argument).
Copy link

coderabbitai bot commented Jan 28, 2025

Walkthrough

The pull request introduces new functionality for handling connection and attachment retry states in the Ably library. It adds ARTConnectRetryState and ARTAttachRetryState classes to manage retry attempts. Additionally, the changes implement the NSCopying protocol for ARTChannelOptions and ARTRealtimeChannelOptions, enabling object copying. New test cases are added to verify the copying behavior, ensuring that copied objects maintain the correct state and properties while remaining independent of the original objects.

Changes

File Change Summary
Ably.xcodeproj/project.pbxproj Added new classes for connection and attachment retry states
Source/ARTChannelOptions.m Implemented copyWithZone: method for creating copies of ARTChannelOptions
Source/ARTRealtimeChannelOptions.m Added copyWithZone: method for ARTRealtimeChannelOptions
Source/include/Ably/ARTChannelOptions.h Added NSCopying protocol to ARTChannelOptions interface
Test/Tests/ChannelOptionsTests.swift Created new test suite for verifying channel options copying behavior

Sequence Diagram

sequenceDiagram
    participant Original as Original ChannelOptions
    participant Copy as Copied ChannelOptions
    
    Original->>Copy: copyWithZone:
    Note over Original,Copy: Create independent copy
    
    Original->>Copy: Copy properties
    Note over Copy: Ensure unfrozen state
    
    Copy-->>Original: Return new instance
Loading

Possibly related PRs

Suggested reviewers

  • umair-ably
  • maratal

Poem

🐰 A Rabbit's Ode to Copying Might

With retry states and options bright,
We clone our objects, pure and light,
No frozen state shall hold us back,
Our code now dances on its track!
Hop, copy, retry - code takes flight! 🚀


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.

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

🧹 Nitpick comments (1)
Test/Tests/ChannelOptionsTests.swift (1)

30-47: Consider adding test for params dictionary mutation behavior.

While the current test coverage is good, consider adding a test that verifies the behavior when the original params dictionary is modified after copying. This would help document the expected behavior and catch any issues with shallow vs deep copying.

func test_copyRealtimeChannelOptions_paramsModification() throws {
    let options = ARTRealtimeChannelOptions()
    options.params = ["foo": "bar"]
    
    let copied = try XCTUnwrap(options.copy() as? ARTRealtimeChannelOptions)
    
    // Modify original params
    options.params = ["foo": "baz"]
    
    // Verify copied params remain unchanged
    XCTAssertEqual(copied.params as? [String: String], ["foo": "bar"])
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 35805d0 and a3b3217.

📒 Files selected for processing (5)
  • Ably.xcodeproj/project.pbxproj (6 hunks)
  • Source/ARTChannelOptions.m (1 hunks)
  • Source/ARTRealtimeChannelOptions.m (1 hunks)
  • Source/include/Ably/ARTChannelOptions.h (1 hunks)
  • Test/Tests/ChannelOptionsTests.swift (1 hunks)
🧰 Additional context used
📓 Learnings (1)
Source/include/Ably/ARTChannelOptions.h (1)
Learnt from: maratal
PR: ably/ably-cocoa#1973
File: Source/include/Ably/ARTRealtimeChannelOptions.h:33-33
Timestamp: 2024-11-12T07:31:53.691Z
Learning: `ARTChannelOptions` is already marked with `NS_SWIFT_SENDABLE`.
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: check (macOS, test_macOS)
  • GitHub Check: check (tvOS, test_tvOS17_2)
  • GitHub Check: check
  • GitHub Check: check
  • GitHub Check: check (iOS, test_iOS17_2)
  • GitHub Check: build
🔇 Additional comments (7)
Source/include/Ably/ARTChannelOptions.h (1)

11-11: LGTM! Clean addition of NSCopying protocol.

The addition of NSCopying protocol is appropriate and aligns with the PR objective.

Source/ARTChannelOptions.m (1)

20-29: LGTM! Well-implemented NSCopying support.

The implementation correctly:

  • Creates a new instance using alloc/init
  • Copies the cipher property
  • Explicitly resets the frozen state
  • Includes a clear comment explaining the frozen state behavior
Source/ARTRealtimeChannelOptions.m (2)

24-32: LGTM! Well-implemented NSCopying support with proper super call.

The implementation correctly:

  • Calls super's copyWithZone:
  • Copies all instance variables
  • Uses consistent direct ivar access

27-27: Consider implications of shallow copying params dictionary.

The params dictionary is copied by reference. If it's mutable, changes to the original's params will affect the copy's params. Consider if deep copying is needed for complete isolation.

Let's verify the mutability of params dictionary:

Test/Tests/ChannelOptionsTests.swift (1)

7-18: LGTM! Well-structured test for ARTChannelOptions copying.

Test thoroughly verifies:

  • Successful copying
  • Object identity
  • Property copying
Ably.xcodeproj/project.pbxproj (2)

100-102: Project configuration changes look good!

The Xcode project has been properly configured with the new test file ChannelOptionsTests.swift and its supporting files. The build settings are correctly set up across all necessary targets.

Also applies to: 1159-1159, 1738-1738, 3054-3054, 3253-3253, 3312-3312


100-102: Verify test coverage for NSCopying implementation.

Let's ensure the new test file covers all necessary scenarios for NSCopying implementation:

  1. Basic copying behavior
  2. Deep vs shallow copy behavior
  3. Immutability preservation
  4. Property retention accuracy
✅ Verification successful

NSCopying implementation is well-tested

The test coverage is comprehensive, including object identity verification, property retention, frozen state handling, and both ARTChannelOptions and ARTRealtimeChannelOptions classes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check test coverage for NSCopying implementation

# Look for NSCopying protocol conformance
echo "Checking NSCopying protocol conformance..."
rg -A 5 "NSCopying" Test/

# Look for copy tests
echo "Checking copy-related test cases..."
rg -A 10 "func test.*[Cc]opy" "Test/Tests/ChannelOptionsTests.swift"

Length of output: 2310

@lawrence-forooghian lawrence-forooghian merged commit fee79bc into main Jan 29, 2025
7 of 8 checks passed
@lawrence-forooghian lawrence-forooghian deleted the add-NSCopying-to-channel-options branch January 29, 2025 11:57
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