test: cover POSIX file URI root preservation#8906
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds a new test to verify that POSIX absolute file URI roots are preserved for container paths. The review feedback correctly identifies that this test will fail on Windows environments due to platform-specific path separators and suggests guarding the test with an OS check to ensure cross-platform compatibility.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| def test_file_uri_to_path_preserves_posix_root_for_container_paths(): | ||
| assert media_utils.file_uri_to_path("file:///AstrBot/data/cache/image.png") == ( | ||
| "/AstrBot/data/cache/image.png" | ||
| ) |
There was a problem hiding this comment.
The test asserts a hardcoded POSIX-style path (/AstrBot/data/cache/image.png), which will fail on Windows because file_uri_to_path normalizes paths using platform-specific separators (backslashes on Windows). Since this test is specifically designed to verify POSIX absolute file URI root preservation, it should be guarded with if os.name != 'nt': to ensure cross-platform compatibility, consistent with other tests in this file.
| def test_file_uri_to_path_preserves_posix_root_for_container_paths(): | |
| assert media_utils.file_uri_to_path("file:///AstrBot/data/cache/image.png") == ( | |
| "/AstrBot/data/cache/image.png" | |
| ) | |
| def test_file_uri_to_path_preserves_posix_root_for_container_paths(): | |
| if os.name != "nt": | |
| assert media_utils.file_uri_to_path("file:///AstrBot/data/cache/image.png") == ( | |
| "/AstrBot/data/cache/image.png" | |
| ) |
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/test_media_utils.py" line_range="449-452" />
<code_context>
assert media_utils.file_uri_to_path(legacy_file_uri) == str(media_path)
+def test_file_uri_to_path_preserves_posix_root_for_container_paths():
+ assert media_utils.file_uri_to_path("file:///AstrBot/data/cache/image.png") == (
+ "/AstrBot/data/cache/image.png"
</code_context>
<issue_to_address>
**suggestion (testing):** Add coverage for the bare root and directory-only POSIX file URIs, not just a full file path.
To strengthen the root-preservation guarantee, please extend this test (via parametrization or additional asserts) to also cover:
- `file:///AstrBot` → `/AstrBot`
- `file:///AstrBot/` → `/AstrBot/`
- `file:///` → `/`
This will ensure minimal and directory-only URIs keep their leading slash as expected.
```suggestion
def test_file_uri_to_path_preserves_posix_root_for_container_paths():
# full file path under container-style root
assert media_utils.file_uri_to_path("file:///AstrBot/data/cache/image.png") == (
"/AstrBot/data/cache/image.png"
)
# bare container root
assert media_utils.file_uri_to_path("file:///AstrBot") == "/AstrBot"
# directory-only URI (trailing slash preserved)
assert media_utils.file_uri_to_path("file:///AstrBot/") == "/AstrBot/"
# bare POSIX root
assert media_utils.file_uri_to_path("file:///") == "/"
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| def test_file_uri_to_path_preserves_posix_root_for_container_paths(): | ||
| assert media_utils.file_uri_to_path("file:///AstrBot/data/cache/image.png") == ( | ||
| "/AstrBot/data/cache/image.png" | ||
| ) |
There was a problem hiding this comment.
suggestion (testing): Add coverage for the bare root and directory-only POSIX file URIs, not just a full file path.
To strengthen the root-preservation guarantee, please extend this test (via parametrization or additional asserts) to also cover:
file:///AstrBot→/AstrBotfile:///AstrBot/→/AstrBot/file:///→/
This will ensure minimal and directory-only URIs keep their leading slash as expected.
| def test_file_uri_to_path_preserves_posix_root_for_container_paths(): | |
| assert media_utils.file_uri_to_path("file:///AstrBot/data/cache/image.png") == ( | |
| "/AstrBot/data/cache/image.png" | |
| ) | |
| def test_file_uri_to_path_preserves_posix_root_for_container_paths(): | |
| # full file path under container-style root | |
| assert media_utils.file_uri_to_path("file:///AstrBot/data/cache/image.png") == ( | |
| "/AstrBot/data/cache/image.png" | |
| ) | |
| # bare container root | |
| assert media_utils.file_uri_to_path("file:///AstrBot") == "/AstrBot" | |
| # directory-only URI (trailing slash preserved) | |
| assert media_utils.file_uri_to_path("file:///AstrBot/") == "/AstrBot/" | |
| # bare POSIX root | |
| assert media_utils.file_uri_to_path("file:///") == "/" |
Summary
Adds a regression test for POSIX absolute file URIs such as
file:///AstrBot/data/cache/image.png.This guards against accidentally dropping the root slash when normalizing local file URIs, which would turn
/AstrBot/...into the relative pathAstrBot/...in container deployments.Testing
uv run pytest tests/test_media_utils.py -k "file_uri_to_path"