mirror of
https://github.com/NCBM/plyngent.git
synced 2026-11-07 15:37:55 +08:00
cli: pretty printed summaries for vcs_status and vcs_log
This commit is contained in:
@@ -51,6 +51,8 @@ _PRETTY_TOOLS = frozenset(
|
|||||||
"copy_path",
|
"copy_path",
|
||||||
"move_path",
|
"move_path",
|
||||||
"delete_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"))
|
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]] = {
|
_PRETTY_BUILDERS: dict[str, Callable[[str, str], str]] = {
|
||||||
"read_file": _read_file_pretty,
|
"read_file": _read_file_pretty,
|
||||||
"tree": _tree_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),
|
"copy_path": lambda args, result: _mutator_pretty("copy_path", args, result),
|
||||||
"move_path": lambda args, result: _mutator_pretty("move_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),
|
"delete_path": lambda args, result: _mutator_pretty("delete_path", args, result),
|
||||||
|
"vcs_status": _vcs_status_pretty,
|
||||||
|
"vcs_log": _vcs_log_pretty,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -488,3 +488,45 @@ async def test_pretty_mutator_error(capsys: pytest.CaptureFixture[str]) -> None:
|
|||||||
)
|
)
|
||||||
out = capsys.readouterr().out
|
out = capsys.readouterr().out
|
||||||
assert "* Copy 'x' → 'y' (error: source does not exist: x)" in 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
|
||||||
|
|||||||
Reference in New Issue
Block a user