agentscope-ai / agentscope-ai/agentscope

[Bug]: test_read_nonexistent_file fails on Windows with Python 3.13+ (ntpath.isabs change)

Đã đóng
#2,604 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
31.6k
Fork
3.5k
Merge trung bình
1 ngày 16 giờ
Pull request đã merge (30 ngày)
103

Mô tả

- [x] I have searched the existing [issues](https://github.com/agentscope-ai/agentscope/issues) and [discussions](https://github.com/agentscope-ai/agentscope/discussions), and this is not a duplicate.
- [x] This is a bug, not a usage question. (For questions, please use [Discussions](https://github.com/agentscope-ai/agentscope/discussions/new?category=general) instead.)

### Background / Description

`tests/builtin_read_test.py::ReadToolTest::test_read_nonexistent_file` fails on **Windows with Python 3.13+**, but passes on Python 3.11 (which is what CI runs).

The test hardcodes a POSIX-style absolute path:

```python
chunk = await self.read_tool(file_path="/nonexistent/file.txt")
self.assertIn("does not exist", chunk.content[0].text)
```

This relied on `ntpath.isabs("/nonexistent/file.txt")` returning `True` on Windows. **CPython 3.13 intentionally changed that** — on Windows, `os.path.isabs()` now returns `False` for a path with exactly one leading (back)slash ([python/cpython#125283](https://github.com/python/cpython/issues/125283), [python-discuss thread](https://discuss.python.org/t/is-xyz-for-instance-os-path-isabs-behavior-change-intentional-answered/93814)).

So on 3.13 the call never reaches the "file does not exist" branch. It is rejected earlier by the absolute-path guard in `src/agentscope/tool/_builtin/_read.py` (line 274), and the assertion sees the wrong message.

Verified directly:

```
py 3.11.16 | ntpath.isabs('/nonexistent/file.txt') = True
py 3.13.15 | ntpath.isabs('/nonexistent/file.txt') = False
```

This is not only a test issue — it means the repo's declared support for Python 3.13+ on Windows is currently untested, because `unittest.yml` pins the matrix to `python-version: ['3.11']`. This test is just the first visible symptom.

### Error Messages

```
tests/builtin_read_test.py:184: in test_read_nonexistent_file
self.assertIn("does not exist", chunk.content[0].text)
E AssertionError: 'does not exist' not found in
'Error: file_path must be an absolute path, got: /nonexistent/file.txt'
```

### Steps to Reproduce

1. On Windows, create an environment with Python 3.13 and install AgentScope:

```bash
uv venv --python 3.13
uv pip install -e .
uv pip install pytest
```

2. Run the single test:

```bash
python -m pytest tests/builtin_read_test.py::ReadToolTest::test_read_nonexistent_file -q
```

3. Observe the failure above. The same command passes on Python 3.11.

For reference, the path decision inside the tool:

```python
# src/agentscope/tool/_builtin/_read.py:274
if not self._backend.isabs(file_path): # False on 3.13 -> takes this branch
return ToolChunk(content=[TextBlock(text="Error: file_path must be an absolute path, ...")], ...)

# src/agentscope/tool/_builtin/_read.py:287
if not await self._backend.file_exists(file_path): # never reached on 3.13
return ToolChunk(content=[TextBlock(text="Error: File does not exist: ...")], ...)
```

`LocalBackend` uses the host's path semantics (`_path_module = os.path`, `src/agentscope/tool/_builtin/_backend.py:758`), so the behaviour follows the host Python version.

### Proposed fix (happy to open a PR)

Make the test build a platform-independent, genuinely non-existent absolute path instead of hardcoding a POSIX one:

```python
async def test_read_nonexistent_file(self) -> None:
"""Test reading a non-existent file."""
missing = os.path.join(
tempfile.gettempdir(),
f"agentscope-no-such-dir-{uuid.uuid4().hex}",
"no-such-file.txt",
)
chunk = await self.read_tool(file_path=missing)

self.assertEqual(chunk.state, "error")
self.assertIn("does not exist", chunk.content[0].text)
```

I verified locally on Windows + Python 3.13.15 that this path satisfies `isabs() == True`, `is_dir() == False`, `file_exists() == False`, and therefore reaches the intended branch and produces `Error: File does not exist: ...`. It also works on POSIX. This keeps the test asserting the behaviour it was written to assert (the existence check), rather than accidentally depending on how the host parses a leading slash.

Separately — and I can raise this as its own issue/PR if you prefer — adding `3.13` to the `unittest.yml` matrix would catch this class of problem. I understand that is a bigger call than a one-line test fix, so I left it out of the proposal above.

### Environment

- AgentScope Version: 2.0.8
- Python Version: 3.13.15 (fails) / 3.11.16 (passes)
- OS: Windows 11

> Note: the rest of the suite is not run here; I narrowed this down while setting up a local dev environment. If you'd like, I can also report which other tests are Python-3.13-sensitive on Windows once I have the full matrix result.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Start with tests/builtin_read_test.py::ReadToolTest::test_read_nonexistent_file and reproduce with python -m pytest tests/builtin_read_test.py::ReadToolTest::test_read_nonexistent_file -q on Windows Python 3.13. The related path handling is noted in src/agentscope/tool/_builtin/_read.py and _backend.py. Done means the test uses a platform-independent nonexistent absolute path and passes on Python 3.13, but the issue is already closed.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
testing
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.