test(agent): cover think scrubber leak after flush-then-retry

This commit is contained in:
xxxigm 2026-07-14 18:01:47 +07:00 committed by kshitij
parent a569226f88
commit 8b209e0dd7

View file

@ -192,6 +192,32 @@ class TestFlushBehaviour:
s = StreamingThinkScrubber()
assert s.flush() == ""
def test_flush_restores_stream_start_boundary(self) -> None:
"""End-of-stream flush must re-arm block-boundary gating.
Thinking-only / empty-response retries flush then stream again
without ``reset()``. If flush left ``_last_emitted_ended_newline``
False (e.g. after emitting a held-back ``<``), the next stream's
opening ``<think>`` looked mid-line and leaked into the UI.
"""
s = StreamingThinkScrubber()
assert s.feed("word") == "word"
assert s._last_emitted_ended_newline is False
assert s.flush() == ""
assert s._last_emitted_ended_newline is True
assert (
_drive(s, ["<think>", "secret reasoning", "</think>", "Visible answer"])
== "Visible answer"
)
def test_flush_partial_tag_tail_does_not_poison_next_stream(self) -> None:
"""Flushing a held-back ``<`` must not make the next open tag leak."""
s = StreamingThinkScrubber()
s.feed("word<")
assert s.flush() == "<"
assert s._last_emitted_ended_newline is True
assert _drive(s, ["<think>hidden</think>Hello"]) == "Hello"
class TestRealisticStreaming:
"""Character-by-character streaming must work as well as larger chunks."""