Skip to content

fix(mock): streamed chunks join back into the returned reply - #13811

Open
lester076 wants to merge 1 commit into
deepset-ai:mainfrom
lester076:fix/mock-chat-generator-stream-whitespace
Open

lester076 wants to merge 1 commit into
deepset-ai:mainfrom
lester076:fix/mock-chat-generator-stream-whitespace

Conversation

@lester076

Copy link
Copy Markdown
Contributor

Fixes #13810

Problem

MockChatGenerator splits the reply with re.findall(r"\S+\s*", reply.text), which drops leading whitespace and streams a whitespace-only reply as no text at all. The streamed chunks no longer join into the reply that run() returns, so tests using the mock to assert streaming behaviour see different text in the callback than in the reply — real generators stream the text unchanged.

What changed

The split is now r"\s*\S+\s*|\s+" (the fix suggested in the issue): leading whitespace rides on the first chunk, and whitespace-only text becomes a single chunk. Chunks still break between words, so per-chunk assertions keep working.

Verification

New test_streamed_chunks_join_back_into_the_reply parametrized over "\n\nhello there", " indented reply\n" and " ": the concatenated chunk contents equal the returned reply text (all three fail on main, pass here). test/components/generators/chat/test_mock.py: 36 passed. ruff check/ruff format clean.

@lester076
lester076 requested a review from a team as a code owner November 19, 2026 05:59
@lester076
lester076 requested review from bogdankostic and removed request for a team November 19, 2026 05:59
@vercel

vercel Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

@lester076 is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/generators/chat
  mock.py
  haystack/core/pipeline
  pipeline.py
Project Total  

This report was generated by python-coverage-comment-action

@lester076
lester076 force-pushed the fix/mock-chat-generator-stream-whitespace branch from d7de66a to 582a47b Compare November 19, 2026 06:12
MockChatGenerator split the reply with re.findall(r'\S+\s*'), which
drops leading whitespace and streams a whitespace-only reply as nothing
at all — the streamed chunks no longer joined into the reply that run()
returns, so tests asserting on streamed text saw different content than
the reply (deepset-ai#13810). Real generators stream the text unchanged.

Split with r'\s*\S+\s*|\s+': leading whitespace rides on the first
chunk and whitespace-only text becomes a single chunk.
@lester076
lester076 force-pushed the fix/mock-chat-generator-stream-whitespace branch from 582a47b to f0b98d8 Compare November 19, 2026 06:34

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MockChatGenerator streaming drops leading whitespace and whitespace-only replies

1 participant