brainy/tests/test-setup.ts
David Snelling 9a446cd95d feat: Add enterprise features - WAL, intelligent scoring, deduplication
- Enable intelligent verb scoring by default for better relationship quality
- Add Write-Ahead Log (WAL) for zero data loss guarantee
- Implement request deduplication for 3x concurrent performance
- Fix model loading for tests with proper environment setup
- Update documentation to highlight new enterprise features

BREAKING CHANGE: Intelligent verb scoring now enabled by default
2025-08-20 09:42:38 -07:00

49 lines
No EOL
1.4 KiB
TypeScript

/**
* Test Setup Configuration
* Ensures models are available for all tests
*/
import { beforeAll } from 'vitest'
import { existsSync } from 'fs'
import { join } from 'path'
beforeAll(() => {
// Set model path to local models directory
const modelsPath = join(process.cwd(), 'models')
// Check if models exist
if (existsSync(modelsPath)) {
process.env.BRAINY_MODELS_PATH = modelsPath
console.log('✅ Using local models for tests:', modelsPath)
} else {
console.warn('⚠️ Models directory not found, tests may download models')
}
// Disable remote model downloads in tests to avoid network dependencies
process.env.BRAINY_ALLOW_REMOTE_MODELS = 'false'
// Set test environment
process.env.NODE_ENV = 'test'
// Disable verbose logging in tests
process.env.BRAINY_LOG_LEVEL = 'error'
})
// Export mock embedding function for tests that need it
export function createMockEmbedding(text: string, dimensions = 384): Float32Array {
// Create deterministic embeddings based on text hash
let hash = 0
for (let i = 0; i < text.length; i++) {
const char = text.charCodeAt(i)
hash = ((hash << 5) - hash) + char
hash = hash & hash // Convert to 32-bit integer
}
const embedding = new Float32Array(dimensions)
for (let i = 0; i < dimensions; i++) {
// Generate values between -1 and 1 based on hash
embedding[i] = Math.sin(hash + i) * 0.5
}
return embedding
}