test(standard-tests): allow extra content blocks in streaming assertions (#37592)

Reasoning-emitting chat models return `[reasoning, text]` content blocks
where vanilla models return `[text]`. The shared streaming integration
tests asserted exactly one block, which fails when reasoning blocks are
returned when streaming is otherwise correct.

Relaxed to assert text presence without touching the lifecycle,
`chunk_position`, or `output_version` checks.
This commit is contained in:
Mason Daugherty
2026-05-21 13:18:54 -05:00
committed by GitHub
parent 1aa4496fb4
commit 22575adba4

View File

@@ -852,8 +852,11 @@ class ChatModelIntegrationTests(ChatModelTests):
assert len(chunks) > 0 assert len(chunks) > 0
assert isinstance(full, AIMessageChunk) assert isinstance(full, AIMessageChunk)
assert full.content assert full.content
assert len(full.content_blocks) == 1 assert full.text
assert full.content_blocks[0]["type"] == "text" # Exactly one text block — guards against merge bugs that would produce
# multiple adjacent text blocks in the aggregated result.
text_blocks = [b for b in full.content_blocks if b["type"] == "text"]
assert len(text_blocks) == 1
# Verify chunk_position signaling # Verify chunk_position signaling
last_chunk = chunks[-1] last_chunk = chunks[-1]
@@ -902,8 +905,11 @@ class ChatModelIntegrationTests(ChatModelTests):
assert len(chunks) > 0 assert len(chunks) > 0
assert isinstance(full, AIMessageChunk) assert isinstance(full, AIMessageChunk)
assert full.content assert full.content
assert len(full.content_blocks) == 1 assert full.text
assert full.content_blocks[0]["type"] == "text" # Exactly one text block — guards against merge bugs that would produce
# multiple adjacent text blocks in the aggregated result.
text_blocks = [b for b in full.content_blocks if b["type"] == "text"]
assert len(text_blocks) == 1
# Verify chunk_position signaling # Verify chunk_position signaling
last_chunk = chunks[-1] last_chunk = chunks[-1]
@@ -941,8 +947,8 @@ class ChatModelIntegrationTests(ChatModelTests):
message = stream.output message = stream.output
assert isinstance(message, AIMessage) assert isinstance(message, AIMessage)
assert message.content assert message.content
assert len(message.content_blocks) == 1 assert message.text
assert message.content_blocks[0]["type"] == "text" assert any(block["type"] == "text" for block in message.content_blocks)
# `stream_events(version="v3")` always assembles content as v1 protocol blocks. # `stream_events(version="v3")` always assembles content as v1 protocol blocks.
assert message.response_metadata.get("output_version") == "v1" assert message.response_metadata.get("output_version") == "v1"
@@ -972,8 +978,8 @@ class ChatModelIntegrationTests(ChatModelTests):
message = await stream.output message = await stream.output
assert isinstance(message, AIMessage) assert isinstance(message, AIMessage)
assert message.content assert message.content
assert len(message.content_blocks) == 1 assert message.text
assert message.content_blocks[0]["type"] == "text" assert any(block["type"] == "text" for block in message.content_blocks)
assert message.response_metadata.get("output_version") == "v1" assert message.response_metadata.get("output_version") == "v1"
def test_invoke_with_model_override(self, model: BaseChatModel) -> None: def test_invoke_with_model_override(self, model: BaseChatModel) -> None: