From 8252d6d2169dd5f711f98c562208ce3bd8610e98 Mon Sep 17 00:00:00 2001 From: Nigel Jones Date: Wed, 13 May 2026 10:23:01 +0100 Subject: [PATCH] fix(test): loosen fragile equality assertions in astream incremental tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two consecutive streaming chunks can legitimately contain identical content (repeated tokens, whitespace) — asserting `chunk2 != chunk1` or `not chunk2.startswith(chunk1)` produced spurious failures under load or with slow models. Replace both assertions with structural reassembly checks: verify that accumulated chunks are a prefix of (or equal to) the final value, which is the invariant that actually matters. Closes #628 Assisted-by: Claude Code --- test/core/test_astream_incremental.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/test/core/test_astream_incremental.py b/test/core/test_astream_incremental.py index 3da4f2ede..ea8c08f5e 100644 --- a/test/core/test_astream_incremental.py +++ b/test/core/test_astream_incremental.py @@ -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() @@ -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: + # 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), ( + "Assembled chunks should match final value progression" + ) @pytest.mark.ollama