Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions minimax_mcp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@
def is_file_writeable(path: Path) -> bool:
if path.exists():
return os.access(path, os.W_OK)
parent_dir = path.parent
return os.access(parent_dir, os.W_OK)
# The path does not exist yet. Callers create it with
# ``mkdir(parents=True)``, which may create several missing levels, so
# check writeability of the nearest existing ancestor rather than only the
# immediate parent (which is itself missing for a multi-level new path).
for ancestor in path.parents:
if ancestor.exists():
return os.access(ancestor, os.W_OK)
return False


def build_output_file(
Expand Down
14 changes: 14 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ def test_is_file_writeable():
temp_path = Path(temp_dir)
assert is_file_writeable(temp_path) is True
assert is_file_writeable(temp_path / "nonexistent.txt") is True
# Multi-level new path: the immediate parent does not exist yet, but
# mkdir(parents=True) can create it, so it must be reported writeable
# (regression: only the immediate parent used to be checked).
Comment on lines +19 to +21
assert is_file_writeable(temp_path / "a" / "b" / "c") is True


def test_build_output_path_creates_nested_dir():
# A nested, not-yet-existing output directory must be created rather than
# rejected as "not writeable".
Comment on lines +26 to +27
with tempfile.TemporaryDirectory() as temp_dir:
result = build_output_path("a/b/c", temp_dir)
assert result == Path(temp_dir) / "a" / "b" / "c"
assert result.exists()
assert result.is_dir()


def test_make_output_file():
Expand Down