pubsub: add device and server packages - #709
Conversation
Introduce per-side pubsub packages, so applications declare whether they are running on an end-user device or a server by their choice of package, shippable in a minor release: - pubsub/device: NewClient, returning a Client (= ably.Realtime) - pubsub/server: NewHTTPClient and NewRealtimeClient, returning an HTTPClient (= ably.REST) and a RealtimeClient (= ably.Realtime) The constructors return type aliases of today's clients rather than wrapper types: the side is the package and constructor choice plus the agent declaration, not a type distinction. Each constructor appends a side-declaring agent (ably-go-pubsub-device / ably-go-pubsub-server) to the Ably-Agent header, which is what monthly-active-user classification keys on. WithAgents now merges its entries into any agents already configured instead of replacing them, so the side agent appended by the constructors and a user-supplied WithAgents coexist regardless of option order. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
WalkthroughThe PR merges successive Ably agent options and adds device- and server-scoped Pub/Sub client constructors that attach corresponding agent identifiers. Tests verify generated ChangesPub/Sub agent classification
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant PubSubConstructor
participant AblyClient
participant HTTPServer
Caller->>PubSubConstructor: provide client options
PubSubConstructor->>AblyClient: create client with scoped agent
AblyClient->>HTTPServer: send request with Ably-Agent
HTTPServer-->>Caller: captured agent header
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pubsub/server/server_test.go (1)
36-56: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover
NewRealtimeClientas well.The new public realtime constructor has a separate code path, but these tests exercise only
NewHTTPClient. Add equivalent agent and user-agent assertions forserver.NewRealtimeClient(with auto-connect disabled) so regressions in realtime option propagation are detected.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pubsub/server/server_test.go` around lines 36 - 56, Extend the constructor agent tests to cover server.NewRealtimeClient using auto-connect disabled. Add equivalent assertions for the ably-go-pubsub-server agent and merged user agent, alongside the existing NewHTTPClient tests, so realtime option propagation is verified.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pubsub/server/server_test.go`:
- Around line 36-56: Extend the constructor agent tests to cover
server.NewRealtimeClient using auto-connect disabled. Add equivalent assertions
for the ably-go-pubsub-server agent and merged user agent, alongside the
existing NewHTTPClient tests, so realtime option propagation is verified.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 6d9d83b2-18e5-48c6-a8b2-cfa394cd41fe
📒 Files selected for processing (5)
ably/options.gopubsub/device/device.gopubsub/device/device_test.gopubsub/server/server.gopubsub/server/server_test.go
| // agentName declares the side in the Ably-Agent header (RSC7d) so that | ||
| // traffic from clients constructed by this package is classified as | ||
| // device-side. | ||
| const agentName = "ably-go-pubsub-device" |
There was a problem hiding this comment.
probably should be ably-pubsub-device-go
There was a problem hiding this comment.
Based on our internal decision record, the agent entry needs to end in -device or -server.
|
Do we expect there to be go devices? |
|
@paddybyers I think there was a recent discussion where it was suggested that the Go SDK could be used to build a desktop or CLI app, in which case it would be in a device context. |
Introduce per-side pubsub packages, so applications declare whether they are running on an end-user device or a server by their choice of package. Additive and shippable in a minor release.
Packages
pubsub/device—NewClient, returning aClient(=ably.Realtime)pubsub/server—NewHTTPClientandNewRealtimeClient, returning anHTTPClient(=ably.REST) and aRealtimeClient(=ably.Realtime)The constructors return type aliases of today's clients rather than wrapper types: the side is the package and constructor choice plus the agent declaration, not a type distinction.
Agent declaration
Each constructor appends a side-declaring agent (
ably-go-pubsub-device/ably-go-pubsub-server) to theAbly-Agentheader, which is what monthly-active-user classification keys on.WithAgentsnow merges its entries into any agents already configured instead of replacing them, so the side agent appended by the constructors and a user-suppliedWithAgentscoexist regardless of option order.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests