test(genai): make grounding_metadata assertions resilient to schema additions#1806
Open
obchain (obchain) wants to merge 1 commit into
Open
Conversation
…dditions `test_response_to_result_grounding_metadata` compared the emitted `grounding_metadata` dict against a frozen expected dict, so any new optional field added to upstream `google.genai.types` schemas (which default to `None` when unset) flipped the equality check and broke the test. `GroundingSupport.rendered_parts` was introduced in google-genai 1.69.0 and triggered this on supported releases >=1.69. Strip `None` values from both sides recursively before comparing. Preserves coverage of every field the test actually populates and keeps the assertion green across the supported `google-genai>=1.65.0` range without weakening guarantees. Fixes langchain-ai#1791
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
tests/unit_tests/test_chat_models.py::test_response_to_result_grounding_metadatastarted failing ongoogle-genai >= 1.69.0because that release addedGroundingSupport.rendered_parts. The field defaults toNone, soGenerateContentResponse.model_validate(...).model_dump()now emits"rendered_parts": Noneinsidegrounding_supports, which the frozenexpected_grounding_metadatadict in the test did not contain.Reproduced locally on
google-genai==1.74.0:The conversion code itself is correct — the test was the brittle part. Rather than freezing the expected dict to one specific upstream version (and breaking the older end of the supported range, or re-breaking on the next field addition), recursively strip
Nonevalues from both sides before comparing. The assertion still fails on any mismatched or missing real value the test cares about; it only ignores newly added optional fields that default toNone.Relevant issues
Fixes #1791
Type
🐛 Bug Fix / ✅ Test
Changes
libs/genai/tests/unit_tests/test_chat_models.py: add_strip_nonehelper and apply it to both operands of thegrounding_metadataequality assertion intest_response_to_result_grounding_metadata.Testing
Ran the failing tests against both ends of the supported
google-genairange:google-genai==1.74.0— 3 passed.google-genai==1.65.0(current minimum) — 3 passed.pytest tests/unit_tests/test_chat_models.py— 219 passed.ruff check,ruff format --check, andmypyclean on the touched file.