fix(tests): stop hardcoding C: in the Windows file-URI migration tests (#6541)

The two Windows-only cases in tests/test_mcp_file_migration.py asserted a
literal "file:///C:/" / "file://C:" prefix on a path built from the pytest
temp dir. On a host whose checkout or temp dir lives on another drive both
assertions fail, so the only coverage of the drive-qualified file-URI forms
handled by _local_uri_to_virtual_path and _rewrite_local_paths_in_text never
ran there.

Derive the expected drive from the fixture path instead. The URI forms under
test are unchanged, so coverage holds on any drive.

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
This commit is contained in:
Jason Cat 2026-10-09 17:08:56 +08:00 committed by GitHub
parent 43d93ce0b7
commit 19befe76a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -143,7 +143,9 @@ class TestLocalUriToVirtualPath:
@pytest.mark.skipif(os.name != "nt", reason="exercises the file:///C:/... drive-qualified URI form")
def test_windows_file_uri_translates_to_virtual_path(self, paths: Paths):
src = _workspace_file(paths, "shot.png")
assert src.as_uri().startswith("file:///C:/")
# The checkout and temp dirs may live on any drive, so derive the
# expected drive instead of hardcoding "C:".
assert src.as_uri().startswith(f"file:///{src.drive}/")
with _patch_paths(paths):
result = mcp_tools._local_uri_to_virtual_path(src.as_uri(), thread_id="t1", user_id="u1")
@ -372,7 +374,7 @@ class TestRewriteLocalPathsInText:
def test_windows_two_slash_file_uri_in_text_is_rewritten(self, paths: Paths):
src = _workspace_file(paths, "shot.png")
two_slash_uri = src.as_uri().replace("file:///", "file://", 1)
assert two_slash_uri.startswith("file://C:")
assert two_slash_uri.startswith(f"file://{src.drive}")
with _patch_paths(paths):
result = mcp_tools._rewrite_local_paths_in_text(f"Saved as {two_slash_uri}", thread_id="t1", user_id="u1")