Skip to content

test(parser): add unit tests for payload_fixer module#1468

Open
vishnuprakaz wants to merge 4 commits into
google:mainfrom
vishnuprakaz:feature/add-payload-fixer-tests
Open

test(parser): add unit tests for payload_fixer module#1468
vishnuprakaz wants to merge 4 commits into
google:mainfrom
vishnuprakaz:feature/add-payload-fixer-tests

Conversation

@vishnuprakaz
Copy link
Copy Markdown

Description

Add unit tests for the payload_fixer module in the Python agent SDK.

The parse_and_fix function had no dedicated unit tests — it was only
exercised indirectly via conformance tests. This PR adds direct coverage
for all behaviors in the module.

Are these changes tested?

Yes — 20 tests covering:

  • Valid JSON list and single-object normalization
  • Smart quote (curly quote) normalization
  • Trailing comma removal (objects, arrays, nested structures)
  • Multiple messages in a single payload
  • Logging warnings on autofix
  • Invalid payloads raising ValueError with the correct message

Testing/Running Instructions

  1. Navigate to the Python SDK directory: cd agent_sdks/python
  2. Run the new tests: uv run pytest tests/parser/test_payload_fixer.py -v
  3. Verify all 20 tests pass.

Pre-launch Checklist

  • I signed the [CLA].
  • I read the [Contributors Guide].
  • I read the [Style Guide].
  • I have added updates to the [CHANGELOG].
  • I updated/added relevant documentation.
  • My code changes (if any) have tests.
  • If my branch is on fork, I have verified that scripts/e2e_test.sh passes.

Copy link
Copy Markdown
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 introduces a new test suite for the parse_and_fix utility, covering JSON normalization, trailing comma autofixes, and error handling. The review feedback highlights opportunities to improve test coverage by including single smart quotes and primitive JSON types (e.g., booleans, nulls) as invalid payloads. The reviewer also pointed out several redundant test cases that could be removed to reduce code duplication and improve clarity.

Comment thread agent_sdks/python/tests/parser/test_payload_fixer.py Outdated
Comment thread agent_sdks/python/tests/parser/test_payload_fixer.py Outdated
Comment thread agent_sdks/python/tests/parser/test_payload_fixer.py Outdated
Comment thread agent_sdks/python/tests/parser/test_payload_fixer.py
@vishnuprakaz vishnuprakaz force-pushed the feature/add-payload-fixer-tests branch from 8669aa3 to ef42fbe Compare May 20, 2026 12:35
@ditman
Copy link
Copy Markdown
Collaborator

ditman commented May 22, 2026

/cc @nan-yu do you mind taking a look at these tests?

@nan-yu
Copy link
Copy Markdown
Collaborator

nan-yu commented May 22, 2026

We have migrated unit tests into conformance tests so that it can be shared across multiple SDK languages: https://github.com/google/A2UI/blob/main/agent_sdks/conformance/suites/parser.yaml#L83.

Are there any missing test cases? If so, we should add them to the conformance test spec.

@vishnuprakaz
Copy link
Copy Markdown
Author

vishnuprakaz commented May 23, 2026

Thanks @nan-yu! Looking at suites/parser.yaml, the basic fix_payload cases are already covered. A few scenarios from this PR aren't in the YAML yet nested trailing commas, multiple messages, and additional invalid payload shapes. Should I add those to parser.yaml and close this PR?

@nan-yu
Copy link
Copy Markdown
Collaborator

nan-yu commented May 26, 2026

Thanks @nan-yu! Looking at suites/parser.yaml, the basic fix_payload cases are already covered. A few scenarios from this PR aren't in the YAML yet nested trailing commas, multiple messages, and additional invalid payload shapes. Should I add those to parser.yaml and close this PR?

You can go either way, either opening a new PR or repurposing this PR with new conformance tests in parser.yaml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants