Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions langstage_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ def start(self):

def stop(self):
"""Stop the spinner and clear the line."""
if not self.running:
return
self.running = False
if self.thread:
self.thread.join(timeout=0.2)
Expand Down
19 changes: 18 additions & 1 deletion tests/test_turn_exit_and_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
pytest.importorskip("fastapi")

from langstage_cli.agui_stream import build_session_agent # noqa: E402
from langstage_cli.cli import print_chunk, run_single_turn_agui # noqa: E402
from langstage_cli.cli import Spinner, print_chunk, run_single_turn_agui # noqa: E402


async def test_turn_reports_error_frame_for_nonzero_exit(monkeypatch):
Expand Down Expand Up @@ -46,6 +46,23 @@ async def test_successful_turn_reports_no_error():
assert had_error is False


async def test_turn_does_not_clear_output_after_first_chunk(monkeypatch):
async def fake_stream(agent, message, thread_id, resume=None):
yield {"status": "streaming", "chunk": "visible reply", "node": "agent"}

import langstage_cli.agui_stream as agui_mod

monkeypatch.setattr(agui_mod, "agui_stream_updates", fake_stream)
monkeypatch.setattr(Spinner, "_spin", lambda self: None)
buf = io.StringIO()
with redirect_stdout(buf):
await run_single_turn_agui(object(), "hi", "t-visible", interactive=False)

out = buf.getvalue()
assert out.count("\r\033[2K") == 1
assert out.endswith("visible reply")


def test_print_chunk_breaks_on_node_change_nonverbose():
# gh #43: two nodes' output must not render as one run-on line.
print_chunk._streaming_text = False
Expand Down