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

spec: Don't expect integers to round-trip through msg.extras #435

Merged
merged 1 commit into from
Sep 2, 2024

Conversation

lmars
Copy link
Member

@lmars lmars commented Aug 21, 2024

Internally, we store msg.extras in a protobuf.Struct which stores a JSON number in a double field:

https://github.com/protocolbuffers/protobuf/blob/5cbf13bc9ab0f883bcb664241f6be8d962915569/src/google/protobuf/struct.proto#L56-L78

This means that when a connection is using binary encoding (i.e. msgpack), any numbers in msg.extras are stored as floats even if the inbound message encoded the number as an int type, so the inbound and outbound representations are not guaranteed to be the same, although the semantic numeric value will be the same.

This commit handles this nuance by not expecting an integer to come back as an integer in msg.extras, but expecting a float to instead.

Summary by CodeRabbit

  • Bug Fixes

    • Updated test data to ensure type consistency by changing an integer value to a floating-point number, enhancing accuracy in data processing scenarios.
  • Tests

    • Improved test reliability by refining the data structure used in acceptance tests, which may impact validations and assertions involved in encoding and decoding operations.

@lmars lmars requested a review from owenpearson August 21, 2024 08:24
Copy link

coderabbitai bot commented Aug 21, 2024

Walkthrough

The recent changes involve a modification to the test data structure in the publish_and_check_extras method. An integer value was updated to a floating-point number, which may impact how the data is processed in tests that rely on type consistency. The overall structure remains unchanged, but this adjustment could influence encoding, decoding, and validation processes.

Changes

Files Change Summary
spec/acceptance/realtime/message_spec.rb Updated test data structure by changing an integer value 55 to a floating-point 55.1 in a JSON Array.

Poem

In a field of bytes and bits,
A change was made with gentle wits.
From fifty-five, we’ve floated high,
A point one now, oh my, oh my!
With care we test, as rabbits do,
To hop through code, both fresh and new! 🐇✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 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.
Early access features: disabled

We are currently testing the following features in early access:

  • Anthropic claude-3-5-sonnet for code reviews: Anthropic claims that the new Claude model has stronger code understanding and code generation capabilities than their previous models. Note: Our default code review model was also updated late last week. Please compare the quality of the reviews between the two models by toggling the early access feature.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues on the discussion post.

@github-actions github-actions bot temporarily deployed to staging/pull/435/docs August 21, 2024 08:24 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/435/features August 21, 2024 08:24 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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 85687a1 and 7840544.

Files selected for processing (1)
  • spec/acceptance/realtime/message_spec.rb (1 hunks)
Additional comments not posted (1)
spec/acceptance/realtime/message_spec.rb (1)

176-176: Verify the impact of changing integer to float in test data.

Changing the integer 55 to a float 55.1 in the test data aligns with the PR objective to handle numeric values as floats. Ensure that this change is reflected in all relevant tests and does not cause unintended side effects.

Run the following script to verify the impact of this change on the test behavior:

Verification successful

Change from integer to float is adequately tested and verified.

The modification of the test data to include a float instead of an integer is verified by the test case, which checks for consistent encoding and decoding. This ensures that the change aligns with the PR's objective and does not introduce unintended side effects.

  • The test it 'is encoded and decoded to the same Array' confirms the correct handling of the float value.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the change from integer to float in test data does not cause unintended side effects.

# Test: Search for the usage of the modified data structure. Expect: Consistent handling of numeric values as floats.
rg --type ruby -A 5 $'let(:data) { { \'push\' => { \'data\' => { \'key\' => [ true, false, 55.1, nil, \'string\', { \'Hash\' => true }, [\'array\'] ] } } } }'

Length of output: 402


Script:

#!/bin/bash
# Description: Verify that the change from integer to float in test data does not cause unintended side effects.

# Corrected Test: Search for the usage of the modified data structure. Expect: Consistent handling of numeric values as floats.
rg --type ruby -A 5 "let\(:data\) \{ \{ 'push' => \{ 'data' => \{ 'key' => \[ true, false, 55\.1, nil, 'string', \{ 'Hash' => true \}, \['array'\] \] \} \} \} \}"

Length of output: 698

Copy link
Member

@owenpearson owenpearson left a comment

Choose a reason for hiding this comment

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

I'm not entirely sure about this, probably not a big deal for frontdoor websockets but will this affect extras when publishing push notifications through frontdoors? for example we have live docs which specify an int value in extras here, is it safe to assume this will all still work correctly if we stop enforcing that ints survive protobuf encoding?

@lmars
Copy link
Member Author

lmars commented Aug 30, 2024

@owenpearson so this only affects msgpack encoding, JSON doesn't have different number types so whether we store an integer as a float or int internally, in JSON it will encode the same (and specifically, this means it won't affect push notifications since they will be encoded as JSON when we send them to the push platform, similarly for integrations), so I don't think this will impact anything other than clients which subscribe using msgpack always getting numbers as floats in msgpack-encoded extras.

Copy link
Member

@owenpearson owenpearson left a comment

Choose a reason for hiding this comment

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

ok nice, sgtm

Internally, we store msg.extras in a protobuf.Struct which stores a JSON
number in a double field:

https://github.com/protocolbuffers/protobuf/blob/5cbf13bc9ab0f883bcb664241f6be8d962915569/src/google/protobuf/struct.proto#L56-L78

This means that when a connection is using binary encoding (i.e.
msgpack), any numbers in msg.extras are encoded as floats even if the
inbound message encoded the number as an int type, so the inbound and
outbound representations are not guaranteed to be the same, although the
semantic numeric value will be the same.

This commit handles this nuance by not expecting an integer to come back
as an integer in msg.extras, but expecting a float to instead.

Signed-off-by: Lewis Marshall <[email protected]>
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7840544 and ca52a1d.

Files selected for processing (1)
  • spec/acceptance/realtime/message_spec.rb (1 hunks)
Additional comments not posted (1)
spec/acceptance/realtime/message_spec.rb (1)

176-176: The code change looks good.

Changing the type of a value in the test data from integer to float should not impact the behavior of the test. The test is only concerned with encoding and decoding the data, not the specific types of the array elements.

@lmars lmars merged commit 5a9e7bc into main Sep 2, 2024
22 of 23 checks passed
@lmars lmars deleted the msg-extras-float branch September 2, 2024 15:12
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