Files

256 lines
7.2 KiB
Python

#!/usr/bin/env python3
"""Simple test script for core Hanzo AI functionality."""
import asyncio
import os
import tempfile
from pathlib import Path
def test_imports():
"""Test that core modules can be imported."""
print("๐Ÿงช Testing Core Imports\n")
try:
print("โœ… Permission manager imported")
print("โœ… Read tool imported")
print("โœ… Diff tool imported")
print("โœ… Context normalization imported")
print("โœ… Enhanced server imported")
return True
except Exception as e:
print(f"โŒ Import failed: {e}")
return False
async def test_file_operations():
"""Test file operations."""
print("\n๐Ÿ“ Testing File Operations\n")
try:
from hanzo_tools.filesystem.diff import create_diff_tool
from hanzo_tools.filesystem.read import ReadTool
from hanzo_mcp.tools.common.permissions import PermissionManager
# Create temp files
with tempfile.TemporaryDirectory() as temp_dir:
temp_path = Path(temp_dir)
# Set up permission manager
pm = PermissionManager()
pm.add_allowed_path(temp_dir)
# Create test files
file1 = temp_path / "test1.txt"
file2 = temp_path / "test2.txt"
file1.write_text("Hello\nWorld\nFrom\nHanzo")
file2.write_text("Hello\nUniverse\nFrom\nHanzo\nMCP")
print(f"๐Ÿ“ Created test files in: {temp_path}")
# Test read tool
read_tool = ReadTool(pm)
class MockContext:
pass
ctx = MockContext()
content = await read_tool.run(ctx, str(file1))
print(f"โœ… Read tool: got {len(content)} characters")
# Test diff tool
diff_tool = create_diff_tool(pm)
diff_result = await diff_tool.run(ctx, str(file1), str(file2))
print("โœ… Diff tool: found differences")
# Show summary line
lines = diff_result.split("\n")
summary_line = [line for line in lines if "Summary:" in line]
if summary_line:
print(f" {summary_line[0]}")
return True
except Exception as e:
print(f"โŒ File operations failed: {e}")
return False
def test_shell_detection():
"""Test shell detection."""
print("\n๐Ÿš Testing Shell Detection\n")
try:
# Test shell detection without creating the tool
import os
import platform
from pathlib import Path
if platform.system() == "Windows":
expected_shell = "cmd.exe"
else:
shell = os.environ.get("SHELL", "/bin/bash")
shell_name = os.path.basename(shell)
if shell_name == "zsh":
zshrc_path = Path.home() / ".zshrc"
if zshrc_path.exists():
expected_shell = shell
print(f"โœ… Found .zshrc at: {zshrc_path}")
else:
expected_shell = "bash"
else:
expected_shell = "bash"
print(f"โœ… Shell detection: {expected_shell}")
print(f"โœ… User's SHELL: {os.environ.get('SHELL', 'not set')}")
return True
except Exception as e:
print(f"โŒ Shell detection failed: {e}")
return False
def test_cloudflare_config():
"""Test Cloudflare configuration."""
print("\nโ˜๏ธ Testing Cloudflare Configuration\n")
# Check environment variables
cf_token = os.environ.get("CLOUDFLARE_API_TOKEN")
cf_account = os.environ.get("CLOUDFLARE_ACCOUNT_ID")
if cf_token:
print(f"โœ… CLOUDFLARE_API_TOKEN configured (ends with: ...{cf_token[-8:]})")
else:
print("โš ๏ธ CLOUDFLARE_API_TOKEN not found in environment")
if cf_account:
print(f"โœ… CLOUDFLARE_ACCOUNT_ID: {cf_account}")
else:
print("โš ๏ธ CLOUDFLARE_ACCOUNT_ID not found in environment")
# Check Claude Desktop config
claude_config = (
Path.home()
/ "Library"
/ "Application Support"
/ "Claude"
/ "claude_desktop_config.json"
)
if claude_config.exists():
print(f"โœ… Claude Desktop config found: {claude_config}")
try:
import json
with open(claude_config) as f:
config = json.load(f)
servers = config.get("mcpServers", {})
print(f"โœ… MCP servers configured: {list(servers.keys())}")
if "cloudflare-bindings" in servers:
print("โœ… Cloudflare Bindings server configured")
if "cloudflare-tunnels" in servers:
print("โœ… Cloudflare Tunnels server configured")
except Exception as e:
print(f"โš ๏ธ Could not parse Claude config: {e}")
else:
print("โš ๏ธ Claude Desktop config not found")
# Check tunnels repo
tunnels_repo = Path("tools/hanzoai-mcp-server-cloudflare")
if tunnels_repo.exists():
print(f"โœ… Cloudflare MCP server repo found: {tunnels_repo}")
tunnels_app = tunnels_repo / "apps" / "cloudflare-tunnels"
if tunnels_app.exists():
print("โœ… Cloudflare Tunnels app found")
else:
print("โŒ Cloudflare Tunnels app not found")
else:
print("โš ๏ธ Cloudflare MCP server repo not found locally")
def test_dev_mode():
"""Test development mode availability."""
print("\n๐Ÿ”ง Testing Development Mode\n")
try:
# Test watchdog import
import watchdog
try:
version = watchdog.__version__
print(f"โœ… Watchdog available: v{version}")
except AttributeError:
print("โœ… Watchdog available (version unknown)")
# Test dev server availability
from hanzo_mcp.dev_server import DevServer
print("โœ… DevServer class available")
# Check if CLI supports --dev
from hanzo_mcp import cli
print("โœ… CLI module available")
return True
except ImportError as e:
print(f"โŒ Development mode dependency missing: {e}")
return False
except Exception as e:
print(f"โŒ Development mode test failed: {e}")
return False
async def main():
"""Run all tests."""
print("๐Ÿš€ Hanzo AI Simple Test Suite")
print("=" * 50)
results = []
# Run tests
results.append(test_imports())
results.append(await test_file_operations())
results.append(test_shell_detection())
results.append(test_dev_mode())
# Cloudflare config test (always runs)
test_cloudflare_config()
# Summary
passed = sum(results)
total = len(results)
print(f"\n๐Ÿ“Š Test Results: {passed}/{total} passed")
if passed == total:
print("๐ŸŽ‰ All core tests passed!")
print("\n๐Ÿ”ง Next Steps:")
print("1. Restart Claude Desktop/Code to load new MCP servers")
print("2. Test Cloudflare tools: 'List my Cloudflare Tunnels'")
print("3. Test palette system: 'palette --action list'")
print("4. Test shell: 'bash \"echo $SHELL\"'")
print("5. Test dev mode: 'hanzo-mcp --dev --project-dir .'")
else:
print("โš ๏ธ Some tests failed. Check the output above.")
return passed == total
if __name__ == "__main__":
asyncio.run(main())