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: 4 additions & 0 deletions mcp_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def shrink_media(source_path: str, output_dir: str, target_bytes: int = 2_000_00

if not source.exists():
return f"Error: Source file does not exist: {source}"
if not source.is_file():
return f"Error: Source path is not a file: {source}"
if target_bytes <= 0:
return "Error: target_bytes must be greater than 0."

out_dir.mkdir(parents=True, exist_ok=True)
root = source.parent
Expand Down
18 changes: 18 additions & 0 deletions tests/test_mcp_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,21 @@ def test_shrink_media_handles_empty_result(self, mock_convert_file):

if __name__ == '__main__':
unittest.main()


class MCPDriverValidationTests(unittest.TestCase):
"""Trust-boundary input validation for the MCP shrink_media tool."""

def test_rejects_directory_source(self):
import tempfile
with tempfile.TemporaryDirectory() as temp_dir:
result = shrink_media(temp_dir, temp_dir + "/out")
self.assertIn("is not a file", result)

def test_rejects_nonpositive_target_bytes(self):
import tempfile
with tempfile.TemporaryDirectory() as temp_dir:
source = Path(temp_dir) / "s.wav"
source.touch()
result = shrink_media(str(source), str(Path(temp_dir) / "out"), 0)
self.assertIn("target_bytes must be greater than 0", result)
Loading