Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions test/core/test_astream_incremental.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,7 @@ async def test_astream_returns_incremental_chunks():
# If not computed, chunk2 should be new content only
assert chunk2 is not None, "Second chunk should not be None if not computed"

# The key test: chunk2 should NOT start with chunk1
# (it should be incremental, not accumulated)
if len(chunk2) > 0:
# chunk2 should be different from chunk1 (new content)
assert chunk2 != chunk1, (
"Second chunk should be different from first (incremental)"
)

# Get final value
final_val = await mot.avalue()

Expand Down Expand Up @@ -133,13 +126,14 @@ async def test_astream_beginning_length_tracking():
# Second call: beginning_length should be captured at start of this call
chunk2 = await mot.astream()

if chunk2 and len(chunk2) > 0:
# chunk2 should not include chunk1's content
# This verifies the slicing logic at lines 352-356
if chunk1:
assert not chunk2.startswith(chunk1), (
"Second chunk should not start with first chunk (should be incremental)"
)
if chunk2 and len(chunk2) > 0 and chunk1:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ok given the expected answer, but in general this accumulation test would make more sense as a loop instead of only working with chunk1,2

# Verify that chunks reassemble correctly (not that they differ textually —
# two consecutive identical tokens are valid).
final_val = await mot.avalue()
accumulated = chunk1 + chunk2
assert final_val.startswith(accumulated) or accumulated.startswith(final_val), (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the right operand of the or could use a comment. It seems to me to not be the obvious thing we want to test here but more of a different truncation case.

"Assembled chunks should match final value progression"
)


@pytest.mark.ollama
Expand Down
Loading