From e27effcefe7804b9ebb3f07e3e0734f7cd4a6a39 Mon Sep 17 00:00:00 2001 From: worldmozara Date: Sat, 15 Aug 2026 18:37:12 +0800 Subject: [PATCH] cli: pretty printed summaries for vcs_status and vcs_log --- src/plyngent/cli/display.py | 22 ++++++++++++++++++ tests/test_cli/test_display.py | 42 ++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/src/plyngent/cli/display.py b/src/plyngent/cli/display.py index 3a87f64..1e4e24f 100644 --- a/src/plyngent/cli/display.py +++ b/src/plyngent/cli/display.py @@ -51,6 +51,8 @@ _PRETTY_TOOLS = frozenset( "copy_path", "move_path", "delete_path", + "vcs_status", + "vcs_log", } ) @@ -360,6 +362,24 @@ def _mutator_pretty(name: str, args_json: str, result: str) -> str: return _pretty_line(f"* {verb} {target} ", ("(done)", "green")) +def _vcs_status_pretty(_args_json: str, result: str) -> str: + """One-line summary for ``vcs_status``: ``* VCS Status (done)``.""" + if result.startswith("error:"): + return _pretty_line("* VCS Status ", (f"({result})", "red")) + return _pretty_line("* VCS Status ", ("(done)", "green")) + + +def _vcs_log_pretty(_args_json: str, result: str) -> str: + """One-line summary for ``vcs_log``: ``* VCS Log (5 commits)``.""" + if result.startswith("error:"): + return _pretty_line("* VCS Log ", (f"({result})", "red")) + if result == "(no commits)": + return _pretty_line("* VCS Log ", ("(no commits)", "dim")) + commits = [line for line in result.splitlines() if line.strip()] + unit = "commit" if len(commits) == 1 else "commits" + return _pretty_line("* VCS Log ", (f"({len(commits)} {unit})", None)) + + _PRETTY_BUILDERS: dict[str, Callable[[str, str], str]] = { "read_file": _read_file_pretty, "tree": _tree_pretty, @@ -377,6 +397,8 @@ _PRETTY_BUILDERS: dict[str, Callable[[str, str], str]] = { "copy_path": lambda args, result: _mutator_pretty("copy_path", args, result), "move_path": lambda args, result: _mutator_pretty("move_path", args, result), "delete_path": lambda args, result: _mutator_pretty("delete_path", args, result), + "vcs_status": _vcs_status_pretty, + "vcs_log": _vcs_log_pretty, } diff --git a/tests/test_cli/test_display.py b/tests/test_cli/test_display.py index f63f6a7..72b47fd 100644 --- a/tests/test_cli/test_display.py +++ b/tests/test_cli/test_display.py @@ -488,3 +488,45 @@ async def test_pretty_mutator_error(capsys: pytest.CaptureFixture[str]) -> None: ) out = capsys.readouterr().out assert "* Copy 'x' → 'y' (error: source does not exist: x)" in out + + +async def test_pretty_vcs_status_done(capsys: pytest.CaptureFixture[str]) -> None: + await render_events(_aiter([_pretty_call("vcs_status", "{}"), _result("(clean)")])) + out = capsys.readouterr().out + assert "* VCS Status (done)" in out + assert "[tool]" not in out + + +async def test_pretty_vcs_status_error(capsys: pytest.CaptureFixture[str]) -> None: + await render_events( + _aiter( + [ + _pretty_call("vcs_status", "{}"), + _result("error: no supported VCS detected under workspace (currently: git)"), + ] + ) + ) + out = capsys.readouterr().out + assert "* VCS Status (error: no supported VCS detected under workspace (currently: git))" in out + + +async def test_pretty_vcs_log_count(capsys: pytest.CaptureFixture[str]) -> None: + result = ( + "5436457 2026-08-15 worldmozara core/tools: allow edit_lineno append\nabc1234 2026-08-14 worldmozara cli: fix\n" + ) + await render_events(_aiter([_pretty_call("vcs_log", '{"limit": 2}'), _result(result)])) + out = capsys.readouterr().out + assert "* VCS Log (2 commits)" in out + + +async def test_pretty_vcs_log_single(capsys: pytest.CaptureFixture[str]) -> None: + content = "abc1234 2026-08-14 worldmozara x\n" + await render_events(_aiter([_pretty_call("vcs_log", '{"limit": 1}'), _result(content)])) + out = capsys.readouterr().out + assert "* VCS Log (1 commit)" in out + + +async def test_pretty_vcs_log_no_commits(capsys: pytest.CaptureFixture[str]) -> None: + await render_events(_aiter([_pretty_call("vcs_log", "{}"), _result("(no commits)")])) + out = capsys.readouterr().out + assert "* VCS Log (no commits)" in out