Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as opaque submodule gitlinks on GitHub) into fully-tracked first-party content. AITM now merges its 7 vendored repos as first-party engines: - memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts - git: vendored C git (bundled binary) + gitnexus (in-process code intelligence) - agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess) Includes the full session's product build: Gitgram web/mobile/backend features, AITM website/CLI/MCP, the unified memory layer, engine build tooling (scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md), and extensive test suites. Build artifacts, node_modules, external/, and gemini-cli are gitignored. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
76 lines
2.1 KiB
Python
76 lines
2.1 KiB
Python
"""Tests for MCP server lifecycle management."""
|
|
|
|
import signal
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
|
|
def test_cleanup_handlers_registered():
|
|
"""Test that cleanup handlers are registered on server import."""
|
|
# Server is already imported, so handlers are already registered
|
|
# We can verify the cleanup function and signal handler exist
|
|
import beads_mcp.server as server
|
|
|
|
# Verify cleanup function exists and is callable
|
|
assert hasattr(server, "cleanup")
|
|
assert callable(server.cleanup)
|
|
|
|
# Verify signal handler exists and is callable
|
|
assert hasattr(server, "signal_handler")
|
|
assert callable(server.signal_handler)
|
|
|
|
# Verify global state exists
|
|
assert hasattr(server, "_cleanup_done")
|
|
|
|
|
|
def test_cleanup_function_safe_to_call_multiple_times():
|
|
"""Test that cleanup function can be called multiple times safely."""
|
|
import beads_mcp.server as server
|
|
from beads_mcp.server import cleanup
|
|
|
|
server._cleanup_done = False
|
|
|
|
# Call cleanup multiple times - should not raise
|
|
cleanup()
|
|
cleanup()
|
|
cleanup()
|
|
|
|
|
|
def test_signal_handler_calls_cleanup():
|
|
"""Test that signal handler calls cleanup and exits."""
|
|
from beads_mcp.server import signal_handler
|
|
|
|
with patch("beads_mcp.server.cleanup") as mock_cleanup, patch("sys.exit") as mock_exit:
|
|
# Call signal handler
|
|
signal_handler(signal.SIGTERM, None)
|
|
|
|
# Verify cleanup was called
|
|
assert mock_cleanup.called
|
|
|
|
# Verify exit was called
|
|
assert mock_exit.called
|
|
|
|
|
|
def test_cleanup_logs_lifecycle_events(caplog):
|
|
"""Test that cleanup logs informative messages."""
|
|
import logging
|
|
|
|
# Reset state
|
|
import beads_mcp.server as server
|
|
from beads_mcp.server import cleanup
|
|
|
|
server._cleanup_done = False
|
|
|
|
with caplog.at_level(logging.INFO):
|
|
cleanup()
|
|
|
|
# Check for lifecycle log messages
|
|
log_messages = [record.message for record in caplog.records]
|
|
assert any("Cleaning up" in msg for msg in log_messages)
|
|
assert any("Cleanup complete" in msg for msg in log_messages)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
pytest.main([__file__, "-v"])
|