AstrBot icon indicating copy to clipboard operation
AstrBot copied to clipboard

[Bug] test: Fix 3 CRLF line-ending test failures in test_computer_fs_tools.py on Windows

Open Dr1985 opened this issue 5 months ago • 2 comments

What happened / 发生了什么

Description

When running uv run pytest tests/test_computer_fs_tools.py on Windows, 3 tests fail due to \r\n (CRLF) vs \n (LF) line-ending mismatches. Windows uses CRLF by default for text file writes, but the test assertions expect LF-only output.

Environment

  • OS: Windows 11 Pro
  • Python: 3.13.7
  • pytest: 9.0.3
  • pytest-asyncio: 1.4.0

Failing Tests (3/14)

tests/test_computer_fs_tools.py::test_restricted_local_member_can_read_plugin_provided_skill FAILED
tests/test_computer_fs_tools.py::test_restricted_local_member_can_read_plugin_skill_inventory_even_if_plugin_inactive FAILED
tests/test_computer_fs_tools.py::test_file_read_tool_allows_partial_read_for_large_text_file FAILED
=================== 3 failed, 11 passed, 1 warning in 5.21s ===================

Detailed Errors

1. test_restricted_local_member_can_read_plugin_provided_skill

>       assert result == "# Demo Skill\n\nRead plugin docs."
E       AssertionError: assert '# Demo Skill... plugin docs.' == '# Demo Skill... plugin docs.'
E         
E         - # Demo Skill
E         + # Demo Skill
E         ?             +
E         - 
E         + 
E           Read plugin docs.

Root cause: FileReadTool().call() returns text with \r\n when reading a file written by write_text() on Windows, but the test expects \n only.

2. test_restricted_local_member_can_read_plugin_skill_inventory_even_if_plugin_inactive

>       assert result == "# Demo Skill\n"
E       AssertionError: assert '# Demo Skill\r\n' == '# Demo Skill\n'
E         
E         - # Demo Skill
E         + # Demo Skill
E         ?             +

Root cause: Same as above — FileReadTool preserves the CRLF written by write_text() on Windows.

3. test_file_read_tool_allows_partial_read_for_large_text_file

>       assert result == "".join(lines[1000:1003])
E       AssertionError: assert 'line-01000\r...ine-01002\r\n' == 'line-01000\n...nline-01002\n'
E         
E         - line-01000
E         + line-01000
E         ?           +
E         - line-01001
E         + line-01001
E         ?           +
E         - line-01002
E         + line-01002
E         ?           +

The test constructs lines with \n:

lines = [f"line-{index:05d}\n" for index in range(50000)]
large_file.write_text("".join(lines), encoding="utf-8")

On Windows, Path.write_text() converts \n to \r\n, and FileReadTool returns the raw content without normalizing line endings.

Suggested Fixes

Option A — Fix in source code

Normalize line endings in FileReadTool by applying .replace("\r\n", "\n") on text read results. This makes the tool behavior consistent across platforms and fixes all 3 tests.

Option B — Fix in tests

Apply .replace("\r\n", "\n") on the result before asserting, e.g.:

assert result.replace("\r\n", "\n") == "# Demo Skill\n\nRead plugin docs."

Option C — Fix file writes in tests

Use newline="\n" when writing test files, or write bytes directly to avoid the platform line-ending conversion:

plugin_skill.write_text("# Demo Skill\n\nRead plugin docs.", encoding="utf-8", newline="\n")

Related

  • PR [#8562](https://github.com/AstrBotDevs/AstrBot/pull/8562) also addresses Windows test compatibility and uses a similar .replace("\r\n", "\n") approach in test_computer.py.

Reproduce / 如何复现?

When running uv run pytest tests/test_computer_fs_tools.py on Windows, 3 tests fail due to \r\n (CRLF) vs \n (LF) line-ending mismatches. Windows uses CRLF by default for text file writes, but the test assertions expect LF-only output.

Environment

  • OS: Windows 11 Pro
  • Python: 3.13.7
  • pytest: 9.0.3
  • pytest-asyncio: 1.4.0

Failing Tests (3/14)

tests/test_computer_fs_tools.py::test_restricted_local_member_can_read_plugin_provided_skill FAILED
tests/test_computer_fs_tools.py::test_restricted_local_member_can_read_plugin_skill_inventory_even_if_plugin_inactive FAILED
tests/test_computer_fs_tools.py::test_file_read_tool_allows_partial_read_for_large_text_file FAILED
=================== 3 failed, 11 passed, 1 warning in 5.21s ===================

Detailed Errors

1. test_restricted_local_member_can_read_plugin_provided_skill

>       assert result == "# Demo Skill\n\nRead plugin docs."
E       AssertionError: assert '# Demo Skill... plugin docs.' == '# Demo Skill... plugin docs.'
E         
E         - # Demo Skill
E         + # Demo Skill
E         ?             +
E         - 
E         + 
E           Read plugin docs.

Root cause: FileReadTool().call() returns text with \r\n when reading a file written by write_text() on Windows, but the test expects \n only.

2. test_restricted_local_member_can_read_plugin_skill_inventory_even_if_plugin_inactive

>       assert result == "# Demo Skill\n"
E       AssertionError: assert '# Demo Skill\r\n' == '# Demo Skill\n'
E         
E         - # Demo Skill
E         + # Demo Skill
E         ?             +

Root cause: Same as above — FileReadTool preserves the CRLF written by write_text() on Windows.

3. test_file_read_tool_allows_partial_read_for_large_text_file

>       assert result == "".join(lines[1000:1003])
E       AssertionError: assert 'line-01000\r...ine-01002\r\n' == 'line-01000\n...nline-01002\n'
E         
E         - line-01000
E         + line-01000
E         ?           +
E         - line-01001
E         + line-01001
E         ?           +
E         - line-01002
E         + line-01002
E         ?           +

AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器

AstrBot version : v4.26.0-beta.2
Deployment method : pip install -e . (editable install from source) Provider used : N/A — running pytest only, no LLM provider configured
Messaging platform used : N/A — running pytest only, no platform adapter configured

OS

Windows

Logs / 报错日志

============================= test session starts ============================= platform win32 -- Python 3.13.7, pytest-9.0.3, pluggy-1.6.0 rootdir: D:\Github Folder\AstrBot configfile: pyproject.toml plugins: anyio-4.9.0, asyncio-1.4.0, cov-7.1.0 asyncio: mode=Mode.STRICT, debug=False collecting ... collected 14 items

tests/test_computer_fs_tools.py::test_restricted_local_member_can_read_plugin_provided_skill FAILED [ 7%] tests/test_computer_fs_tools.py::test_restricted_local_member_can_read_plugin_skill_inventory_even_if_plugin_inactive FAILED [ 14%] tests/test_computer_fs_tools.py::test_restricted_local_member_cannot_write_plugin_provided_skill PASSED [ 21%] tests/test_computer_fs_tools.py::test_detect_text_encoding_allows_utf8_probe_cut_mid_character PASSED [ 28%] tests/test_computer_fs_tools.py::test_file_read_tool_rejects_large_full_text_read_before_local_stream_read PASSED [ 35%] tests/test_computer_fs_tools.py::test_file_read_tool_allows_partial_read_for_large_text_file FAILED [ 42%] tests/test_computer_fs_tools.py::test_file_read_tool_returns_image_call_tool_result_for_images PASSED [ 50%] tests/test_computer_fs_tools.py::test_file_read_tool_treats_svg_as_text PASSED [ 57%] tests/test_computer_fs_tools.py::test_file_read_tool_reads_pdf_via_parser PASSED [ 64%] tests/test_computer_fs_tools.py::test_file_read_tool_reads_docx_via_parser_and_magic PASSED [ 71%] tests/test_computer_fs_tools.py::test_is_epub_bytes_rejects_plain_zip_archive PASSED [ 78%] tests/test_computer_fs_tools.py::test_file_read_tool_reads_epub_via_parser_and_magic PASSED [ 85%] tests/test_computer_fs_tools.py::test_file_read_tool_stores_long_converted_document_in_workspace PASSED [ 92%] tests/test_computer_fs_tools.py::test_grep_tool_applies_result_limit PASSED [100%]

================================== FAILURES =================================== _________ test_restricted_local_member_can_read_plugin_provided_skill _________

  @pytest.mark.asyncio
  async def test_restricted_local_member_can_read_plugin_provided_skill(
      monkeypatch: pytest.MonkeyPatch,
      tmp_path,
  ):
      _setup_local_fs_tools(monkeypatch, tmp_path)
      plugin_skill = (
          tmp_path / "plugins" / "astrbot_plugin_demo"
          / "skills" / "demo-skill" / "SKILL.md"
      )
      plugin_skill.parent.mkdir(parents=True)
      plugin_skill.write_text("# Demo Skill\n\nRead plugin docs.", encoding="utf-8")

      result = await fs_tools.FileReadTool().call(
          _make_context(role="member"),
          path=str(plugin_skill),
      )
  assert result == "# Demo Skill\n\nRead plugin docs."

E AssertionError: assert '# Demo Skill... plugin docs.' == '# Demo Skill... plugin docs.' E - # Demo Skill E + # Demo Skill E ? + E - E + E Read plugin docs.

tests\test_computer_fs_tools.py:215: AssertionError

_ test_restricted_local_member_can_read_plugin_skill_inventory_even_if_plugin_inactive _

  @pytest.mark.asyncio
  async def test_restricted_local_member_can_read_plugin_skill_inventory_even_if_plugin_inactive(
      monkeypatch: pytest.MonkeyPatch,
      tmp_path,
  ):
      _setup_local_fs_tools(monkeypatch, tmp_path)
      plugin_skill = (
          tmp_path / "plugins" / "astrbot_plugin_demo"
          / "skills" / "demo-skill" / "SKILL.md"
      )
      plugin_skill.parent.mkdir(parents=True)
      plugin_skill.write_text("# Demo Skill\n", encoding="utf-8")

      result = await fs_tools.FileReadTool().call(
          _make_context(role="member"),
          path=str(plugin_skill),
      )
  assert result == "# Demo Skill\n"

E AssertionError: assert '# Demo Skill\r\n' == '# Demo Skill\n' E - # Demo Skill E + # Demo Skill E ? +

tests\test_computer_fs_tools.py:240: AssertionError

_________ test_file_read_tool_allows_partial_read_for_large_text_file _________

  @pytest.mark.asyncio
  async def test_file_read_tool_allows_partial_read_for_large_text_file(
      monkeypatch: pytest.MonkeyPatch,
      tmp_path,
  ):
      workspace = _setup_local_fs_tools(monkeypatch, tmp_path)
      large_file = workspace / "large.txt"
      lines = [f"line-{index:05d}\n" for index in range(50000)]
      large_file.write_text("".join(lines), encoding="utf-8")

      result = await fs_tools.FileReadTool().call(
          _make_context(),
          path="large.txt",
          offset=1000,
          limit=3,
      )
  assert result == "".join(lines[1000:1003])

E AssertionError: assert 'line-01000\r...ine-01002\r\n' == 'line-01000\n...nline-01002\n' E - line-01000 E + line-01000 E ? + E - line-01001 E + line-01001 E ? + E - line-01002 E + line-01002 E ? +

tests\test_computer_fs_tools.py:317: AssertionError

=========================== short test summary info =========================== FAILED tests/test_computer_fs_tools.py::test_restricted_local_member_can_read_plugin_provided_skill FAILED tests/test_computer_fs_tools.py::test_restricted_local_member_can_read_plugin_skill_inventory_even_if_plugin_inactive FAILED tests/test_computer_fs_tools.py::test_file_read_tool_allows_partial_read_for_large_text_file =================== 3 failed, 11 passed, 1 warning in 5.40s ===================

Are you willing to submit a PR? / 你愿意提交 PR 吗?

  • [x] Yes!

Code of Conduct

Dr1985 avatar Jun 16 '26 06:06 Dr1985

This is a duplicate of the still-open PR #8562, which addresses exactly these 3 CRLF test failures in test_computer_fs_tools.py using Option B (.replace("\r\n", "\n") on test assertions) [1]. That PR also fixes additional Windows compatibility issues (file URI paths, sandbox path formatting, skill manager commands, and pip-related tests).

Since you've indicated willingness to submit a PR, you may want to coordinate with or build upon PR #8562 to avoid duplicating effort.

To reply, just mention @dosu.


Docs are dead. Just use Dosu.

Leave Feedback Ask Dosu about AstrBot Share Dosu with your team

dosubot[bot] avatar Jun 16 '26 06:06 dosubot[bot]

OK,I see. Thank you for the information on the still-open https://github.com/AstrBotDevs/AstrBot/pull/8562. I will try to fix it.

Dr1985 avatar Jun 16 '26 07:06 Dr1985