Fix test
Some checks failed
Unit Tests: Proxy DB Operations / proxy-db (auth-checks, tests/proxy_unit_tests/test_auth_checks.py tests/proxy_unit_tests/test_user_api_key_auth.py, 20, 8) (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-db (key-generation, tests/proxy_unit_tests/test_key_generate_prisma.py, 30, 0) (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-db (proxy-utils, tests/proxy_unit_tests/test_proxy_utils.py, 20, 8) (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-db (remaining, tests/proxy_unit_tests --ignore=tests/proxy_unit_tests/test_key_generate_prisma.py --ignore=tests/proxy_unit_tests/test_auth_checks.py --ignore=tests/proxy_unit_tests/test_user_api_key_auth.py --ignore=tests/proxy_unit_tests/test_p… (push) Has been cancelled
Unit Tests: Security / security (push) Has been cancelled

This commit is contained in:
Sameer Kankute 2026-04-24 20:10:30 +05:30
parent e7bc1616cc
commit e03bb3437f
No known key found for this signature in database

View file

@ -86,8 +86,10 @@ def test_check_if_part_exists_in_parts_camel_case_snake_case():
assert check_if_part_exists_in_parts(parts_mixed, part_mixed_casing)
def test_cached_content_omits_system_instruction_tools_toolconfig():
"""Regression: #26014 / #17304 — cachedContent must not ship with tools/system/toolConfig."""
def test_cached_content_respects_modify_params_for_cache_incompatible_fields():
"""Regression: cachedContent drops system/tools/toolConfig only when modify_params=True."""
import litellm
cache_name = "projects/p/locations/us-central1/cachedContents/abc123"
messages = [
{"role": "system", "content": "You are helpful"},
@ -104,33 +106,54 @@ def test_cached_content_omits_system_instruction_tools_toolconfig():
"tool_choice": {"functionCallingConfig": {"mode": "AUTO"}},
}
result = _transform_request_body(
messages=list(messages),
model="gemini-2.5-pro",
optional_params=dict(optional_params),
custom_llm_provider="vertex_ai",
litellm_params={},
cached_content=cache_name,
)
original_modify_params = litellm.modify_params
try:
# With modify_params=False (default), keep fields even with cachedContent.
litellm.modify_params = False
result = _transform_request_body(
messages=list(messages),
model="gemini-2.5-pro",
optional_params=dict(optional_params),
custom_llm_provider="vertex_ai",
litellm_params={},
cached_content=cache_name,
)
assert result.get("cachedContent") == cache_name
assert "system_instruction" in result
assert "tools" in result
assert "toolConfig" in result
assert "contents" in result
assert result.get("cachedContent") == cache_name
assert "system_instruction" not in result
assert "tools" not in result
assert "toolConfig" not in result
assert "contents" in result
# With modify_params=True, drop cache-incompatible fields.
litellm.modify_params = True
result_modify_true = _transform_request_body(
messages=list(messages),
model="gemini-2.5-pro",
optional_params=dict(optional_params),
custom_llm_provider="vertex_ai",
litellm_params={},
cached_content=cache_name,
)
assert result_modify_true.get("cachedContent") == cache_name
assert "system_instruction" not in result_modify_true
assert "tools" not in result_modify_true
assert "toolConfig" not in result_modify_true
assert "contents" in result_modify_true
# Without cache, conflicting fields are included as before
result_no_cache = _transform_request_body(
messages=list(messages),
model="gemini-2.5-pro",
optional_params=dict(optional_params),
custom_llm_provider="vertex_ai",
litellm_params={},
cached_content=None,
)
assert "system_instruction" in result_no_cache
assert "tools" in result_no_cache
assert "toolConfig" in result_no_cache
# Without cache, fields are always included.
result_no_cache = _transform_request_body(
messages=list(messages),
model="gemini-2.5-pro",
optional_params=dict(optional_params),
custom_llm_provider="vertex_ai",
litellm_params={},
cached_content=None,
)
assert "system_instruction" in result_no_cache
assert "tools" in result_no_cache
assert "toolConfig" in result_no_cache
finally:
litellm.modify_params = original_modify_params
# Tests for issue #14556: Labels field provider-aware filtering