Skip to content
NeuroCognitive Architecture Badge

Memory System Test Plan

Last Updated: April 14, 2025

This document outlines the comprehensive test plan for the Neuroca memory system. It defines the testing approach, test categories, and specific test cases for each component.

Testing Approach

The memory system will be tested using a multi-layered approach:

  1. Unit Tests: Test individual components in isolation
  2. Integration Tests: Test interactions between components
  3. System Tests: Test the entire memory system as a whole
  4. Performance Tests: Measure performance characteristics
  5. Mutation Tests: Ensure test quality by modifying code and verifying test failures

Test Environment

  • Development: Local environment with in-memory backends
  • CI/CD: Automated tests in the CI pipeline with containerized dependencies
  • Staging: Tests against full infrastructure in a staging environment

Test Components

1. Storage Backends

Unit Tests

Test ID Description Assertions
SB-U-001 Initialize and shutdown storage backend Backend is properly initialized and can be shut down cleanly
SB-U-002 Create an item Item is created successfully with correct data
SB-U-003 Read an item Item can be retrieved with correct data
SB-U-004 Update an item Item is updated successfully with new data
SB-U-005 Delete an item Item is deleted successfully
SB-U-006 Check if an item exists Existence check returns correct result
SB-U-007 Batch create items Multiple items are created successfully
SB-U-008 Batch read items Multiple items can be retrieved correctly
SB-U-009 Batch update items Multiple items are updated successfully
SB-U-010 Batch delete items Multiple items are deleted successfully
SB-U-011 Query items with filters Query returns correct items based on filters
SB-U-012 Query items with sorting Query returns items in correct order
SB-U-013 Query items with pagination Query returns correct number of items and respects offset
SB-U-014 Handle vector search (if supported) Vector search returns items by similarity
SB-U-015 Handle item expiry (if supported) Items expire correctly and can be retrieved before expiry
SB-U-016 Count items Count returns correct number of items
SB-U-017 Clear all items All items are removed from storage
SB-U-018 Get storage statistics Stats contain expected metrics
SB-U-019 Handle concurrent operations Operations work correctly under concurrent load
SB-U-020 Handle storage errors Appropriate exceptions are raised for error conditions

Integration Tests

Test ID Description Assertions
SB-I-001 Redis backend with real Redis Backend works correctly with actual Redis instance
SB-I-002 SQL backend with real database Backend works correctly with actual SQL database
SB-I-003 Vector backend with real vector DB Backend works correctly with actual vector database
SB-I-004 Persistence across restarts Data persists after backend shutdown and restart
SB-I-005 Handle connection issues Backend gracefully handles connection failures

2. Memory Tiers

Unit Tests

Test ID Description Assertions
MT-U-001 Initialize and shutdown memory tier Tier is properly initialized and can be shut down cleanly
MT-U-002 Store a memory item Item is stored with tier-specific metadata
MT-U-003 Retrieve a memory item Item can be retrieved with tier-specific metadata
MT-U-004 Update a memory item Item is updated correctly including metadata
MT-U-005 Delete a memory item Item is deleted successfully
MT-U-006 Check if a memory exists Existence check returns correct result
MT-U-007 Search for memories Search returns relevant items according to tier-specific logic
MT-U-008 Get recent memories Recent memories are returned in correct order
MT-U-009 Get important memories Important memories are returned according to tier criteria
MT-U-010 Mark memory as accessed Access count and timestamp are updated
MT-U-011 Get memory strength Strength is calculated according to tier-specific logic
MT-U-012 Update memory strength Strength is updated correctly
MT-U-013 Perform cleanup operations Tier-specific cleanup works correctly
MT-U-014 Count memories Count returns correct number of memories
MT-U-015 Clear all memories All memories are removed from tier
MT-U-016 Get tier statistics Stats contain tier-specific metrics
MT-U-017 STM tier expiry STM memories expire correctly
MT-U-018 MTM tier priority MTM memories respect priority settings
MT-U-019 LTM tier relationships LTM memory relationships work correctly

Integration Tests

Test ID Description Assertions
MT-I-001 STM tier with real backend STM tier works correctly with actual storage backend
MT-I-002 MTM tier with real backend MTM tier works correctly with actual storage backend
MT-I-003 LTM tier with real backend LTM tier works correctly with actual storage backend
MT-I-004 Large-scale operation handling Tier handles large numbers of memories efficiently

3. Memory Manager

Unit Tests

Test ID Description Assertions
MM-U-001 Initialize and shutdown memory manager Manager initializes all components and shuts down cleanly
MM-U-002 Add a memory Memory is added to the appropriate tier
MM-U-003 Retrieve a memory by ID Memory is retrieved correctly, possibly searching multiple tiers
MM-U-004 Update a memory Memory is updated correctly across tiers
MM-U-005 Delete a memory Memory is deleted correctly from all tiers
MM-U-006 Search memories across tiers Search combines results from all tiers correctly
MM-U-007 Update context Context is updated and triggers relevant memory retrieval
MM-U-008 Get prompt context memories Appropriate memories are selected for prompt context
MM-U-009 Clear context Context and working memory are cleared correctly
MM-U-010 Consolidate memory between tiers Memory is moved correctly from one tier to another
MM-U-011 Strengthen memory Memory strength is increased correctly
MM-U-012 Decay memory Memory strength is decreased correctly
MM-U-013 Get system statistics Stats include data from all tiers
MM-U-014 Run maintenance Maintenance tasks are performed on all components
MM-U-015 Handle missing memory Appropriate error is raised when memory is not found
MM-U-016 Handle invalid tier Appropriate error is raised when tier is invalid
MM-U-017 Generate embeddings Embeddings are generated correctly for memory content

Integration Tests

Test ID Description Assertions
MM-I-001 Cross-tier memory operations Memory retrieval works across tiers
MM-I-002 Automatic consolidation Memories are automatically consolidated based on criteria
MM-I-003 Working memory updates Working memory updates correctly based on context
MM-I-004 Multi-user isolation Memory manager correctly isolates memories by user
MM-I-005 Full maintenance cycle Complete maintenance cycle updates all tiers correctly

4. Data Models

Unit Tests

Test ID Description Assertions
DM-U-001 MemoryItem creation and validation Memory items are created and validated correctly
DM-U-002 MemoryContent handling Different content types are handled correctly
DM-U-003 MemoryMetadata operations Metadata fields are updated correctly
DM-U-004 MemoryStatus transitions Status changes are handled correctly
DM-U-005 MemorySearchOptions validation Search options are validated correctly
DM-U-006 MemorySearchResult processing Search results are processed correctly
DM-U-007 WorkingMemoryItem operations Working memory items handle relevance correctly
DM-U-008 WorkingMemoryBuffer management Buffer manages items and pruning correctly

5. System Tests

Test ID Description Assertions
SYS-001 End-to-end memory lifecycle Memory flows through system from creation to retrieval to consolidation
SYS-002 Context-based retrieval System retrieves appropriate memories based on context
SYS-003 Prompt integration Memories are correctly formatted and integrated into prompts
SYS-004 Long-running system behavior System behaves correctly after extended operation
SYS-005 Error recovery System recovers correctly from various error conditions
SYS-006 Configuration changes System adapts correctly to configuration changes
SYS-007 Multi-component interaction All components interact correctly in various scenarios

6. Performance Tests

Test ID Description Metrics
PERF-001 Memory addition throughput Memories added per second under various conditions
PERF-002 Memory retrieval latency Time to retrieve memories by ID and by search
PERF-003 Search performance Time to perform various types of searches
PERF-004 Context update performance Time to update context and retrieve relevant memories
PERF-005 Consolidation performance Time to consolidate memories between tiers
PERF-006 Large-scale memory management Performance with large numbers of memories
PERF-007 Concurrent operation throughput Performance under concurrent operations

Mocking Strategy

To isolate components during unit testing, the following mocking strategy will be used:

  1. Storage Backend Testing
  2. Mock actual database connections for unit tests
  3. Use in-memory implementations where possible
  4. Use real databases for integration tests

  5. Memory Tier Testing

  6. Mock storage backends for unit tests
  7. Use real backends for integration tests

  8. Memory Manager Testing

  9. Mock memory tiers for unit tests
  10. Use real tiers with mocked backends for integration tests
  11. Use real tiers with real backends for system tests

Test Data Strategy

  1. Synthetic Data
  2. Generate varied memory content, metadata, and embeddings
  3. Ensure coverage of edge cases (empty content, large content, special characters)

  4. Realistic Data

  5. Sample real-world memory patterns for more realistic tests
  6. Create scenarios that mimic actual user interactions

Testing Tools

  1. Unit Testing Framework: pytest
  2. Mocking: pytest-mock, unittest.mock
  3. Coverage: pytest-cov
  4. Async Testing: pytest-asyncio
  5. Benchmarking: pytest-benchmark
  6. Integration Testing: TestContainers for database dependencies

Continuous Integration

  1. Build Pipeline Stages
  2. Run unit tests
  3. Run integration tests
  4. Run performance tests
  5. Generate and publish coverage reports

  6. Quality Gates

  7. Minimum code coverage: 90%
  8. All tests must pass
  9. No degradation in performance metrics

Test Implementation Plan

Phase 1: Core Test Infrastructure

  1. Set up test fixtures for all components
  2. Implement basic mocks for dependencies
  3. Create test data generators

Phase 2: Storage Backend Tests

  1. Implement unit tests for all storage backends
  2. Implement integration tests for backend-specific features

Phase 3: Memory Tier Tests

  1. Implement unit tests for all memory tiers
  2. Implement tier-specific tests (STM, MTM, LTM)

Phase 4: Memory Manager Tests

  1. Implement unit tests for memory manager
  2. Implement tests for cross-tier operations

Phase 5: System and Performance Tests

  1. Implement end-to-end system tests
  2. Implement performance benchmarks
  3. Implement load tests for concurrent operations

Test File Structure

Tests will follow a structure mirroring the implementation files:

``` tests/unit/memory/ ├── interfaces/ │ ├── test_storage_backend.py │ ├── test_memory_tier.py │ └── test_memory_manager.py ├── models/ │ ├── test_memory_item.py │ ├── test_search.py │ └── test_working_memory.py ├── backends/ │ ├── test_in_memory_backend.py │ ├── test_redis_backend.py │ ├── test_sql_backend.py │ └── test_vector_backend.py ├── tiers/ │ ├── test_stm.py │ ├── test_mtm.py │ └── test_ltm.py └── manager/ ├── test_core.py ├── test_consolidation.py ├── test_decay.py └── test_working_memory.py

tests/integration/memory/ ├── backends/ │ ├── test_redis_integration.py │ ├── test_sql_integration.py │ └── test_vector_integration.py ├── tiers/ │ ├── test_stm_integration.py │ ├── test_mtm_integration.py │ └── test_ltm_integration.py