agentscope-ai / agentscope-ai/agentscope
[Bug]: test_read_nonexistent_file fails on Windows with Python 3.13+ (ntpath.isabs change)
- Dominant language
- Python
- Stars
- 31.6k
- Forks
- 3.5k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 103
Description
- [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.
Contributor guide
Research direction
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.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100