Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/test_media_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,12 @@ def test_file_uri_to_path_supports_standard_and_legacy_posix_file_uris(tmp_path)
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"
)
Comment on lines +449 to +452

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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"
)

Comment on lines +449 to +452

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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:///") == "/"



def test_from_file_system_uses_pathlib_file_uri(tmp_path):
media_path = tmp_path / "media file.bin"
media_path.write_bytes(b"media")
Expand Down