Skip to content

Commit d46be2c

Browse files
committed
fix: shell and filesystem logic to support Windows paths
1 parent 9460efd commit d46be2c

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

allos/utils/file_utils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def is_safe_path(base_dir: Path, target_path: Path) -> bool:
2929
resolved_target = target_path.resolve(strict=True)
3030
# Check if the resolved target path is a subpath of the resolved base path
3131
return resolved_target.is_relative_to(resolved_base)
32-
except (FileNotFoundError, RuntimeError):
32+
except (FileNotFoundError, RuntimeError, OSError):
3333
# strict=True raises FileNotFoundError if path doesn't exist
3434
# is_relative_to can raise RuntimeError on Windows with different drives
3535
# In these cases, we can check the unresolved path as a fallback
@@ -154,9 +154,9 @@ def list_directory_recursive(
154154

155155
current_path = Path(root).relative_to(base_dir)
156156
for name in sorted(dirs):
157-
contents.append(f"{current_path / name}/")
157+
contents.append(f"{(current_path / name).as_posix()}/")
158158
for name in sorted(files):
159-
contents.append(str(current_path / name))
159+
contents.append(str((current_path / name).as_posix()))
160160
return contents
161161

162162

@@ -169,5 +169,8 @@ def list_directory_non_recursive(
169169
if not show_hidden and entry.name.startswith("."):
170170
continue
171171
relative_path = entry.relative_to(base_dir)
172-
contents.append(f"{relative_path}/" if entry.is_dir() else str(relative_path))
172+
if entry.is_dir():
173+
contents.append(f"{relative_path.as_posix()}/")
174+
else:
175+
contents.append(str(relative_path.as_posix()))
173176
return contents

tests/unit/tools/test_shell_tool.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# tests/unit/tools/test_shell_tool.py
22

3-
import platform
3+
import sys
44

55
import pytest
66

@@ -35,10 +35,11 @@ def test_execute_command_with_error(self):
3535

3636
def test_execute_timeout(self):
3737
"""Test that a long-running command is correctly timed out."""
38-
# Use a command that sleeps for longer than the timeout
39-
sleep_command = (
40-
"sleep 2" if platform.system() != "Windows" else "timeout /t 2 /nobreak"
41-
)
38+
# Use a reliable cross-platform way to create a long-running process.
39+
# This calls the current Python interpreter to run a short script that sleeps.
40+
python_executable = sys.executable
41+
sleep_command = f'"{python_executable}" -c "import time; time.sleep(2)"'
42+
4243
result = self.tool.execute(command=sleep_command, timeout=1)
4344

4445
assert result["status"] == "error"

0 commit comments

Comments
 (0)