Skip to content

test: cover POSIX file URI root preservation#8906

Open
casama233 wants to merge 1 commit into
AstrBotDevs:masterfrom
casama233:fix/file-uri-posix-root-regression
Open

test: cover POSIX file URI root preservation#8906
casama233 wants to merge 1 commit into
AstrBotDevs:masterfrom
casama233:fix/file-uri-posix-root-regression

Conversation

@casama233

@casama233 casama233 commented Jun 19, 2026

Copy link
Copy Markdown

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 path AstrBot/... in container deployments.

Testing

  • uv run pytest tests/test_media_utils.py -k "file_uri_to_path"

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. area:core The bug / feature is about astrbot's core, backend labels Jun 19, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

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.

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.

Comment thread tests/test_media_utils.py
Comment on lines +449 to +452
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"
)

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

@sourcery-ai sourcery-ai Bot left a comment

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.

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread tests/test_media_utils.py
Comment on lines +449 to +452
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"
)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant