test: strengthen JSON preamble mutation coverage

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
ryan 2026-10-28 08:50:25 +00:00
parent e323ea243a
commit 814fd2275e
3 changed files with 38 additions and 7 deletions

View file

@ -210,8 +210,8 @@ class TestBedrockNative:
def test_bedrock_json_schema_response_exposes_text_before_json_tool_call(
self, proxy: ProxyClient, resources: ResourceManager, sdk: SdkClients
) -> None:
model = f"e2e-bedrock-json-mode-preamble-{unique_marker()}"
model_id = proxy.create_model(
model: Final = f"e2e-bedrock-json-mode-preamble-{unique_marker()}"
model_id: Final = proxy.create_model(
model,
LiteLLMParamsBody(
model=BEDROCK_JSON_SCHEMA_BACKEND,

View file

@ -9756,6 +9756,14 @@ def test_json_mode_text_without_tool_call_is_unchanged():
assert message.tool_calls is None
assert "json_mode_preamble_text" not in (message.provider_specific_fields or {})
preamble: Final = "Let me answer the question. "
json_result: Final = _transform_json_mode_body(
{**body, "content": [{"type": "text", "text": preamble}, *body["content"]]}
)
json_message: Final = json_result.choices[0].message
assert json_message.content == '{"answer": "Hello"}'
assert json_message.provider_specific_fields["json_mode_preamble_text"] == preamble
def test_json_mode_with_a_real_tool_keeps_mixed_response_behavior():
preamble: Final = "I will look up the details. "
@ -9778,6 +9786,13 @@ def test_json_mode_with_a_real_tool_keeps_mixed_response_behavior():
assert message.tool_calls[0].function.arguments == '{"location": "San Francisco"}'
assert "json_mode_preamble_text" not in (message.provider_specific_fields or {})
json_result: Final = _transform_json_mode_body(
{**body, "content": [{"type": "text", "text": preamble}, *body["content"]]}
)
json_message: Final = json_result.choices[0].message
assert json_message.content == '{"answer": "Hello"}'
assert json_message.provider_specific_fields["json_mode_preamble_text"] == preamble
def test_non_dict_upstream_body_still_transforms_without_refusal_fields() -> None:
result = AnthropicConfig().transform_parsed_response(

View file

@ -6761,7 +6761,7 @@ def _transform_json_mode_content_blocks(content: list[dict[str, object]]) -> Mod
return json.dumps(response_json)
return AmazonConverseConfig()._transform_response(
model="bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0",
model="bedrock/us.anthropic.claude-haiku-5-5",
response=MockResponse(),
model_response=ModelResponse(),
stream=False,
@ -6795,7 +6795,7 @@ def test_bedrock_json_mode_preserves_nonblank_text_before_json_tool_call():
def test_bedrock_json_mode_omits_whitespace_only_preamble():
result: Final = _transform_json_mode_content_blocks(
whitespace_result: Final = _transform_json_mode_content_blocks(
[
{"text": " \n\t"},
{
@ -6808,9 +6808,25 @@ def test_bedrock_json_mode_omits_whitespace_only_preamble():
]
)
message: Final = result.choices[0].message
assert message.content == '{"answer": 42}'
assert "json_mode_preamble_text" not in (message.provider_specific_fields or {})
whitespace_message: Final = whitespace_result.choices[0].message
assert whitespace_message.content == '{"answer": 42}'
assert "json_mode_preamble_text" not in (whitespace_message.provider_specific_fields or {})
preamble: Final = "Here is the answer. "
nonblank_result: Final = _transform_json_mode_content_blocks(
[
{"text": preamble},
{
"toolUse": {
"toolUseId": "tooluse_json_001",
"name": "json_tool_call",
"input": {"answer": 42},
}
},
]
)
nonblank_message: Final = nonblank_result.choices[0].message
assert nonblank_message.provider_specific_fields["json_mode_preamble_text"] == preamble
def test_bedrock_json_mode_preamble_preserves_reasoning_content_fields():