test_tools.py•1.83 kB
#!/usr/bin/env python3
"""
Test script to verify git tools work correctly
"""
import subprocess
import sys
def test_git_command(command, description):
"""Test a git command"""
print(f"\n{'='*60}")
print(f"Testing: {description}")
print(f"Command: git {' '.join(command)}")
print('='*60)
try:
result = subprocess.run(
["git"] + command,
cwd="/Users/prateek/Code/claude", # Test in the claude repo
capture_output=True,
text=True,
check=True
)
print(result.stdout)
print("✓ Success")
return True
except subprocess.CalledProcessError as e:
print(f"✗ Error: {e.stderr}")
return False
except Exception as e:
print(f"✗ Exception: {e}")
return False
def main():
"""Run all tests"""
print("Git Helper MCP - Tool Tests")
print("Testing against /Users/prateek/Code/claude repository\n")
tests = [
(["status", "--short"], "Get repository status"),
(["branch", "-a"], "List all branches"),
(["log", "-5", "--pretty=format:%h - %s (%an, %ar)"], "Get commit history"),
(["branch", "--show-current"], "Get current branch"),
(["diff"], "Get unstaged changes"),
]
results = []
for command, description in tests:
results.append(test_git_command(command, description))
# Summary
print(f"\n{'='*60}")
print("Test Summary")
print('='*60)
passed = sum(results)
total = len(results)
print(f"Passed: {passed}/{total}")
if passed == total:
print("\n✓ All tests passed! Your MCP tools should work correctly.")
return 0
else:
print(f"\n✗ {total - passed} test(s) failed.")
return 1
if __name__ == "__main__":
sys.exit(main())