test(models): re-enable finish_reason unknown-maps-to-OTHER litellm test#6303
Open
anxkhn wants to merge 1 commit into
Open
test(models): re-enable finish_reason unknown-maps-to-OTHER litellm test#6303anxkhn wants to merge 1 commit into
anxkhn wants to merge 1 commit into
Conversation
test_finish_reason_unknown_maps_to_other was skipped during the v2.0.0 GA transition with reason "LiteLLM finish_reason mapping behaviour changed". That reason is now stale: _map_finish_reason ends with _FINISH_REASON_MAPPING.get(finish_reason_str, types.FinishReason.OTHER), so any unmapped finish_reason deterministically maps to OTHER regardless of LiteLLM's own normalization. The test bypasses that normalization with a mock returning a raw "totally_unknown_reason" and asserts the OTHER fallback. This skipped test is the only coverage of the _map_finish_reason -> OTHER fallback branch in the litellm suite, so the skip left a live production branch untested. Removing the skip restores that coverage with no production change; the test passes as-is.
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
Problem:
test_finish_reason_unknown_maps_to_otherintests/unittests/models/test_litellm.pyis skipped with@pytest.mark.skip(reason="LiteLLM finish_reason mapping behaviour changed").That skip was added during the v2.0.0 GA transition, and the reason is now stale.
LiteLlm._map_finish_reasonends with:so any
finish_reasonthat is not in_FINISH_REASON_MAPPING(which only haslength,stop,tool_calls,function_call,content_filter)deterministically maps to
FinishReason.OTHER, independent of LiteLLM's ownnormalization. The test deliberately builds a mock choice/response that returns a
raw
"totally_unknown_reason"to bypass LiteLLM's normalization and exerciseADK's own fallback, and asserts the result is
OTHER. This skipped test is theonly coverage of the
_map_finish_reason -> OTHERfallback branch in the litellmsuite, so the skip has left a live production branch untested.
Solution:
Remove the single
@pytest.mark.skip(...)line above the test. No productionchange. The test passes as-is against current code, restoring coverage of the
OTHERfallback. I chose deletion over refreshing the mock because the extractedtest body already drives
generate_content_async->_model_response_to_generate_content_response->_map_finish_reason->OTHERcorrectly against the current source; no mock detail has drifted.
Diff (1 file, -1 line):
-@pytest.mark.skip(reason="LiteLLM finish_reason mapping behaviour changed") @pytest.mark.asyncio async def test_finish_reason_unknown_maps_to_other( mock_acompletion, lite_llm_instanceTesting Plan
Unit Tests:
pytestresults (withuv run --no-sync):pytest tests/unittests/models/test_litellm.py::test_finish_reason_unknown_maps_to_other -q->
1 passed.pytest tests/unittests/models/test_litellm.py -q -k "finish_reason or map_finish"->
10 passed.pytest tests/unittests/models/test_litellm.py -q->
318 passed(previously317 passed, 1 skipped; the delta is exactly thisre-enabled test).
I also confirmed the test genuinely guards the branch: temporarily changing the
production fallback from
OTHERtoSTOPmade this test fail(
AssertionError: - OTHER + STOP); reverting restored green. So it is aneffective regression test, not a vacuous one.
Manual End-to-End (E2E) Tests:
N/A. This is a test-only change (removal of a stale skip marker); there is no
runtime or user-facing behavior to test manually.
Checklist
one-line skip-marker removal; the test already carries an explanatory
docstring and comments.)
(Re-enables the sole existing coverage of the
_map_finish_reason -> OTHERfallback.)
(None.)
Additional context
The mapping table and fallback live in
src/google/adk/models/lite_llm.py(
_FINISH_REASON_MAPPINGand_map_finish_reason). The test reaches the fallbackthrough
LiteLlm.generate_content_async->_model_response_to_generate_content_response, which readsfirst_choice.get("finish_reason")and passes it to_map_finish_reason.