fix(tools): preserve supplied newlines when creating files

This commit is contained in:
Shuhan Si authored and Xubin Ren committed 2026-10-03 17:38:18 +08:00
1 parent 042bcbbe46
commit ae6801d3eb
2 files changed
+25 -3

No files matched your search

+22
View File
@@ -10,6 +10,28 @@ from nanobot.agent.tools.filesystem import (
WriteFileTool,
)
@pytest.mark.asyncio
@pytest.mark.parametrize("newline", ["\n", "\r\n", "\r"])
@pytest.mark.parametrize("operation", ["write", "edit_new", "edit_empty"])
async def test_file_creation_preserves_provided_newlines(tmp_path, newline, operation):
target = tmp_path / "nested" / "script.py"
content = f"first = 1{newline}second = 2{newline}"
if operation == "write":
result = await WriteFileTool(workspace=tmp_path).execute(
path=str(target), content=content,
)
else:
if operation == "edit_empty":
target.parent.mkdir()
target.touch()
result = await EditFileTool(workspace=tmp_path).execute(
path=str(target), old_text="", new_text=content,
)
assert "Error" not in result
assert target.read_bytes() == content.encode("utf-8")
# ---------------------------------------------------------------------------
# ReadFileTool
# ---------------------------------------------------------------------------