ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
#!/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()
|
||||
Reference in New Issue
Block a user