fix: fractional number as id -> invalid request#118
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR enhances JSON-RPC request validation by adding stricter validation for the id field to reject fractional numbers, while also improving test coverage and optimizing project dependencies.
- Validates that numeric IDs in JSON-RPC requests must be non-fractional integers
- Adds comprehensive test cases for fractional number ID validation
- Optimizes dependency configuration by moving
System.Threading.Channelsto target-specific scope
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/A2A/JsonRpc/JsonRpcRequestConverter.cs |
Added validation logic to reject fractional numbers as IDs and updated error message |
tests/A2A.UnitTests/JsonRpc/JsonRpcRequestConverterTests.cs |
Added test case for fractional number ID and updated assertion message |
tests/A2A.AspNetCore.UnitTests/A2AJsonRpcProcessorTests.cs |
Added test cases for valid integer and invalid fractional number IDs |
src/A2A/A2A.csproj |
Moved System.Threading.Channels dependency to netstandard2.0-specific scope and removed obsolete NoWarn directive |
There was a problem hiding this comment.
Summary of Changes
Hello @brandonh-msft, 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 primarily focuses on enhancing the robustness of JSON-RPC request handling by enforcing stricter validation rules for the id field, specifically disallowing fractional numbers. It also includes corresponding updates to unit tests to ensure proper error handling and minor adjustments to project dependencies for better target framework specificity and code analysis.
Highlights
- JSON-RPC Validation Enhancement: The
idfield validation in JSON-RPC requests has been made stricter. It now explicitly rejects fractional numbers, ensuring that numeric IDs must be non-fractional integers. The corresponding error message has been updated to reflect this new requirement. - Unit Test Coverage Expansion: New unit tests have been added across
A2AJsonRpcProcessorTestsandJsonRpcRequestConverterTeststo validate the proper handling and rejection of fractional number IDs, ensuring the updated validation logic works as expected. Existing tests for valid numeric IDs were also enabled. - Project Dependency Refinement: The
A2A.csprojfile was updated to adjust project dependencies. Specifically,System.Threading.Channelsis now conditionally included only for thenetstandard2.0target framework, and an irrelevantNoWarndirective forCA1510has been removed.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue 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 or fill out our survey to provide feedback.
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
-
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. ↩
There was a problem hiding this comment.
Code Review
This pull request correctly implements validation to reject fractional numbers as JSON-RPC request IDs, as per the spec's recommendation. The changes include updating the validation logic, adjusting the error message, and adding corresponding unit tests to ensure the new behavior is covered. The project dependencies have also been correctly adjusted for different target frameworks. My main feedback is a suggestion to refactor the validation logic for better readability.
we're doing this is editorconfig now, so the IDE won't complain either
a74aa48 to
bc08c1b
Compare
# Conflicts: # src/A2A/A2A.csproj
# Conflicts: # src/A2A/A2A.csproj
adamsitnik
left a comment
There was a problem hiding this comment.
LGTM, thank you @brandonh-msft !
This pull request includes updates to improve JSON-RPC request validation, enhance test coverage, and adjust project dependencies. The most important changes include stricter validation of the
idfield in JSON-RPC requests, expanded unit tests, and dependency adjustments in theA2A.csprojfile.JSON-RPC Request Validation Updates:
idfield validation inJsonRpcRequestConverter.csto ensure that numeric IDs must be non-fractional, throwing an exception for fractional numbers. The error message was updated accordingly. (src/A2A/JsonRpc/JsonRpcRequestConverter.cs, src/A2A/JsonRpc/JsonRpcRequestConverter.csL74-R80)Unit Test Enhancements:
A2AJsonRpcProcessorTeststo validate fractional number IDs as invalid and ensure proper error handling. (tests/A2A.AspNetCore.UnitTests/A2AJsonRpcProcessorTests.cs, tests/A2A.AspNetCore.UnitTests/A2AJsonRpcProcessorTests.csL11-R12)JsonRpcRequestConverterTeststo include fractional number IDs as invalid and updated assertions to match the new error message. (tests/A2A.UnitTests/JsonRpc/JsonRpcRequestConverterTests.cs, [1] [2]Project Dependency Adjustments:
System.Threading.Channelsas a dependency for thenetstandard2.0target framework and removed it from global dependencies inA2A.csproj. (src/A2A/A2A.csproj, [1] [2]NoWarndirective forCA1510, as it is no longer relevant. (src/A2A/A2A.csproj, src/A2A/A2A.csprojL13-L14)