Files
ai-agent-book/chapter5/coding-agent/tests/test_read_limit_zero.py
T
liqiang b119135836
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
2026-08-20 13:12:50 +00:00

39 lines
1.3 KiB
Python

"""limit=0 on a nonempty file must not claim the file is empty."""
def test_limit_zero_on_nonempty_file(system_state, temp_dir):
from tools.read_tool import ReadTool
path = temp_dir / "lines.txt"
path.write_text("a\nb\nc\n", encoding="utf-8")
result = ReadTool(system_state).execute(
{"file_path": str(path), "limit": 0}
)
data = result.data
assert data["total_lines"] == 3
assert data["content"] != "File is empty."
assert "No lines in selected range" in data["content"]
assert data["showing_lines"] == "1-0"
def test_truly_empty_file_still_warns(system_state, temp_dir):
from tools.read_tool import ReadTool
path = temp_dir / "empty.txt"
path.write_text("", encoding="utf-8")
result = ReadTool(system_state).execute({"file_path": str(path)})
assert result.data["content"] == "File is empty."
assert result.data["total_lines"] == 0
def test_positive_limit_still_returns_lines(system_state, temp_dir):
from tools.read_tool import ReadTool
path = temp_dir / "lines.txt"
path.write_text("a\nb\nc\n", encoding="utf-8")
result = ReadTool(system_state).execute(
{"file_path": str(path), "limit": 1}
)
assert " 1|a" in result.data["content"]
assert result.data["total_lines"] == 3