Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion open_terminal/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,9 @@ async def view_file(
)
async def serve_file(path: str, fs: UserFS = Depends(get_filesystem)):
"""Path-based alias for view_file — enables relative URL resolution in iframes."""
return await view_file(path=f"/{path}", fs=fs)
if not (path.startswith("/") or (len(path) >= 2 and path[1] == ":")):
path = f"/{path}"
return await view_file(path=path, fs=fs)


@app.post(
Expand Down
2 changes: 1 addition & 1 deletion open_terminal/utils/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def _is_writable_sync(self, path: str) -> bool:
pass
try:
return os.access(path, os.W_OK, effective_ids=True)
except TypeError:
except (TypeError, NotImplementedError):
return os.access(path, os.W_OK)

async def is_writable(self, path: str) -> bool:
Expand Down
29 changes: 29 additions & 0 deletions tests/test_windows_compatibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os
from unittest.mock import AsyncMock, patch

import pytest

os.environ.setdefault("OPEN_TERMINAL_API_KEY", "test-key")

from open_terminal.main import serve_file
from open_terminal.utils.fs import UserFS


@pytest.mark.asyncio
async def test_serve_file_preserves_windows_drive_path():
filesystem = object()
with patch("open_terminal.main.view_file", new_callable=AsyncMock) as view_file:
await serve_file("C:/Users/test/index.html", filesystem)

view_file.assert_awaited_once_with(path="C:/Users/test/index.html", fs=filesystem)


def test_is_writable_falls_back_when_effective_ids_are_unsupported():
filesystem = UserFS(home="C:/Users/test")
path = "C:/Users/test"

with patch.object(os, "access", side_effect=[NotImplementedError, True]) as access:
assert filesystem._is_writable_sync(path) is True

assert access.call_count == 2
assert access.call_args_list[1].kwargs == {}