refactor(cli): split commands into focused modules (#5175)

This commit is contained in:
chengyongru
2026-07-30 15:01:35 +08:00
committed by GitHub
parent ad6900e56c
commit e2563e2e74
24 changed files with 3190 additions and 2781 deletions
+21 -21
View File
@@ -4,7 +4,7 @@ from unittest.mock import patch
import pytest
from nanobot.bus.outbound_events import ProgressEvent, RetryWaitEvent
from nanobot.cli import commands
from nanobot.cli import terminal
@pytest.mark.asyncio
@@ -22,8 +22,8 @@ async def test_interactive_retry_wait_is_rendered_as_progress_even_when_progress
async def fake_print(text: str, active_thinking: object | None, renderer=None) -> None:
calls.append((text, active_thinking))
with patch("nanobot.cli.commands._print_interactive_progress_line", side_effect=fake_print):
handled = await commands._maybe_print_interactive_progress(
with patch("nanobot.cli.terminal._print_interactive_progress_line", side_effect=fake_print):
handled = await terminal._maybe_print_interactive_progress(
msg,
thinking,
channels_config,
@@ -46,8 +46,8 @@ async def test_reasoning_displayed_when_show_reasoning_enabled():
metadata={},
)
with patch("nanobot.cli.commands._print_cli_reasoning", side_effect=lambda t, th, r=None: calls.append(t)):
handled = await commands._maybe_print_interactive_progress(msg, None, channels_config)
with patch("nanobot.cli.terminal._print_cli_reasoning", side_effect=lambda t, th, r=None: calls.append(t)):
handled = await terminal._maybe_print_interactive_progress(msg, None, channels_config)
assert handled is True
assert calls == ["Let me think about this..."]
@@ -66,8 +66,8 @@ async def test_reasoning_delta_displayed_when_show_reasoning_enabled():
metadata={},
)
with patch("nanobot.cli.commands._print_cli_reasoning", side_effect=lambda t, th, r=None: calls.append(t)):
handled = await commands._maybe_print_interactive_progress(msg, None, channels_config)
with patch("nanobot.cli.terminal._print_cli_reasoning", side_effect=lambda t, th, r=None: calls.append(t)):
handled = await terminal._maybe_print_interactive_progress(msg, None, channels_config)
assert handled is True
assert calls == ["I should search first."]
@@ -79,10 +79,10 @@ async def test_reasoning_delta_buffers_until_sentence_boundary():
channels_config = SimpleNamespace(
send_progress=True, send_tool_hints=False, show_reasoning=True,
)
reasoning_buffer = commands._ReasoningBuffer()
reasoning_buffer = terminal._ReasoningBuffer()
with patch("nanobot.cli.commands._print_cli_reasoning", side_effect=lambda t, th, r=None: calls.append(t)):
first = await commands._maybe_print_interactive_progress(
with patch("nanobot.cli.terminal._print_cli_reasoning", side_effect=lambda t, th, r=None: calls.append(t)):
first = await terminal._maybe_print_interactive_progress(
SimpleNamespace(
content="The",
event=ProgressEvent(content="The", reasoning_delta=True),
@@ -92,7 +92,7 @@ async def test_reasoning_delta_buffers_until_sentence_boundary():
channels_config,
reasoning_buffer=reasoning_buffer,
)
second = await commands._maybe_print_interactive_progress(
second = await terminal._maybe_print_interactive_progress(
SimpleNamespace(
content=" user asked.",
event=ProgressEvent(content=" user asked.", reasoning_delta=True),
@@ -114,10 +114,10 @@ async def test_reasoning_end_flushes_buffered_delta():
channels_config = SimpleNamespace(
send_progress=True, send_tool_hints=False, show_reasoning=True,
)
reasoning_buffer = commands._ReasoningBuffer()
reasoning_buffer = terminal._ReasoningBuffer()
with patch("nanobot.cli.commands._print_cli_reasoning", side_effect=lambda t, th, r=None: calls.append(t)):
delta = await commands._maybe_print_interactive_progress(
with patch("nanobot.cli.terminal._print_cli_reasoning", side_effect=lambda t, th, r=None: calls.append(t)):
delta = await terminal._maybe_print_interactive_progress(
SimpleNamespace(
content="The user asked",
event=ProgressEvent(content="The user asked", reasoning_delta=True),
@@ -127,7 +127,7 @@ async def test_reasoning_end_flushes_buffered_delta():
channels_config,
reasoning_buffer=reasoning_buffer,
)
end = await commands._maybe_print_interactive_progress(
end = await terminal._maybe_print_interactive_progress(
SimpleNamespace(
content="",
event=ProgressEvent(reasoning_end=True),
@@ -155,8 +155,8 @@ async def test_reasoning_hidden_when_show_reasoning_disabled():
metadata={},
)
with patch("nanobot.cli.commands._print_cli_reasoning") as mock_reasoning:
handled = await commands._maybe_print_interactive_progress(msg, None, channels_config)
with patch("nanobot.cli.terminal._print_cli_reasoning") as mock_reasoning:
handled = await terminal._maybe_print_interactive_progress(msg, None, channels_config)
assert handled is True
mock_reasoning.assert_not_called()
@@ -178,8 +178,8 @@ async def test_non_reasoning_progress_not_affected_by_show_reasoning():
async def fake_print(text: str, thinking=None, renderer=None):
calls.append(text)
with patch("nanobot.cli.commands._print_interactive_progress_line", side_effect=fake_print):
handled = await commands._maybe_print_interactive_progress(msg, None, channels_config)
with patch("nanobot.cli.terminal._print_interactive_progress_line", side_effect=fake_print):
handled = await terminal._maybe_print_interactive_progress(msg, None, channels_config)
assert handled is True
assert calls == ["working on it..."]
@@ -200,10 +200,10 @@ async def test_reasoning_shown_when_send_progress_disabled():
)
with patch(
"nanobot.cli.commands._print_cli_reasoning",
"nanobot.cli.terminal._print_cli_reasoning",
side_effect=lambda t, th, r=None: calls.append(t),
):
handled = await commands._maybe_print_interactive_progress(msg, None, channels_config)
handled = await terminal._maybe_print_interactive_progress(msg, None, channels_config)
assert handled is True
assert calls == ["Let me think about this..."]