Skip to content

Commit 57756db

Browse files
committed
fix review comments
1 parent a9f86e4 commit 57756db

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

src/agents/sandbox/workspace_paths.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,6 @@ def relative_path(self, path: str | PurePath) -> Path:
137137
"""
138138

139139
if (windows_path := windows_absolute_path(path)) is not None:
140-
if self._root_is_existing_host_path:
141-
result, _grant = self._resolved_host_path_and_grant(Path(windows_path))
142-
host_relative = result.relative_to(self._root.resolve(strict=False))
143-
return host_relative if host_relative.parts else Path(".")
144140
raise self._invalid_path_error(windows_path)
145141
normalized = self._absolute_workspace_posix_path(coerce_posix_path(path))
146142
root = self._normalized_root()

tests/sandbox/test_workspace_paths.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,25 @@ def test_windows_drive_absolute_path_is_rejected_before_posix_coercion() -> None
303303
assert exc_info.value.context == {"rel": "C:/tmp/secret.txt", "reason": "absolute"}
304304

305305

306+
def test_relative_path_rejects_windows_drive_absolute_path_for_host_root(
307+
tmp_path: Path,
308+
) -> None:
309+
workspace = tmp_path / "workspace"
310+
workspace.mkdir()
311+
policy = WorkspacePathPolicy(root=workspace)
312+
313+
for path in (
314+
PureWindowsPath("C:/tmp/secret.txt"),
315+
"C:\\tmp\\secret.txt",
316+
coerce_posix_path(PureWindowsPath("C:/tmp/secret.txt")),
317+
):
318+
with pytest.raises(InvalidManifestPathError) as exc_info:
319+
policy.relative_path(path)
320+
321+
assert str(exc_info.value) == "manifest path must be relative: C:/tmp/secret.txt"
322+
assert exc_info.value.context == {"rel": "C:/tmp/secret.txt", "reason": "absolute"}
323+
324+
306325
def test_posix_path_as_path_returns_native_path() -> None:
307326
path = posix_path_as_path(PurePosixPath("/workspace/file.txt"))
308327

0 commit comments

Comments
 (0)