-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest_server.py
More file actions
387 lines (329 loc) · 14.3 KB
/
test_server.py
File metadata and controls
387 lines (329 loc) · 14.3 KB
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
#!/usr/bin/env python3
"""
Test script for Claude Thread Continuity MCP Server
This script tests the basic functionality of the server to ensure it's working correctly.
Run this before setting up the server with Claude Desktop.
"""
import asyncio
import json
import sys
import os
from pathlib import Path
# Add the current directory to Python path so we can import the server
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
try:
from server import ProjectState, ContinuityServer
print("✅ Successfully imported server modules")
except ImportError as e:
print(f"❌ Failed to import server modules: {e}")
print("Make sure you're running this from the directory containing server.py")
sys.exit(1)
async def test_project_state():
"""Test the ProjectState class functionality."""
print("\n🧪 Testing ProjectState class...")
# Use a temporary directory for testing
test_dir = Path("/tmp/claude_continuity_test")
storage = ProjectState(str(test_dir))
# Test data
test_project = "test-project"
test_data = {
"current_focus": "Testing the continuity system",
"technical_decisions": ["Using Python for MCP server", "JSON for data storage"],
"files_modified": ["server.py", "test_server.py"],
"next_actions": ["Run integration tests", "Deploy to production"],
"conversation_summary": "Building and testing Claude Thread Continuity MCP server"
}
try:
# Test saving
print(" 📝 Testing save_state...")
result = await storage.save_state(test_project, test_data)
if result.get('success'):
print(" ✅ save_state successful")
else:
print(f" ❌ save_state failed: {result.get('message')}")
return False
# Test loading
print(" 📖 Testing load_state...")
loaded_data = await storage.load_state(test_project)
if loaded_data:
print(" ✅ load_state successful")
# Verify data integrity
if loaded_data.get("current_focus") == test_data["current_focus"]:
print(" ✅ Data integrity verified")
else:
print(" ❌ Data integrity check failed")
return False
else:
print(" ❌ load_state returned None")
return False
# Test listing projects
print(" 📋 Testing list_projects...")
projects = storage.list_projects()
if projects and any(p["name"] == test_project for p in projects):
print(" ✅ list_projects successful")
else:
print(" ❌ list_projects failed or project not found")
return False
# Test project summary
print(" 📊 Testing get_project_summary...")
summary = await storage.get_project_summary(test_project)
if summary and "Testing the continuity system" in summary:
print(" ✅ get_project_summary successful")
else:
print(" ❌ get_project_summary failed")
return False
# Test auto-save checkpoint
print(" 💾 Testing auto_save_checkpoint...")
checkpoint_success = await storage.auto_save_checkpoint(test_project, "test_trigger", "Testing checkpoint functionality")
if checkpoint_success:
print(" ✅ auto_save_checkpoint successful")
else:
print(" ❌ auto_save_checkpoint failed")
return False
# Cleanup
import shutil
if test_dir.exists():
shutil.rmtree(test_dir)
print(" 🧹 Cleanup completed")
return True
except Exception as e:
print(f" ❌ Error during testing: {e}")
import traceback
traceback.print_exc()
return False
async def test_project_validation():
"""Test the new project validation functionality."""
print("\n🧪 Testing Project Validation features...")
# Use a temporary directory for testing
test_dir = Path("/tmp/claude_continuity_validation_test")
storage = ProjectState(str(test_dir))
try:
# Create some test projects with similar names
projects_to_create = [
"Hebrew Evaluation MVP",
"Test Project Alpha",
"Website Development"
]
print(" 📝 Creating test projects...")
for project_name in projects_to_create:
test_data = {
"current_focus": f"Working on {project_name}",
"conversation_summary": f"Test project for {project_name}"
}
result = await storage.save_state(project_name, test_data, force=True)
if not result.get('success'):
print(f" ❌ Failed to create test project: {project_name}")
return False
print(" ✅ Test projects created")
# Test validation with unique name
print(" 🔍 Testing validation with unique name...")
validation = storage.validate_project_name("Completely Different Project")
if validation['is_unique']:
print(" ✅ Unique name validation successful")
else:
print(" ❌ Unique name validation failed")
return False
# Test validation with similar name (should detect Hebrew Evaluation MVP)
print(" 🔍 Testing validation with similar name...")
validation = storage.validate_project_name("Hebrew Speaking Evaluation MVP")
if not validation['is_unique'] and len(validation['similar_projects']) > 0:
similar_project = validation['similar_projects'][0]
if 'Hebrew Evaluation MVP' in similar_project['name']:
print(f" ✅ Similar name detection successful (found: {similar_project['name']}, similarity: {similar_project['similarity']})")
else:
print(f" ❌ Wrong similar project detected: {similar_project['name']}")
return False
else:
print(" ❌ Similar name validation failed - should have detected similarity")
return False
# Test save with validation (should fail)
print(" 🚫 Testing save with validation failure...")
result = await storage.save_state("Hebrew Evaluation Website", {"test": "data"}, force=False)
if not result.get('success') and result.get('status') == 'validation_required':
print(" ✅ Save validation correctly prevented similar project creation")
else:
print(" ❌ Save validation failed to prevent similar project creation")
return False
# Test save with force override
print(" 💪 Testing save with force override...")
result = await storage.save_state("Hebrew Evaluation Website", {"test": "data"}, force=True)
if result.get('success'):
print(" ✅ Force override successful")
else:
print(" ❌ Force override failed")
return False
# Test different similarity thresholds
print(" 🎯 Testing different similarity thresholds...")
validation_strict = storage.validate_project_name("Hebrew Eval MVP", similarity_threshold=0.9)
validation_loose = storage.validate_project_name("Hebrew Eval MVP", similarity_threshold=0.5)
if len(validation_loose['similar_projects']) >= len(validation_strict['similar_projects']):
print(" ✅ Similarity threshold working correctly")
else:
print(" ❌ Similarity threshold not working as expected")
return False
# Cleanup
import shutil
if test_dir.exists():
shutil.rmtree(test_dir)
print(" 🧹 Validation test cleanup completed")
return True
except Exception as e:
print(f" ❌ Error during validation testing: {e}")
import traceback
traceback.print_exc()
return False
async def test_server_initialization():
"""Test basic server initialization."""
print("\n🧪 Testing ContinuityServer initialization...")
try:
server = ContinuityServer()
print(" ✅ Server instance created successfully")
# Test async initialization
init_result = await server.initialize()
if init_result:
print(" ✅ Async initialization successful")
else:
print(" ⚠️ Async initialization returned False (may still work)")
# Test storage initialization
storage = await server._ensure_storage_initialized()
if storage:
print(" ✅ Storage initialization successful")
else:
print(" ❌ Storage initialization failed")
return False
return True
except Exception as e:
print(f" ❌ Error during server testing: {e}")
import traceback
traceback.print_exc()
return False
async def test_new_tools():
"""Test the new MCP tools for validation."""
print("\n🧪 Testing new MCP tools...")
try:
server = ContinuityServer()
await server.initialize()
# First, create a project to test against
await server.handle_save_project_state({
"project_name": "My Test Project",
"current_focus": "Setup for tool testing",
"force": True
})
# Test validate_project_name tool with a similar name
print(" 🔍 Testing validate_project_name tool...")
result = await server.handle_validate_project_name({
"project_name": "My Test Proj",
"similarity_threshold": 0.7
})
if result and len(result) > 0 and "SIMILAR PROJECTS FOUND" in result[0].text:
print(" ✅ validate_project_name tool working")
else:
print(" ❌ validate_project_name tool failed")
# print(f"DEBUG: {result[0].text if result else 'No result'}")
return False
# Test enhanced save_project_state with validation
print(" 💾 Testing enhanced save_project_state...")
save_result = await server.handle_save_project_state({
"project_name": "Unique Save Test Project",
"current_focus": "Testing enhanced save functionality",
"force": False
})
if save_result and len(save_result) > 0 and "✅" in save_result[0].text:
print(" ✅ Enhanced save_project_state working")
else:
print(" ❌ Enhanced save_project_state failed")
return False
# Cleanup the test project
import shutil
test_dir = Path(os.path.expanduser("~/.claude_states/"))
project_dirs = ["My Test Project", "Unique Save Test Project"]
for p_dir in project_dirs:
dir_to_remove = test_dir / p_dir
if dir_to_remove.exists():
shutil.rmtree(dir_to_remove)
return True
except Exception as e:
print(f" ❌ Error during new tools testing: {e}")
import traceback
traceback.print_exc()
return False
def test_dependencies():
"""Test that all required dependencies are available."""
print("\n🧪 Testing dependencies...")
dependencies = [
("mcp", "MCP SDK"),
("mcp.server", "MCP Server"),
("mcp.types", "MCP Types"),
("json", "JSON (built-in)"),
("pathlib", "Pathlib (built-in)"),
("asyncio", "Asyncio (built-in)"),
("difflib", "Difflib (built-in) - NEW for validation")
]
for module_name, description in dependencies:
try:
__import__(module_name)
print(f" ✅ {description}")
except ImportError:
print(f" ❌ {description} - MISSING!")
print(f" Try: pip install {module_name}")
return False
return True
def main():
"""Run all tests."""
print("🚀 Claude Thread Continuity MCP Server Test Suite v1.1")
print("==" * 30)
all_tests_passed = True
# Test dependencies
if not test_dependencies():
all_tests_passed = False
print("\n❌ Dependency tests failed. Please install missing dependencies.")
# Test ProjectState functionality
try:
if not asyncio.run(test_project_state()):
all_tests_passed = False
print("\n❌ ProjectState tests failed.")
except Exception as e:
print(f"\n❌ ProjectState test crashed: {e}")
all_tests_passed = False
# Test NEW project validation functionality
try:
if not asyncio.run(test_project_validation()):
all_tests_passed = False
print("\n❌ Project validation tests failed.")
except Exception as e:
print(f"\n❌ Project validation test crashed: {e}")
all_tests_passed = False
# Test server initialization
try:
if not asyncio.run(test_server_initialization()):
all_tests_passed = False
print("\n❌ Server initialization tests failed.")
except Exception as e:
print(f"\n❌ Server initialization test crashed: {e}")
all_tests_passed = False
# Test new MCP tools
try:
if not asyncio.run(test_new_tools()):
all_tests_passed = False
print("\n❌ New tools tests failed.")
except Exception as e:
print(f"\n❌ New tools test crashed: {e}")
all_tests_passed = False
# Summary
print("\n" + "=" * 60)
if all_tests_passed:
print("🎉 All tests passed! The enhanced server is ready to use.")
print("\n✨ NEW FEATURES VALIDATED:")
print(" • Project name validation with fuzzy matching")
print(" • Automatic fragmentation prevention")
print(" • Force override for edge cases")
print(" • Configurable similarity thresholds")
print("\nNext steps:")
print("1. Add the server to your Claude Desktop config")
print("2. Restart Claude Desktop")
print("3. Enjoy fragmentation-free project continuity!")
else:
print("❌ Some tests failed. Please fix the issues above before using the server.")
return 0 if all_tests_passed else 1
if __name__ == "__main__":
sys.exit(main())