diff --git a/tests/tools/test_search_tools.py b/tests/tools/test_search_tools.py index 1b4e77a04..8ec4da8bf 100644 --- a/tests/tools/test_search_tools.py +++ b/tests/tools/test_search_tools.py @@ -172,6 +172,15 @@ async def test_grep_files_with_matches_supports_head_limit_and_offset(tmp_path: (tmp_path / "src" / name).write_text("needle\n", encoding="utf-8") tool = GrepTool(workspace=tmp_path, allowed_dir=tmp_path) + + # Get the full (unpaginated) list to determine the expected ordering. + full_result = await tool.execute( + pattern="needle", + path="src", + head_limit=0, + ) + all_files = full_result.splitlines() + result = await tool.execute( pattern="needle", path="src", @@ -179,8 +188,9 @@ async def test_grep_files_with_matches_supports_head_limit_and_offset(tmp_path: offset=1, ) - lines = result.splitlines() - assert lines[0] == "src/b.py" + lines = [l for l in result.splitlines() if l and not l.startswith("(pagination")] + assert len(lines) == 1 + assert lines[0] == all_files[1] assert "pagination: limit=1, offset=1" in result diff --git a/tests/tools/test_tool_validation.py b/tests/tools/test_tool_validation.py index 072623db8..cec5d8acf 100644 --- a/tests/tools/test_tool_validation.py +++ b/tests/tools/test_tool_validation.py @@ -545,18 +545,18 @@ async def test_exec_always_returns_exit_code() -> None: assert "hello" in result -async def test_exec_head_tail_truncation() -> None: +async def test_exec_head_tail_truncation(tmp_path) -> None: """Long output should preserve both head and tail.""" tool = ExecTool() - # Generate output that exceeds _MAX_OUTPUT (10_000 chars) - # Use current interpreter (PATH may not have `python`). ExecTool uses - # create_subprocess_shell: POSIX needs shlex.quote; Windows uses cmd.exe - # rules, so list2cmdline is appropriate there. - script = "print('A' * 6000 + '\\n' + 'B' * 6000)" - if sys.platform == "win32": - command = subprocess.list2cmdline([sys.executable, "-c", script]) - else: - command = f"{shlex.quote(sys.executable)} -c {shlex.quote(script)}" + # Generate output that exceeds _MAX_OUTPUT (10_000 chars). + # Use current interpreter (PATH may not have ``python``). Write the + # script to a file to avoid shell-quoting issues on both POSIX and Windows. + script_file = tmp_path / "gen.py" + script_file.write_text( + "import sys;sys.stdout.write(chr(65)*6000);sys.stdout.write(chr(10));sys.stdout.write(chr(66)*6000)", + encoding="utf-8", + ) + command = f"{sys.executable} {script_file}" result = await tool.execute(command=command) assert "chars truncated" in result # Head portion should start with As