summaryrefslogtreecommitdiff
path: root/mcp-servers/memory-mcp-server/.claude/commands/test.md
blob: e78843c123145ce7b56e50b547b4efa3613ac776 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
---
description: Generate comprehensive tests for Memory MCP Server
argument-hint: "[file, function, MCP tool, or test scenario]"
allowed-tools: Read, Write, MultiEdit, Bash, Task, TodoWrite
---

# Memory MCP Server Test Generation

Generate comprehensive test cases for $ARGUMENTS with focus on MCP protocol compliance and memory operations:

## Unit Tests

### MCP Protocol Tests

```typescript
// Test MCP message handling
describe('MCP Protocol', () => {
  it('should handle JSON-RPC 2.0 requests', async () => {
    // Test request with id
    // Test notification without id
    // Test batch requests
  });
  
  it('should return proper error codes', async () => {
    // -32700: Parse error
    // -32600: Invalid request
    // -32601: Method not found
    // -32602: Invalid params
    // -32603: Internal error
  });
  
  it('should validate tool parameters with Zod', async () => {
    // Test required fields
    // Test type validation
    // Test nested schemas
  });
});
```

### Memory Operations Tests

```typescript
// Test memory CRUD operations
describe('Memory Operations', () => {
  it('should create memory with embeddings', async () => {
    // Test successful creation
    // Test OpenAI API failure handling
    // Test vector dimension validation
  });
  
  it('should perform vector similarity search', async () => {
    // Test similarity threshold
    // Test result limit
    // Test empty results
    // Test index usage
  });
  
  it('should handle memory lifecycle', async () => {
    // Test expiration
    // Test archival
    // Test soft delete
    // Test importance decay
  });
  
  it('should consolidate memories', async () => {
    // Test deduplication
    // Test summarization
    // Test relationship creation
  });
});
```

### Database Tests

```typescript
// Test database operations
describe('Database Operations', () => {
  it('should handle transactions', async () => {
    // Test commit on success
    // Test rollback on error
    // Test isolation levels
  });
  
  it('should use pgvector correctly', async () => {
    // Test vector operations
    // Test distance calculations
    // Test index scans
  });
  
  it('should maintain referential integrity', async () => {
    // Test foreign keys
    // Test cascade deletes
    // Test orphan prevention
  });
});
```

## Integration Tests

### MCP Server Integration

```typescript
// Test full MCP server flow
describe('MCP Server Integration', () => {
  let server: MCPServer;
  let client: MCPClient;
  
  beforeEach(async () => {
    server = await createMemoryMCPServer();
    client = await connectMCPClient(server);
  });
  
  it('should register tools on connection', async () => {
    const tools = await client.listTools();
    expect(tools).toContain('create_memory');
    expect(tools).toContain('search_memories');
  });
  
  it('should handle tool execution', async () => {
    const result = await client.executeTool('create_memory', {
      content: 'Test memory',
      type: 'fact'
    });
    expect(result.id).toBeDefined();
    expect(result.embedding).toHaveLength(1536);
  });
  
  it('should maintain session isolation', async () => {
    // Test multi-tenant boundaries
    // Test companion isolation
    // Test user context
  });
});
```

### Vector Search Integration

```typescript
// Test vector search functionality
describe('Vector Search Integration', () => {
  it('should find similar memories', async () => {
    // Create test memories
    // Generate embeddings
    // Test similarity search
    // Verify ranking
  });
  
  it('should use indexes efficiently', async () => {
    // Test IVFFlat performance
    // Test HNSW performance
    // Monitor query plans
  });
});
```

## Edge Cases & Error Conditions

```typescript
describe('Edge Cases', () => {
  it('should handle malformed requests', async () => {
    // Invalid JSON
    // Missing required fields
    // Wrong types
  });
  
  it('should handle resource limits', async () => {
    // Max memory count per user
    // Request size limits
    // Rate limiting
  });
  
  it('should handle concurrent operations', async () => {
    // Parallel memory creation
    // Concurrent searches
    // Session conflicts
  });
  
  it('should handle external service failures', async () => {
    // Database down
    // OpenAI API timeout
    // Network errors
  });
});
```

## Performance Tests

```typescript
describe('Performance', () => {
  it('should handle bulk operations', async () => {
    // Batch memory creation
    // Large result sets
    // Pagination
  });
  
  it('should meet latency requirements', async () => {
    // Vector search < 200ms
    // CRUD operations < 100ms
    // Tool registration < 50ms
  });
  
  it('should scale with data volume', async () => {
    // Test with 10K memories
    // Test with 100K memories
    // Test with 1M memories
  });
});
```

## Mock Strategies

```typescript
// Mocking external dependencies
const mocks = {
  // Mock OpenAI API
  openai: {
    embeddings: {
      create: jest.fn().mockResolvedValue({
        data: [{ embedding: new Array(1536).fill(0.1) }]
      })
    }
  },
  
  // Mock database
  db: {
    query: jest.fn(),
    transaction: jest.fn()
  },
  
  // Mock MCP client
  mcpClient: {
    request: jest.fn(),
    notify: jest.fn()
  }
};
```

## Test Data Fixtures

```typescript
// Reusable test data
export const fixtures = {
  memories: [
    {
      content: 'User prefers dark mode',
      type: 'preference',
      importance: 0.8
    },
    {
      content: 'Meeting scheduled for 3pm',
      type: 'event',
      expires_at: '2024-12-31'
    }
  ],
  
  embeddings: {
    sample: new Array(1536).fill(0.1),
    similar: new Array(1536).fill(0.09),
    different: new Array(1536).fill(0.5)
  },
  
  mcpRequests: {
    valid: {
      jsonrpc: '2.0',
      method: 'create_memory',
      params: { content: 'Test' },
      id: 1
    },
    invalid: {
      jsonrpc: '1.0', // Wrong version
      method: 'unknown_method'
    }
  }
};
```

## Test Coverage Requirements

- **Unit Tests**: 90% code coverage
- **Integration Tests**: All critical paths
- **E2E Tests**: Core user journeys
- **Performance Tests**: Load scenarios
- **Security Tests**: Auth and isolation

## Test Execution Commands

```bash
# Run all tests
npm test

# Run with coverage
npm run test:coverage

# Run specific test file
npm test -- memory.test.ts

# Run integration tests
npm run test:integration

# Run performance tests
npm run test:perf

# Watch mode for development
npm run test:watch
```