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
This commit is contained in:
parent
8f7eed05e0
commit
5f10f8d9ab
10 changed files with 340 additions and 22 deletions
47
test-infinite-loop.js
Normal file
47
test-infinite-loop.js
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
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);
|
||||
Loading…
Add table
Add a link
Reference in a new issue