brainy/test-memory-safe.js
David Snelling 4949b6a629 CHECKPOINT: Industry-standard 3-tier testing implemented
 MAJOR BREAKTHROUGH - Session 5 Success:
- Unit tests: 18/19 passing with mocked AI (<500MB RAM)
- Integration tests: Real AI models loading successfully
- Core features: Real embeddings, CRUD operations verified
- Architecture: All 11 augmentations, worker threads operational

📋 CRITICAL FINDINGS:
- Real AI models load and cache correctly
- 384D embeddings generate properly
- Core CRUD operations work with real transformers
- Memory management effective for production

⚠️ RELEASE BLOCKER IDENTIFIED:
- Search operations timeout in test environment
- Affects: search(), find(), clustering functionality
- Root cause: Likely worker communication during HNSW search
- Priority: MUST fix before 2.0.0 release

🎯 NEXT SESSION PRIORITIES:
1. Debug and fix search timeout issue
2. Verify search/find/clustering work in production
3. Final documentation cleanup
4. Release preparation

Confidence: 90% ready (pending search functionality verification)
2025-08-25 17:12:58 -07:00

114 lines
No EOL
3.8 KiB
JavaScript
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
/**
* Test Memory-Safe Brainy System
*
* Verifies that our universal memory manager prevents crashes
* Uses reasonable memory limits (4GB instead of 16GB)
*/
import { BrainyData } from './dist/index.js'
console.log('🧠 Testing Memory-Safe Brainy System')
console.log('=' + '='.repeat(50))
async function testMemorySafety() {
try {
console.log('📊 Memory before start:')
const startMem = process.memoryUsage()
console.log(` Heap: ${(startMem.heapUsed / 1024 / 1024).toFixed(2)} MB`)
console.log(` RSS: ${(startMem.rss / 1024 / 1024).toFixed(2)} MB`)
console.log('\n🚀 Initializing Brainy with Universal Memory Manager...')
const brain = new BrainyData({
storage: { forceMemoryStorage: true },
verbose: false
})
await brain.init()
console.log('✅ Initialized successfully')
console.log('\n📝 Testing multiple embedding operations...')
const testItems = [
'JavaScript programming language',
'Python data science framework',
'React component library',
'Node.js runtime environment',
'Machine learning algorithms',
'Database query optimization',
'Web development frameworks',
'Cloud computing services',
'Artificial intelligence models',
'Software engineering practices'
]
// Add items that require embeddings
for (let i = 0; i < testItems.length; i++) {
const id = await brain.addNoun({
text: testItems[i],
category: 'tech',
index: i
})
console.log(` Added item ${i + 1}/10: ${testItems[i].substring(0, 30)}...`)
// Check memory periodically
if (i % 3 === 0) {
const mem = process.memoryUsage()
console.log(` Memory: ${(mem.heapUsed / 1024 / 1024).toFixed(2)} MB heap, ${(mem.rss / 1024 / 1024).toFixed(2)} MB RSS`)
}
}
console.log('\n🔍 Testing search operations...')
const searchResults = await brain.search('programming', 5)
console.log(`✅ Search completed: found ${searchResults.length} results`)
console.log('\n🧠 Testing Brain Patterns...')
const filteredResults = await brain.search('*', 10, {
metadata: { category: 'tech' }
})
console.log(`✅ Brain Patterns completed: found ${filteredResults.length} results`)
console.log('\n📊 Final memory usage:')
const endMem = process.memoryUsage()
console.log(` Heap Used: ${(endMem.heapUsed / 1024 / 1024).toFixed(2)} MB`)
console.log(` RSS: ${(endMem.rss / 1024 / 1024).toFixed(2)} MB`)
console.log(` Heap Growth: ${((endMem.heapUsed - startMem.heapUsed) / 1024 / 1024).toFixed(2)} MB`)
// Get memory manager stats if available
try {
const { getEmbeddingMemoryStats } = await import('./dist/embeddings/universal-memory-manager.js')
const stats = getEmbeddingMemoryStats()
console.log('\n🔧 Memory Manager Stats:')
console.log(` Strategy: ${stats.strategy}`)
console.log(` Embeddings: ${stats.embeddings}`)
console.log(` Restarts: ${stats.restarts}`)
console.log(` Memory: ${stats.memoryUsage}`)
} catch (error) {
console.log('\n⚠ Memory stats not available')
}
console.log('\n✅ All tests completed without crashes!')
console.log('🎉 Memory-safe system is working correctly')
return true
} catch (error) {
console.error('\n❌ Test failed:', error.message)
console.error(error.stack)
return false
}
}
// Run test
async function main() {
const success = await testMemorySafety()
if (success) {
console.log('\n🚀 SUCCESS: Memory-safe Brainy is ready for production!')
process.exit(0)
} else {
console.log('\n💥 FAILURE: Memory issues detected')
process.exit(1)
}
}
main()