brainy/test-infinite-loop.js
David Snelling 4ba22f95bc fix: prevent infinite loop in pagination when storage returns phantom items
- Fix FileSystemStorage counting non-existent files in totalCount
- Add safety check in BaseStorage to prevent hasMore:true with empty items
- Ensure pagination terminates correctly even with corrupted storage state
2025-09-16 10:35:07 -07:00

47 lines
No EOL
927 B
JavaScript

import { Brainy } from './dist/index.js';
import fs from 'fs/promises';
async function test() {
// Clean up any existing test data
const testDir = './.test-brainy';
try {
await fs.rm(testDir, { recursive: true });
} catch (e) {
// Ignore if doesn't exist
}
console.log('Testing Brainy initialization...');
const brain = new Brainy({
storage: {
type: 'filesystem',
options: {
path: testDir
}
},
model: {
type: 'accurate' // Same as Sage
},
cache: true,
verbose: false,
silent: true
});
console.log('Calling brain.init()...');
try {
await brain.init();
console.log('✅ Initialization completed successfully!');
} catch (error) {
console.error('❌ Initialization failed:', error);
}
// Clean up
try {
await fs.rm(testDir, { recursive: true });
} catch (e) {
// Ignore
}
}
test().catch(console.error);