Testing Infrastructure
Relevant source files
The following files were used as context for generating this wiki page:
The testing infrastructure provides a comprehensive validation suite for the Sequential Thinking MCP v2 server. It covers unit testing for domain models and business logic, adapter-level testing for tool handlers, and full integration tests for end-to-end reasoning workflows. The suite ensures that session persistence, memory management, and structured reasoning remain robust during modernization efforts.
Sources: memory-bank/memories/67944906-43bc-4c85-9424-f2261850bc97.md:7-9, tests/test_integration.py:10-12
Testing Layers
The infrastructure divides testing into three distinct layers to ensure complete coverage of the 5-layer architecture.
| Layer | Scope | Primary File |
|---|---|---|
| Model Validation | Validates data integrity, default values, and UUID generation for dataclasses. | tests/test_models.py |
| Logic & Storage | Tests UnifiedSessionManager for file operations and state transitions. | tests/test_session_manager.py |
| Tool Interface | Verifies MCPToolsHandler response formats and error catching. | tests/test_mcp_tools.py |
| Integration | Simulates complete user workflows and server restarts. | tests/test_integration.py |
Sources: tests/test_models.py:5, tests/test_session_manager.py:11, tests/test_mcp_tools.py:9, tests/test_integration.py:10
Environment Management
The test suite uses pytest fixtures to manage temporary files. This prevents test execution from polluting the actual memory-bank/ directory.
Temporary Memory Bank Setup
The temp_memory_bank fixture creates a unique directory for each test class using tempfile.mkdtemp(). It recursively deletes the directory after the test finishes using shutil.rmtree().
@pytest.fixture
def temp_memory_bank(self):
"""Create a temporary memory bank for testing."""
temp_dir = tempfile.mkdtemp()
yield temp_dir
shutil.rmtree(temp_dir)
Sources: tests/test_integration.py:13-18, tests/test_mcp_tools.py:12-17
Component Relationship Flow
This diagram illustrates how the testing infrastructure initializes the system components within a temporary environment.
The diagram shows the setup and teardown flow used in TestIntegration and TestMCPToolsHandler.
Sources: tests/test_integration.py:20-25, tests/test_mcp_tools.py:19-27
Domain Model Testing
The infrastructure validates the core data structures defined in models.py. Tests ensure that every object receives a unique ID and that defaults (like confidence levels) are applied correctly.
Key Model Validations
- UUID Uniqueness: Validates that calling constructors multiple times generates distinct identifiers.
- Default Values: Confirms that
ThoughtandMemoryobjects start with a 0.8 confidence level. - Enum Integrity: Verifies that
SessionTypecorrectly distinguishes between "general" and "coding" sessions.
Sources: tests/test_models.py:10-15, tests/test_models.py:157-175, tests/test_models.py:178-185
Session and Storage Validation
Testing for UnifiedSessionManager focuses on the persistence layer and state management.
Persistence Verification
Tests verify that the manager creates a structured filesystem upon initialization:
sessions/for markdown snapshots.memories/for standalone memory artifacts.patterns/for reserved code patterns.index.mdfor the session registry.
Sources: tests/test_session_manager.py:25-33
Workflow Logic
The suite tests complex state transitions, such as branching and merging.
The diagram shows the sequence of operations for testing branch lifecycle.
Sources: tests/test_session_manager.py:91-133
Tool Handler Testing
Tests in tests/test_mcp_tools.py ensure the MCPToolsHandler provides a stable interface for the MCP protocol.
Success and Error Patterns
Tool tests verify that successful operations return dictionaries with relevant IDs (e.g., thought_id, memory_id), while failures are caught and returned as error strings rather than raising unhandled exceptions.
| Tool Method | Success Assertion | Error Condition |
|---|---|---|
start_session | Returns session_id | Invalid parameters |
add_thought | Returns thought_id | No active session |
query_memories | Returns memories list | Non-existent tags |
export_session | Returns filename | Invalid format or no session |
Sources: tests/test_mcp_tools.py:29-57, tests/test_mcp_tools.py:186-218
Integration Testing
Integration tests simulate real-world reasoning tasks to verify that the 12 tools work together.
Persistence and Recovery
A critical test case simulates a server crash and restart:
- Initialize a session and add data.
- Create a new
UnifiedSessionManagerinstance pointing to the same temporary path. - Call
load_session(original_id). - Verify that all thoughts, memories, and architecture decisions are re-hydrated from the markdown files.
Sources: tests/test_integration.py:218-257
End-to-End Coding Workflow
The test_complete_workflow_coding_session validates a multi-step process:
- Starting a "coding" type session.
- Exploring package dependencies.
- Recording architecture decisions with rationale and consequences.
- Exporting the final session to a markdown file for human review.
Sources: tests/test_integration.py:27-142
The infrastructure achieves >85% coverage across unit, integration, and error handling scenarios, transforming a previously untested project into a production-ready system.
Sources: memory-bank/memories/67944906-43bc-4c85-9424-f2261850bc97.md:7-9, memory-bank/memories/1eba30a1-6283-44a2-a372-82e9fe92460d.md:16