Commit 0a66ac718 for llama.cpp
commit 0a66ac7189a6f25f3c4760bf1bec620ed537f4bb
Author: Pascal <admin@serveurperso.com>
Date: Thu Nov 12 23:47:14 2026 +0100
server, fix CI: read a small temp file in the read_file tool test [no release] (#32168)
* server: read a small temp file in the read_file tool test
test_tools_builtin_read_file read its own file, which grows with every
added test. On Windows the CRLF checkout puts it at 16664 bytes, over
the 16384 byte read limit, and the tool refuses it.
The test now writes a small file of its own and checks the exact
content read back.
* server: use a temp cwd in the x-tool-cwd tool test
test_tools_builtin_cwd_header read test_tools_builtin.py through the
x-tool-cwd header, which hits the same 16384 byte read limit on the
Windows CRLF checkout, and wrote its shell marker into the source tree.
The test now uses a temp directory as cwd, reads a small file from it
and checks the shell marker lands there.
diff --git a/tools/server/tests/unit/test_tools_builtin.py b/tools/server/tests/unit/test_tools_builtin.py
index b3af73604..b6673a089 100755
--- a/tools/server/tests/unit/test_tools_builtin.py
+++ b/tools/server/tests/unit/test_tools_builtin.py
@@ -53,15 +53,16 @@ def test_tools_builtin_grep_search():
assert "Total matches: 1" in text
-def test_tools_builtin_read_file():
+def test_tools_builtin_read_file(tmp_path):
global server
server.start()
- this_file = os.path.join(PROJECT_ROOT, "tools", "server", "tests", "unit", "test_tools_builtin.py")
- res = call_tool("read_file", {"path": this_file})
- text = res["plain_text_response"]
- assert GREP_MARKER in text
- assert "def test_tools_builtin_read_file" in text
+ # a file of its own keeps the test below the read limit, unlike this file which grows with every test
+ path = str(tmp_path / "read.txt")
+ with open(path, "w", newline="\n") as f:
+ f.write("line1\nline2\nline3\n")
+ res = call_tool("read_file", {"path": path})
+ assert res["plain_text_response"] == "line1\nline2\nline3\n"
def test_tools_builtin_write_then_edit_file(tmp_path):
@@ -128,27 +129,21 @@ def test_tools_builtin_exec_shell_command_stream():
assert "[exit code: 0]" in chunks
-def test_tools_builtin_cwd_header():
+def test_tools_builtin_cwd_header(tmp_path):
global server
server.start()
- cwd_dir = os.path.join(PROJECT_ROOT, "tools", "server", "tests", "unit")
- headers = {"x-tool-cwd": cwd_dir}
+ headers = {"x-tool-cwd": str(tmp_path)}
- res = call_tool("read_file", {"path": "test_tools_builtin.py"}, headers=headers)
- assert GREP_MARKER in res["plain_text_response"]
+ (tmp_path / "cwd.txt").write_text("cwd-content")
+ res = call_tool("read_file", {"path": "cwd.txt"}, headers=headers)
+ assert "cwd-content" in res["plain_text_response"]
# exec_shell_command should also run with that directory as its working directory:
- # writing to a relative filename must land inside cwd_dir
+ # writing to a relative filename must land inside it
marker_name = "llama_cpp_test_tools_builtin_cwd_marker.txt"
- marker_path = os.path.join(cwd_dir, marker_name)
- try:
- command = f"echo hello > {marker_name}"
- call_tool("exec_shell_command", {"command": command}, headers=headers)
- assert os.path.exists(marker_path)
- finally:
- if os.path.exists(marker_path):
- os.remove(marker_path)
+ call_tool("exec_shell_command", {"command": f"echo hello > {marker_name}"}, headers=headers)
+ assert (tmp_path / marker_name).exists()
def _container_engine_unavailable_reason(engine: str) -> str | None: