chore(lint): type JSON-parsed task data in a2a-server#27685
Conversation
Eliminates four `@typescript-eslint/no-unsafe-assignment` suppressions in the a2a-server persistence/restore paths by typing the values deserialized from JSON instead of leaving them as `any`: - commands/restore.ts: annotate the parsed checkpoint as `unknown`; it is immediately validated by a Zod `safeParse`, which accepts `unknown`. - persistence/gcs.ts: type the loaded task metadata as `PersistedTaskMetadata` (consistent with the existing `as PersistedTaskMetadata` usage in the same file) and reuse the existing `getContextIdFromMetadata` helper to read the context id in a type-safe way. Net result: four no-unsafe-assignment suppressions removed, one no-unsafe-type-assertion added in gcs.ts. Behavior is unchanged for the documented metadata shape (`_contextId` is always a string). Part of google-gemini#19440
Summary of ChangesHello, 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 focuses on enhancing type safety within the a2a-server by addressing unsafe assignments during JSON deserialization. By explicitly typing parsed data and utilizing existing validation helpers, the changes reduce reliance on 'any' types and suppressions, contributing to the ongoing linter hygiene epic. Highlights
Using Gemini Code AssistThe 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
Customization To customize the 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 Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. 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. Footnotes
|
|
📊 PR Size: size/S
|
There was a problem hiding this comment.
Code Review
This pull request improves type safety and cleans up ESLint disable comments in the a2a-server package. In restore.ts, parsed JSON is now typed as unknown before schema validation. In gcs.ts, explicit type assertions and the getContextIdFromMetadata helper are introduced to avoid unsafe assignments. There are no review comments, and I have no feedback to provide.
Summary
Part of the linter hygiene epic (#19440), which calls out unsafe assignments as a target. This eliminates four
@typescript-eslint/no-unsafe-assignmentsuppressions in the a2a-server persistence/restore paths by typing the values deserialized from JSON instead of leaving them asany.Changes
commands/restore.ts— annotate the parsed checkpoint asunknown; it is immediately validated by a ZodsafeParse, which already acceptsunknown. No new suppression.persistence/gcs.ts— type the loaded task metadata asPersistedTaskMetadata(consistent with the existingas PersistedTaskMetadatausage elsewhere in the same file) and reuse the existinggetContextIdFromMetadatahelper to read the context id in a type-safe way.Net result: four
no-unsafe-assignmentsuppressions removed, oneno-unsafe-type-assertionadded ingcs.ts.Behavior
Unchanged for the documented metadata shape —
_contextIdis always written as a string (seeagent/executor.ts), andgetContextIdFromMetadatareturns it directly. For malformed/non-string values it now falls back to a freshuuidv4()instead of propagating a non-string, which is slightly more robust.Testing
eslintclean on both filestsc --noEmitpasses for@google/gemini-cli-a2a-servergcs.test.ts(12) andrestore.test.ts(6)