Skip to content

Conversation

@Akanksha928
Copy link
Contributor

Description

This PR adds new unit tests to improve coverage for ProtoUtils.ToProto and ProtoUtils.FromProto.

Tests Added

  • testFromProtoPartUnsupportedType: verifies invalid proto parts throw InvalidParamsError.
  • testTaskQueryParamsInvalidName: makes sure invalid task name formats are handled gracefully.
  • testToProtoPartUnsupportedType: checks handling of unsupported Part types during conversion.

Fixes #304

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Akanksha928, 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 test coverage for the ProtoUtils conversion utilities, specifically focusing on ToProto and FromProto methods. The added tests ensure that these utilities can robustly handle various edge cases, such as unsupported data types and malformed input parameters, thereby improving the overall reliability and stability of the protobuf conversion logic.

Highlights

  • New Test File for FromProto: A new test file, FromProtoTest.java, has been added to specifically test the ProtoUtils.FromProto utility methods.
  • Unsupported Type Handling in FromProto: Added a test case testFromProtoPartUnsupportedType to verify that ProtoUtils.FromProto.message correctly throws an InvalidParamsError when encountering unsupported Part types within a message.
  • Invalid Task Query Parameters Handling: Included testTaskQueryParamsInvalidName to ensure that ProtoUtils.FromProto.taskQueryParams gracefully handles and extracts the ID from invalid task name formats in GetTaskRequest.
  • Unsupported Type Handling in ToProto: A new test testToProtoPartUnsupportedType has been added to ToProtoTest.java to confirm that ProtoUtils.ToProto.message can process messages containing unsupported Part types without failure, ensuring robustness during conversion.
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.

@Akanksha928
Copy link
Contributor Author

Hi, I’ve added three initial tests that match the Python equivalent.

Could you please confirm if this direction looks good before I add a few more?

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

This pull request adds unit tests to improve coverage for ProtoUtils, which is a good initiative. My review focuses on improving the correctness and robustness of these new tests. I've identified a test that will fail due to an incorrect exception assertion, a test that validates potentially undesirable lenient behavior, and another test that could be strengthened with more specific assertions. Please review my comments for details.

Comment on lines +16 to +21
io.a2a.spec.InvalidParamsError exception = assertThrows(
io.a2a.spec.InvalidParamsError.class,
() -> ProtoUtils.FromProto.message(invalidMessage)
);

assertEquals("Invalid parameters", exception.getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

This test asserts that an InvalidParamsError is thrown for an unsupported part type. However, the current implementation of ProtoUtils.FromProto.part() throws an InvalidRequestError. This discrepancy will cause the test to fail.

To align with the existing implementation, the test should expect an InvalidRequestError. If the long-term goal is to throw InvalidParamsError (which could be more semantically accurate), ProtoUtils.FromProto.part() should be updated, and that change should be part of this PR to ensure tests and code are in sync.

Suggested change
io.a2a.spec.InvalidParamsError exception = assertThrows(
io.a2a.spec.InvalidParamsError.class,
() -> ProtoUtils.FromProto.message(invalidMessage)
);
assertEquals("Invalid parameters", exception.getMessage());
io.a2a.spec.InvalidRequestError exception = assertThrows(
io.a2a.spec.InvalidRequestError.class,
() -> ProtoUtils.FromProto.message(invalidMessage)
);
assertEquals("Invalid request", exception.getMessage());

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can ignore this Gemini message, I think you're correct that an InvalidParamsError will occur.

Comment on lines +26 to +35
public void testTaskQueryParamsInvalidName() {
io.a2a.grpc.GetTaskRequest request = io.a2a.grpc.GetTaskRequest.newBuilder()
.setName("invalid-name-format")
.build();

var result = ProtoUtils.FromProto.taskQueryParams(request);

assertNotNull(result);
assertEquals("invalid-name-format", result.id());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This test validates that an invalid task name format is handled by using the entire string as the task ID. This behavior is too lenient and might hide bugs from malformed task names, as the name field is expected to follow the format tasks/{id}.

For better robustness, taskQueryParams() should validate the name format and throw an IllegalArgumentException if it's invalid. This would be consistent with how other methods in ProtoUtils, like getTaskPushNotificationConfigParams, handle malformed names.

Consider updating this test to assert that an IllegalArgumentException is thrown for an invalid name format, which would encourage a more robust implementation in taskQueryParams().

Comment on lines +312 to +313
assertNotNull(result);
assertEquals(1, result.getContentCount());
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The current assertion only checks that the number of parts is correct. To make this test more robust, you should also assert that the converted Part is empty, as it's an unsupported type. This ensures that an empty part is correctly generated and we are not accidentally creating a Part with data.

        assertNotNull(result);
        assertEquals(1, result.getContentCount());
        assertEquals(io.a2a.grpc.Part.PartCase.PART_NOT_SET, result.getContent(0).getPartCase());

@Akanksha928 Akanksha928 changed the title initial tests: add ToProto and FromProto tests test: add ToProto and FromProto tests Oct 12, 2025
.setName("invalid-name-format")
.build();

var result = ProtoUtils.FromProto.taskQueryParams(request);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking at the python test, it looks like it's expecting an error to occur in this case. If we're not currently getting an error, that likely means we should update the taskQueryParams method to make sure the name is in the right format.

.build();
io.a2a.grpc.Message result = ProtoUtils.ToProto.message(message);

assertNotNull(result);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking at the Python test, they are expecting an error to occur in this case. If we're not hitting an error here, that means that we likely need to update ToProto so that we get an error in this case.

@fjuma
Copy link
Collaborator

fjuma commented Oct 14, 2025

@Akanksha928 It looks like you're on the right track! I've added some comments. Feel free to let us know if you have more questions. Thanks!

@ehsavoie ehsavoie merged commit 4ddac8b into a2aproject:main Oct 21, 2025
8 of 12 checks passed
ehsavoie added a commit that referenced this pull request Oct 21, 2025
ehsavoie added a commit that referenced this pull request Oct 21, 2025
@ehsavoie
Copy link
Collaborator

I wrongly merged that so I reverted @Akanksha928 May you please fix the comments from @fjuma and re-send a PR. Sorry for this

kabir pushed a commit to kabir/a2a-java that referenced this pull request Dec 23, 2025
# Description

This PR adds new unit tests to improve coverage for `ProtoUtils.ToProto`
and `ProtoUtils.FromProto`.

### Tests Added
- `testFromProtoPartUnsupportedType`: verifies invalid proto parts throw
`InvalidParamsError`.
- `testTaskQueryParamsInvalidName`: makes sure invalid task name formats
are handled gracefully.
- `testToProtoPartUnsupportedType`: checks handling of unsupported
`Part` types during conversion.

Fixes a2aproject#304
kabir pushed a commit to kabir/a2a-java that referenced this pull request Dec 23, 2025
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.

[chore]: Add more tests for ProtoUtils

3 participants