-
Notifications
You must be signed in to change notification settings - Fork 1
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
[ECO-5904] Disable implicit attach #129
Conversation
None of this stuff is public in JS, from where it was copied.
We shouldn’t be mutating the channel options that are passed in to `getChannel(…)` (violates caller’s expectations), and ably-cocoa offers us no mechanism for copying an ARTRealtimeChannelOptions object.
WalkthroughThe changes introduce a new internal struct Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
🧹 Outside diff range and nitpick comments (5)
Sources/AblyChat/Version.swift (1)
7-7
: Consider using a version management systemWhile changing visibility to
internal
aligns with the PR objectives, consider:
- Using a version management tool or build system to inject version numbers
- Adding documentation about version update process
Tests/AblyChatTests/Mocks/MockChannels.swift (1)
Line range hint
47-55
: Usedefer
for safer mutex unlocking in releaseArguments getterFor consistency with other mutex handling improvements, consider using
defer
here as well.var releaseArguments: [String] { let result: [String] mutex.lock() + defer { mutex.unlock() } result = _releaseArguments - mutex.unlock() return result }Sources/AblyChat/Dependencies.swift (1)
24-45
: LGTM! Consider adding Equatable conformance.The introduction of
RealtimeChannelOptions
with value semantics is a good design choice. The implementation is clean and well-documented.Consider adding
Equatable
conformance to make the struct easier to test:-internal struct RealtimeChannelOptions { +internal struct RealtimeChannelOptions: Equatable { internal var modes: ARTChannelMode internal var params: [String: String]? internal var attachOnSubscribe: BoolTests/AblyChatTests/DefaultRoomTests.swift (2)
8-24
: LGTM! Test implements CHA-GP2a specification.The test effectively verifies that
attachOnSubscribe
is disabled when fetching channels. Good use of mocks and clear test structure.Consider adding the following test cases to make it more comprehensive:
- Test with an empty channel list
- Test with channels that have different attachment states
- Test error scenarios when fetching channels
6-7
: Consider adding section documentation.The "Fetching channels" section could benefit from a brief comment explaining its purpose and relationship to the CHA-GP2a specification.
// MARK: - Fetching channels +// Tests related to channel fetching behavior and configuration. +// CHA-GP2a: Ensures that implicit attach is disabled when fetching channels.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (5)
Sources/AblyChat/Dependencies.swift
(1 hunks)Sources/AblyChat/Room.swift
(1 hunks)Sources/AblyChat/Version.swift
(1 hunks)Tests/AblyChatTests/DefaultRoomTests.swift
(1 hunks)Tests/AblyChatTests/Mocks/MockChannels.swift
(1 hunks)
🔇 Additional comments (9)
Sources/AblyChat/Version.swift (3)
9-9
: LGTM!
The internal visibility and format are appropriate for the agent string.
Line range hint 3-3
: Verify the status of issue #76
The TODO comment indicates this is a temporary implementation copied from chat-js. Let's verify if this approach is still valid or needs updating.
11-11
: Verify the integration of defaultChannelParams
The change from defaultChannelOptions
to defaultChannelParams
looks good, but let's verify its usage across the codebase.
✅ Verification successful
Based on the search results, I can now generate the final response:
Integration of defaultChannelParams is correctly implemented
The defaultChannelParams
constant is properly integrated and used in the codebase:
- It's used in
Dependencies.swift
within thegetChannel
function to merge the default params with any channel-specific options - The implementation ensures the agent string is consistently applied to all channel initializations
- The old
defaultChannelOptions
has been completely removed with no remaining references
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check usage of defaultChannelParams and old defaultChannelOptions
echo "Checking usage of new defaultChannelParams:"
rg "defaultChannelParams" -A 2
echo "Checking for any remaining references to old defaultChannelOptions:"
rg "defaultChannelOptions"
Length of output: 585
Script:
#!/bin/bash
# Let's check the context around the usage in Dependencies.swift
echo "Checking context of defaultChannelParams usage in Dependencies.swift:"
rg "defaultChannelParams" Dependencies.swift -B 5 -A 5
# Let's also check for any channel-related code to understand the integration
echo -e "\nChecking for channel-related code:"
ast-grep --pattern 'func $_ ($_: ARTRealtimeChannel$$$) {
$$$
}'
Length of output: 416
Script:
#!/bin/bash
# Let's check the correct path for Dependencies.swift and its content
echo "Finding Dependencies.swift location:"
fd Dependencies.swift
echo -e "\nChecking context of defaultChannelParams usage:"
rg "defaultChannelParams" -B 5 -A 5
# Let's also look for any channel-related initialization or usage
echo -e "\nChecking for channel initialization patterns:"
rg "channel|Channel" -B 2 -A 2
Length of output: 175040
Tests/AblyChatTests/Mocks/MockChannels.swift (2)
8-9
: LGTM! Well-documented properties with appropriate access control.
The properties are correctly marked as private(set)
with clear documentation about synchronization requirements.
16-34
: Verify test coverage for implicit attach behavior
The mock now tracks channel options, which is crucial for verifying the PR's objective of disabling implicit attach.
✅ Verification successful
Mock implementation correctly supports testing of implicit attach behavior
The verification shows that:
- The mock is being used effectively in
DefaultRoomTests
to verify that channels are created withattachOnSubscribe
set to false - Test coverage exists specifically for this behavior, with assertions checking that all channel instances have the correct option set
- The implementation aligns with the PR's objective (CHA-GP2a) to disable implicit attach
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that tests are using this mock to check implicit attach behavior
# Look for test cases verifying attachOnSubscribe option
rg -l "attachOnSubscribe.*false" Tests/
Length of output: 84
Script:
#!/bin/bash
# Check the actual test implementation to verify how attachOnSubscribe is being tested
rg -A 10 "attachOnSubscribe.*false" Tests/AblyChatTests/DefaultRoomTests.swift
Length of output: 664
Script:
#!/bin/bash
# Look for any other related test cases that might be using the mock channels
rg -l "MockChannels" Tests/
Length of output: 204
Script:
#!/bin/bash
# Check if there are any other tests verifying channel options
rg "options.*ARTRealtimeChannelOptions" Tests/
Length of output: 660
Script:
#!/bin/bash
# Check the full test implementation in DefaultRoomTests to understand the test coverage
rg -B 5 -A 5 "channelsGetArguments" Tests/AblyChatTests/DefaultRoomTests.swift
Length of output: 775
Script:
#!/bin/bash
# Check if there are any other test files that verify attachOnSubscribe behavior
rg -l "attachOnSubscribe" Tests/
Length of output: 75
Sources/AblyChat/Dependencies.swift (2)
49-56
: LGTM! Clean implementation of parameter handling.
The parameter merging logic is well-implemented and the use of the new RealtimeChannelOptions
type improves type safety.
59-62
: Verify the impact of disabling implicit attach.
The implementation correctly addresses CHA-GP2a by setting attachOnSubscribe = false
. However, we should verify that this change doesn't break existing functionality.
Let's check for any direct dependencies on the attach behavior:
✅ Verification successful
Based on the test results, I can now generate the final response as we have sufficient information to verify the impact of disabling implicit attach.
Setting attachOnSubscribe = false
is safe and verified by tests
The codebase has comprehensive test coverage for the attach behavior:
DefaultRoomTests.disablesImplicitAttach()
explicitly verifies thatattachOnSubscribe
is set to false for all channels- The lifecycle management tests verify proper handling of manual attach operations
- Integration tests demonstrate the correct attach sequence with explicit attach calls
- No tests rely on implicit attach behavior
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for tests or code that might depend on implicit attach behavior
rg -l "attachOnSubscribe|attach\(\)" --type swift
# Look for potential issues in test files
rg "attach" --type swift -g "*Tests.swift" -C 3
Length of output: 105948
Sources/AblyChat/Room.swift (1)
Line range hint 141-163
: Fix inconsistent usage of channel options types and implement implicit attach disable
There are several issues in this code segment:
- The presence block creates a new
ARTRealtimeChannelOptions
instance that shadows the outerRealtimeChannelOptions
variable, causing the presence mode settings to be lost. - The implementation is missing the requirement to disable implicit attach as specified in the PR objective (ECO-5904).
Apply this diff to fix the issues:
var channelOptions = RealtimeChannelOptions()
+ channelOptions.attachOnSubscribe = false // Disable implicit attach as per ECO-5904
// channel setup for presence and occupancy
if feature == .presence {
- let channelOptions = ARTRealtimeChannelOptions()
let presenceOptions = roomOptions.presence
if presenceOptions?.enter ?? false {
channelOptions.modes.insert(.presence)
}
if presenceOptions?.subscribe ?? false {
channelOptions.modes.insert(.presenceSubscribe)
}
} else if feature == .occupancy {
channelOptions.params = ["occupancy": "metrics"]
}
Let's verify that we're not missing any other places where implicit attach needs to be disabled:
Tests/AblyChatTests/DefaultRoomTests.swift (1)
17-18
: Verify DefaultRoom implementation of CHA-GP2a.
While the test looks good, let's verify that the actual implementation in DefaultRoom correctly sets attachOnSubscribe = false
.
✅ Verification successful
Let me search for more specific information about where the channel options are set.
Implementation of CHA-GP2a (disable implicit attach) is correctly verified
The implementation is correctly setting attachOnSubscribe = false
in Dependencies.swift
with an explicit comment "CHA-GP2a". This setting is applied to all channel options through the getChannel
extension method, ensuring that implicit attach is disabled for all channels in the room.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Find DefaultRoom implementation and verify attachOnSubscribe setting
# Find DefaultRoom implementation
echo "Searching for DefaultRoom implementation..."
rg -l "class DefaultRoom" --type swift
# Look for channel creation with attachOnSubscribe
echo "Checking channel creation options..."
rg -A 5 "getChannel|channels\.get" --type swift
Length of output: 2147
Script:
#!/bin/bash
# Search for channelOptions initialization and DefaultRoom implementation
echo "Searching for channelOptions in DefaultRoom..."
rg -B 5 -A 10 "channelOptions" --type swift
# Look for RealtimeChannelOptions or related configuration
echo "Searching for RealtimeChannelOptions configuration..."
rg -B 2 -A 2 "RealtimeChannelOptions|attachOnSubscribe" --type swift
Length of output: 11197
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Implements spec point CHA-GP2a.
Resolves #102.
Summary by CodeRabbit
Release Notes
New Features
RealtimeChannelOptions
for enhanced channel configuration.Room
protocol to utilize the new channel options structure.Bug Fixes
Room
protocol.Tests
Chores
Version
module for better encapsulation.