- simple_test_cli.py: Working CLI for simple (stateless) backend - Supports one-shot execution and interactive REPL - Uses PassthroughValidator and wrappers to bypass security for testing - Skips resource limits to avoid cgroupv2 issues in rootless Podman - test_containers.py: Container verification script (all tests passing) - simple_test_cli_README.md: Documentation for test tools Note: Jupyter backend has connection file timing issues (future work)
132 lines
3.4 KiB
Python
Executable file
132 lines
3.4 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
"""
|
|
Minimal test script to verify container execution works.
|
|
|
|
This tests the basic container creation and execution without
|
|
using the full MCP-Forge stack.
|
|
"""
|
|
|
|
import sys
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
# ANSI colors
|
|
GREEN = "\033[92m"
|
|
RED = "\033[91m"
|
|
GRAY = "\033[90m"
|
|
RESET = "\033[0m"
|
|
|
|
|
|
def test_simple_execution():
|
|
"""Test simple container execution."""
|
|
print(f"\n{GRAY}Testing simple (stateless) execution...{RESET}")
|
|
|
|
code = "print('Hello from MCP-Forge!')\nprint(2 + 2)"
|
|
|
|
cmd = [
|
|
"podman", "run", "--rm",
|
|
"--network=none",
|
|
"mcp-forge/python:3.12",
|
|
"python3", "-c", code
|
|
]
|
|
|
|
try:
|
|
result = subprocess.run(
|
|
cmd,
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=10
|
|
)
|
|
|
|
if result.returncode == 0:
|
|
print(f"{GREEN}✓ Simple execution works!{RESET}")
|
|
print(f"{GRAY}Output:{RESET}")
|
|
print(result.stdout)
|
|
return True
|
|
else:
|
|
print(f"{RED}✗ Simple execution failed{RESET}")
|
|
print(f"{RED}Error:{RESET}")
|
|
print(result.stderr)
|
|
return False
|
|
|
|
except subprocess.TimeoutExpired:
|
|
print(f"{RED}✗ Execution timed out{RESET}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"{RED}✗ Error: {e}{RESET}")
|
|
return False
|
|
|
|
|
|
def test_jupyter_kernel():
|
|
"""Test Jupyter kernel container."""
|
|
print(f"\n{GRAY}Testing Jupyter kernel availability...{RESET}")
|
|
|
|
cmd = [
|
|
"podman", "run", "--rm",
|
|
"--network=host",
|
|
"mcp-forge/jupyter:latest",
|
|
"python3", "-c", "import ipykernel; print(ipykernel.__version__)"
|
|
]
|
|
|
|
try:
|
|
result = subprocess.run(
|
|
cmd,
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=10
|
|
)
|
|
|
|
if result.returncode == 0:
|
|
version = result.stdout.strip()
|
|
print(f"{GREEN}✓ Jupyter kernel available (ipykernel {version})!{RESET}")
|
|
return True
|
|
else:
|
|
print(f"{RED}✗ Jupyter kernel check failed{RESET}")
|
|
print(f"{RED}Error:{RESET}")
|
|
print(result.stderr)
|
|
return False
|
|
|
|
except subprocess.TimeoutExpired:
|
|
print(f"{RED}✗ Check timed out{RESET}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"{RED}✗ Error: {e}{RESET}")
|
|
return False
|
|
|
|
|
|
def main():
|
|
"""Main entry point."""
|
|
print(f"{GREEN}MCP-Forge Container Tests{RESET}")
|
|
print(f"{GRAY}{'='*40}{RESET}")
|
|
|
|
results = []
|
|
|
|
# Test simple execution
|
|
results.append(("Simple Execution", test_simple_execution()))
|
|
|
|
# Test Jupyter kernel
|
|
results.append(("Jupyter Kernel", test_jupyter_kernel()))
|
|
|
|
# Summary
|
|
print(f"\n{GRAY}{'='*40}{RESET}")
|
|
print(f"{GREEN}Test Summary:{RESET}\n")
|
|
|
|
passed = sum(1 for _, result in results if result)
|
|
total = len(results)
|
|
|
|
for name, result in results:
|
|
status = f"{GREEN}✓ PASS{RESET}" if result else f"{RED}✗ FAIL{RESET}"
|
|
print(f" {name}: {status}")
|
|
|
|
print(f"\n{GRAY}Passed: {passed}/{total}{RESET}")
|
|
|
|
if passed == total:
|
|
print(f"\n{GREEN}All tests passed!{RESET}")
|
|
return 0
|
|
else:
|
|
print(f"\n{RED}Some tests failed.{RESET}")
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|