cli/display: merge a batch of todo calls into one line

A round that updated its todo list printed one header plus a full stack
render per call, so the same list appeared several times. When a batch only
touches todo tools, print one `* Todo x<N>: Push, Update` line and the last
result, whose text already ends with the final stack. A batch holding any
other tool keeps the per-call lines, and a todo call never prints a prefix
at call time (it would dangle when the batch is merged).
This commit is contained in:
2026-10-06 20:51:07 +08:00
parent 49ddf1c3c1
commit 7cd5fcc576
2 changed files with 88 additions and 2 deletions
+45
View File
@@ -186,6 +186,51 @@ async def test_pretty_todo_push(capsys: pytest.CaptureFixture[str]) -> None:
assert "[tool]" not in out
async def test_pretty_todo_batch_merges_to_one_stack(capsys: pytest.CaptureFixture[str]) -> None:
"""A batch of todo calls: one summary line, then the last result's stack."""
stack = "(LIFO of groups: depth=1; TOP group = current breakdown level)\ngroup d=0 TOP:\n [ ] a1: T1"
await render_events(
_aiter(
[
_pretty_call("todo_push", '{"titles": ["T1"]}'),
_pretty_call("todo_update", '{"item_id": "a1", "status": "done"}'),
_result(f"pushed group (depth=1) items=[a1]\n{stack}"),
_result(f"updated a1 → done: T1\n{stack}"),
]
)
)
out = capsys.readouterr().out
assert "* Todo x2: Push, Update" in out
assert "* Todo Push:" not in out
assert "* Todo Update:" not in out
# Only the last result is printed, so the stack renders once.
assert out.count("group d=0 TOP:") == 1
assert "pushed group" not in out
assert "updated a1 → done: T1" in out
async def test_pretty_todo_batch_mixed_with_other_tool_stays_per_call(
capsys: pytest.CaptureFixture[str],
) -> None:
"""A batch holding a non-todo call keeps one line (and stack) per todo call."""
stack = "group d=0 TOP:\n [ ] a1: T1"
await render_events(
_aiter(
[
_pretty_call("todo_push", '{"titles": ["T1"]}'),
_pretty_call("listdir", '{"path": "src"}'),
_result(f"pushed group (depth=1) items=[a1]\n{stack}"),
_result("dir\tsrc\nfile\tREADME.md\n"),
]
)
)
out = capsys.readouterr().out
assert "* Todo Push:" in out
assert "group d=0 TOP:" in out
assert "src" in out
assert "* Todo x" not in out
async def test_non_pretty_tool_keeps_old_style(capsys: pytest.CaptureFixture[str]) -> None:
"""Tools with no pretty line (plugins, unknown names) keep the ``[tool]`` style."""
call = ToolCallEvent(