mirror of
https://github.com/NCBM/plyngent.git
synced 2026-11-07 23:47:54 +08:00
cli: restore line range in read_file pretty summary
This commit is contained in:
@@ -154,7 +154,7 @@ def _pretty_line(prefix: str, *segments: tuple[str, str | None]) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def _read_file_pretty(args_json: str, result: str) -> str:
|
def _read_file_pretty(args_json: str, result: str) -> str:
|
||||||
"""One-line summary for a ``read_file`` call: ``* Read 'path' (done)``."""
|
"""One-line summary for a ``read_file`` call: ``* Read 'path' L1-4 (done)``."""
|
||||||
path = _json_str_arg(args_json, "path") or "?"
|
path = _json_str_arg(args_json, "path") or "?"
|
||||||
if result.startswith("error: file not found"):
|
if result.startswith("error: file not found"):
|
||||||
return _pretty_line(f"* Read '{path}' ", ("(file not found)", "red"))
|
return _pretty_line(f"* Read '{path}' ", ("(file not found)", "red"))
|
||||||
@@ -162,6 +162,9 @@ def _read_file_pretty(args_json: str, result: str) -> str:
|
|||||||
return _pretty_line(f"* Read '{path}' ", ("(not a file)", "red"))
|
return _pretty_line(f"* Read '{path}' ", ("(not a file)", "red"))
|
||||||
if result.startswith("error:"):
|
if result.startswith("error:"):
|
||||||
return _pretty_line(f"* Read '{path}' ", ("(error)", "red"))
|
return _pretty_line(f"* Read '{path}' ", ("(error)", "red"))
|
||||||
|
first = result.splitlines()[0] if result.splitlines() else ""
|
||||||
|
if first.startswith("L") and "-" in first:
|
||||||
|
return _pretty_line(f"* Read '{path}' ", (f"{first} ", "dim"), ("(done)", "green"))
|
||||||
return _pretty_line(f"* Read '{path}' ", ("(done)", "green"))
|
return _pretty_line(f"* Read '{path}' ", ("(done)", "green"))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -98,11 +98,19 @@ def _result(content: str) -> ToolResultEvent:
|
|||||||
async def test_pretty_read_file_done(capsys: pytest.CaptureFixture[str]) -> None:
|
async def test_pretty_read_file_done(capsys: pytest.CaptureFixture[str]) -> None:
|
||||||
await render_events(_aiter([_read_call('{"path": "a.txt"}'), _result("L1-4\none\ntwo\n")]))
|
await render_events(_aiter([_read_call('{"path": "a.txt"}'), _result("L1-4\none\ntwo\n")]))
|
||||||
out = capsys.readouterr().out
|
out = capsys.readouterr().out
|
||||||
assert "* Read 'a.txt' (done)" in out
|
assert "* Read 'a.txt' L1-4 (done)" in out
|
||||||
assert "[tool]" not in out
|
assert "[tool]" not in out
|
||||||
assert "[tool ok]" not in out
|
assert "[tool ok]" not in out
|
||||||
|
|
||||||
|
|
||||||
|
async def test_pretty_read_file_numbered_no_range(capsys: pytest.CaptureFixture[str]) -> None:
|
||||||
|
"""Numbered reads carry no L header, so the summary falls back to ``(done)``."""
|
||||||
|
content = " 1|one\n 2|two\n"
|
||||||
|
await render_events(_aiter([_read_call('{"path": "a.txt", "with_lineno": true}'), _result(content)]))
|
||||||
|
out = capsys.readouterr().out
|
||||||
|
assert "* Read 'a.txt' (done)" in out
|
||||||
|
|
||||||
|
|
||||||
async def test_pretty_read_file_statuses(capsys: pytest.CaptureFixture[str]) -> None:
|
async def test_pretty_read_file_statuses(capsys: pytest.CaptureFixture[str]) -> None:
|
||||||
cases = [
|
cases = [
|
||||||
("error: file not found: a.txt", "(file not found)"),
|
("error: file not found: a.txt", "(file not found)"),
|
||||||
|
|||||||
Reference in New Issue
Block a user