Skip to content

Comments

test: subscribe param compatibility tests and docs (#17)#355

Merged
julienrbrt merged 3 commits intomainfrom
ws-compat_worker-1
Feb 23, 2026
Merged

test: subscribe param compatibility tests and docs (#17)#355
julienrbrt merged 3 commits intomainfrom
ws-compat_worker-1

Conversation

@tac0turtle
Copy link
Contributor

@tac0turtle tac0turtle commented Feb 23, 2026

Summary

Partially addresses #17 with test coverage and documentation. No code logic changes.

Issue #17 asks: WebSocket subscribe should use plain string query instead of SubscribeArgs struct for compatibility with Tendermint WS clients.

Finding: CometBFT v0.38's jsonParamsToArgs already normalizes both map ({"query": "..."}) and array (["..."]) param formats into a plain string before reaching ev-abci's Subscribe handler. The function signature already takes query string. So the param format issue is handled at the CometBFT layer — no code change needed in ev-abci.

What this PR adds:

  • 15 tests for Subscribe, Unsubscribe, UnsubscribeAll covering input validation, event delivery, slow client handling, subscription cancellation, and boundary conditions
  • Doc comment on Subscribe explaining the param format compatibility situation for future maintainers

What remains for full #17 closure:

Test coverage

  • Input validation: empty query, oversized query (512/513 boundary), malformed query
  • Client limits: max subscription clients, max subscriptions per client
  • Event delivery: publishes real event via EventBus, asserts WriteRPCResponse called with correct payload
  • Slow client: CloseOnSlowClient=true + write error triggers cancellation response
  • Subscription cancellation: EventBus stop triggers "CometBFT exited" response
  • Unsubscribe: valid, not-found, unsubscribe-all with state verification

Related: #18, #20

Test plan

  • make test passes with race detection
  • make lint passes with zero warnings
  • All 15 new tests pass

🤖 Generated with Claude Code

tac0turtle and others added 3 commits February 23, 2026 15:20
Automatically adds newly opened issues to the EVStack Evolve
project board (orgs/evstack/projects/7).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Create pkg/rpc/core/events_test.go with table-driven tests covering:
  Subscribe (valid query, empty query, oversized query, malformed query,
  max clients exceeded, max subscriptions per client exceeded),
  Unsubscribe (valid after subscribe, malformed query), and
  UnsubscribeAll (after subscribe).
- Add mockWSConn implementing rpctypes.WSRPCConnection to handle the
  background goroutine started by Subscribe.
- Add doc comment to Subscribe explaining that CometBFT's jsonParamsToArgs
  normalises map/array param formats to a plain string before this function
  is called, making it compatible with legacy Tendermint WS clients (#17).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add goroutine behavior coverage that was completely absent:

- TestSubscribe_EventDelivery: publish a NewBlock event to the real
  EventBus and assert WriteRPCResponse is called on the WSConn mock with
  the correct subscription ID and ResultEvent.Query payload. Uses a
  buffered channel + select-with-timeout for synchronisation.
- TestSubscribe_SlowClient: set CloseOnSlowClient=true, have
  WriteRPCResponse return an error, publish event, assert
  TryWriteRPCResponse is called with "slow client" in Error.Data.
- TestSubscribe_Cancellation: stop the EventBus to trigger removeAll(nil),
  assert TryWriteRPCResponse carries "CometBFT exited" reason.

Edge case additions:
- Boundary query (exactly 512 chars) succeeds — confirms the > not >=
  condition in the length guard.
- Unsubscribe without prior Subscribe returns ErrSubscriptionNotFound.
- UnsubscribeAll with no subscriptions returns ErrSubscriptionNotFound.
- State verification: NumClientSubscriptions == 0 after Unsubscribe and
  UnsubscribeAll success cases.

Mock fixes:
- Replace blanket .Maybe() with .Once() + Run(signal-channel) for
  goroutine-path assertions; AssertExpectations called in each new test.
- .Maybe() retained only on cleanup-path mocks (TryWriteRPCResponse
  triggered by EventBus Stop in test cleanup for non-cancellation tests).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tac0turtle tac0turtle requested a review from a team as a code owner February 23, 2026 15:22
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @tac0turtle, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the robustness and clarity of the WebSocket event handling in the RPC layer. It introduces a comprehensive suite of tests for subscription and unsubscription functionalities, covering various scenarios from input validation to client behavior. Additionally, it updates the Subscribe function's documentation to explicitly detail its compatibility with different parameter formats, ensuring smoother integration for both legacy and modern WebSocket clients.

Highlights

  • Comprehensive WebSocket Event Handler Tests: Extensive unit tests have been added for the Subscribe, Unsubscribe, and UnsubscribeAll WebSocket event handlers, covering input validation, client limits, event delivery, slow client handling, and subscription cancellation scenarios.
  • Improved Subscribe Documentation: The Subscribe function now includes a detailed documentation comment clarifying how CometBFT's JSON-RPC layer normalizes both legacy Tendermint map-based and modern array-based parameter formats, ensuring compatibility for various WebSocket clients.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • pkg/rpc/core/events.go
    • Added documentation comment explaining WebSocket subscribe parameter compatibility for different JSON formats.
  • pkg/rpc/core/events_test.go
    • Added a new test file for WebSocket event handlers.
    • Implemented 15 new test cases for Subscribe, Unsubscribe, and UnsubscribeAll.
    • Included tests for input validation (empty, oversized, malformed queries), client limits (max clients, max subscriptions per client), event delivery, slow client handling, and subscription cancellation.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/add-to-project.yml
Activity
  • The author, tac0turtle, created this pull request to address issue WebSockets: string should be used instead of SubscribeArgs #17, focusing on WebSocket subscribe parameter compatibility.
  • The author has provided a detailed summary of the changes, including comprehensive test coverage and a test plan.
  • The author has confirmed that all new tests pass, and make test and make lint checks are successful.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces comprehensive tests for Subscribe, Unsubscribe, and UnsubscribeAll WebSocket event handlers, significantly improving test coverage. It also adds a documentation comment to the Subscribe function to clarify parameter format compatibility. The new tests cover various scenarios including input validation, client limits, event delivery, slow client handling, and subscription cancellation, which is a great addition to the codebase.

@julienrbrt julienrbrt changed the title fix: subscribe param compatibility tests and docs (#17) test: subscribe param compatibility tests and docs (#17) Feb 23, 2026
@julienrbrt julienrbrt merged commit c1388c3 into main Feb 23, 2026
20 checks passed
@julienrbrt julienrbrt deleted the ws-compat_worker-1 branch February 23, 2026 16:23
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.

2 participants