mirror of
https://github.com/hanzoai/python-sdk.git
synced 2026-10-23 20:23:00 +00:00
Filesystem Tool Tests
This directory contains tests for the filesystem tools in the Hanzo MCP project.
Test Files
test_fs_tools.py: Tests for the refactored filesystem toolstest_file_operations.py: Tests for various file operationstest_write_file.py: Comprehensive tests for the write file tool
Write File Tool Testing
The test_write_file.py file contains comprehensive tests for the write file tool, including:
Success Cases
- Writing files with standard content
- Creating nested directories
- Writing files with Unicode content
- Overwriting existing files
- Writing large files
Error Cases
- Missing path parameter
- Empty path parameter
- Missing content parameter
- Path not allowed
- Parent directory not allowed
- Write permission issues
- Encoding errors
- I/O errors
Running Tests
To run all filesystem tests:
make test TEST_DIR=tests/test_filesystem
To run a specific test file:
make test TEST_DIR=tests/test_filesystem/test_write_file.py
Adding New Tests
When adding new tests for filesystem tools, follow these guidelines:
- Use appropriate fixtures for setup and teardown
- Mock external dependencies and tool context
- Test both success and error paths
- Verify file content and filesystem state after operations
- Clean up temporary files after tests
- Add tests for various edge cases (permissions, encoding, large files, etc.)
Error Handling
The write_file tool has been enhanced with improved error handling:
- Error categorization: Different types of errors are caught and handled appropriately
- Detailed error messages: Error messages include specific information about what went wrong
- Logging: All errors are logged with appropriate severity levels
- Error propagation: Errors are properly returned to the client
Debug Logging
To enable debug logging during tests:
make test TEST_DIR=tests/test_filesystem LOG_LEVEL=DEBUG
This will provide detailed logs of the test execution, including input parameters, error conditions, and results.