Skip to content

Conversation

@zensgit
Copy link
Owner

@zensgit zensgit commented Oct 15, 2025

Purpose

  • Add contract tests to ensure Decimal fields serialize as JSON strings, preventing JS float precision issues.

Scope

  • jive-api/tests/contract_decimal_serialization.rs
    • Verifies GlobalMarketStats Decimal fields serialize as strings
    • Verifies AccountResponse Decimal fields serialize as strings (including optional fields)

Notes

@Copilot Copilot AI review requested due to automatic review settings October 15, 2025 15:18
@gemini-code-assist
Copy link

Summary of Changes

Hello @zensgit, 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 enhances the robustness of the API by adding comprehensive contract tests to validate the serialization of Decimal fields. The primary goal is to ensure that these fields are consistently converted to JSON strings, thereby safeguarding against potential precision loss when consumed by JavaScript clients. This is a crucial step in maintaining data integrity across the system.

Highlights

  • New Contract Tests: Introduced new contract tests specifically for Decimal serialization within the jive-api to prevent JavaScript float precision issues.
  • Decimal Field Serialization: Ensures that Decimal fields in GlobalMarketStats and AccountResponse are serialized as JSON strings, maintaining precision.
  • Specific Field Handling: Added an explicit check for the updated_at field, confirming it serializes as a numeric Unix timestamp (i64) rather than a string, as it's an exception to the general Decimal string serialization rule.
  • Test-Only Changes: These changes are purely for testing purposes and do not introduce any modifications to existing business logic, complementing prior Decimal migration efforts.
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

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds contract tests to verify that Decimal fields in API responses are serialized as JSON strings rather than numbers, which prevents JavaScript floating-point precision issues. This is part of a broader effort to ensure consistent Decimal handling across the API.

Key Changes

  • Added test assertions for GlobalMarketStats to verify Decimal fields serialize as strings
  • Added explicit verification that the updated_at timestamp field remains numeric

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

@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

This pull request adds valuable contract tests to ensure Decimal fields are correctly serialized as strings, which is an important step to prevent precision loss in client-side applications. The new tests cover both GlobalMarketStats and AccountResponse structs. My review contains one suggestion for improving the structure of the tests to enhance clarity and maintainability.

Comment on lines +27 to +28
// updated_at is numeric unix timestamp
assert!(val.get("updated_at").and_then(|v| v.as_i64()).is_some());

Choose a reason for hiding this comment

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

medium

The test function is named global_market_stats_decimal_serializes_as_string, which implies its scope is limited to testing Decimal fields. The added assertion for updated_at (an i64) is outside this scope. While testing the entire contract is important, mixing concerns within a single test can make the test suite harder to understand and maintain. It's best practice for a test to have a single, clear purpose reflected in its name.

To improve clarity, I recommend moving this check to a separate test function, for example global_market_stats_numeric_fields_are_serialized_correctly. This would keep your tests focused and self-documenting.

@zensgit zensgit merged commit eab65be into chore/invitations-audit-align-dev-mock Oct 15, 2025
@zensgit zensgit deleted the chore/decimal-contract-tests branch October 15, 2025 16:00
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.

1 participant