#!/usr/bin/env python3 """Offline regressions for local tool error handling.""" from agent import LocalFileTools def test_error_handling(): """Test that local tools return structured errors instead of raising.""" print("๐Ÿงช Testing Error Handling in Tool Execution") print("="*60) # Test local tools directly first print("\n1๏ธโƒฃ Testing direct tool error handling:") tools = LocalFileTools(root_dir="../..") # Test with invalid arguments print(" Testing read_file with extra 'limit' parameter...") # The tool should ignore the extra parameter result = tools.read_file("chapter1/context/README.md") print(f" Result: {'โœ“ Success' if result.get('success') else 'โœ— Error'}") assert result.get("success") is True # Test with non-existent file print(" Testing read_file with non-existent file...") result = tools.read_file("non_existent_file.txt") print(f" Result: {'โœ“ Error handled' if not result.get('success') else 'โœ— Unexpected success'}") print(f" Error message: {result.get('error', 'N/A')}") assert result.get("success") is False assert "File not found" in result.get("error", "") # Test security boundary print(" Testing security boundary...") result = tools.read_file("../../../../etc/passwd") print(f" Result: {'โœ“ Access denied' if 'Access denied' in result.get('error', '') else 'โœ— Security issue'}") assert result.get("success") is False assert "Access denied" in result.get("error", "") print("\n" + "="*60) print("โœ… Error handling test complete!") print("\nKey findings:") print(" โ€ข Tools return errors as results instead of throwing exceptions") print(" โ€ข Unexpected arguments are filtered out safely") print(" โ€ข Security boundaries are enforced") if __name__ == "__main__": test_error_handling()