Skip to content

fix(test): loosen fragile equality assertions in astream incremental tests#1069

Open
planetf1 wants to merge 1 commit into
generative-computing:mainfrom
planetf1:worktree-issue-628
Open

fix(test): loosen fragile equality assertions in astream incremental tests#1069
planetf1 wants to merge 1 commit into
generative-computing:mainfrom
planetf1:worktree-issue-628

Conversation

@planetf1
Copy link
Copy Markdown
Contributor

@planetf1 planetf1 commented May 13, 2026

Misc PR

Type of PR

  • Bug Fix
  • New Feature
  • Documentation
  • Other

Description

Two assertions in test/core/test_astream_incremental.py compared streaming chunk content for inequality, which caused intermittent test failures:

assert chunk2 != chunk1                  # fragile
assert not chunk2.startswith(chunk1)     # fragile

Two consecutive streaming chunks can legitimately contain identical content — repeated tokens, whitespace, short common substrings — so these assertions fail spuriously under load or with slow models.

Both replaced with structural reassembly checks: verify that the accumulated chunks form a valid prefix of (or equal) the final streamed value. This is the invariant that actually matters, and is the same pattern already used correctly in test_astream_multiple_calls_accumulate_correctly.

Testing

  • Tests added to the respective file if code was changed
  • New code has 100% coverage if code as added
  • Ensure existing tests and github automation passes (a maintainer will kick off the github automation when the rest of the PR is populated)

Attribution

  • AI coding assistants used

…tests

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 generative-computing#628

Assisted-by: Claude Code
@github-actions github-actions Bot added the bug Something isn't working label May 13, 2026
@planetf1 planetf1 marked this pull request as ready for review May 14, 2026 12:09
@planetf1 planetf1 requested a review from a team as a code owner May 14, 2026 12:09
Copy link
Copy Markdown
Contributor

@markstur markstur left a comment

Choose a reason for hiding this comment

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

I approve merging this now as a targeted fix.
But I think the tests could be improved by using a loop for accumulation testing instead of chunk1 vs chunk2. Also if a loop is added then probably consolidate the 2 tests into 1.

Also see one nit about a comment but it's very optional.

# 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.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: loosen assertion in test_astream_incremental.py

2 participants