review: tighten scope and add regression tests
Follow-ups from review of #3194: - ci.yml: drop unconditional --ignore=tests/channels/test_matrix_channel.py. That test file already calls pytest.importorskip("nio") at module top, so it self-skips on Windows (where nio isn't installed) without also hiding 62 tests from Linux CI. - filesystem.py: hoist `import os` to the module top and drop the duplicate inline import in ReadFileTool.execute. Document the CRLF->LF normalization as intentional (primarily a Windows UX fix so downstream StrReplace/Grep match consistently regardless of where the file was written). - test_read_enhancements.py: lock down two new behaviors * TestFileStateHashFallback: check_read warns when content changes but mtime is unchanged (coarse-mtime filesystems on Windows). * TestReadFileLineEndingNormalization: ReadFileTool strips CRLF and preserves LF-only files untouched. - test_tool_validation.py: restore list2cmdline/shlex.quote in test_exec_head_tail_truncation. The temp_path-based form was correct, but dropping the quoting broke on any Windows path containing spaces (e.g. C:\Users\John Doe\...). CI runners happen not to have spaces so this slipped through. Tests: 1993 passed locally. Made-with: Cursor
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
from typing import Any
|
||||
@@ -547,13 +548,20 @@ async def test_exec_always_returns_exit_code() -> 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 a temp script file to avoid Windows command line quote parsing issues
|
||||
# Generate output that exceeds _MAX_OUTPUT (10_000 chars).
|
||||
# Use a temp script file so the output-generating logic lives in a file
|
||||
# (Windows cmd.exe has finicky rules for quoting `-c` payloads with
|
||||
# embedded newlines). ExecTool runs via create_subprocess_shell, so we
|
||||
# must quote *both* the interpreter path and the script path — tmp_path
|
||||
# on some CI runners and on many local Windows installs contains spaces
|
||||
# (e.g. C:\Users\John Doe\AppData\...) which would otherwise break the
|
||||
# shell's argv split.
|
||||
script_file = tmp_path / "gen_output.py"
|
||||
script_file.write_text("print('A' * 6000 + chr(10) + 'B' * 6000)", encoding="utf-8")
|
||||
# On Windows, cmd.exe handles quotes differently. Use the path directly
|
||||
# without additional quotes since the temp path shouldn't have spaces.
|
||||
command = f"{sys.executable} {script_file}"
|
||||
if sys.platform == "win32":
|
||||
command = subprocess.list2cmdline([sys.executable, str(script_file)])
|
||||
else:
|
||||
command = f"{shlex.quote(sys.executable)} {shlex.quote(str(script_file))}"
|
||||
result = await tool.execute(command=command)
|
||||
assert "chars truncated" in result
|
||||
# Head portion should start with As
|
||||
|
||||
Reference in New Issue
Block a user