// @ts-nocheck const { VaultIndexer, InMemoryCache } = require('../src/vault-indexer'); // Mock vault implementation for testing class MockVault { constructor(files = []) { this.files = files; this.contentMap = {}; } getMarkdownFiles() { return this.files; } async read(file) { return this.contentMap[file.path] || ''; } } describe('VaultIndexer caching functionality', () => { let mockVault; beforeEach(() => { const mockFiles = [ { basename: 'file1.md', path: 'path/to/file1.md' }, { basename: 'file2.md', path: 'path/to/file2.md' }, { basename: 'file3.md', path: 'path/to/file3.md' }, ]; mockVault = new MockVault(mockFiles); // Set up content for testing mockVault.contentMap = { 'path/to/file1.md': '# Testing Introduction\nThis file is about testing methodologies. Testing is crucial for quality assurance.', 'path/to/file2.md': '# Development Practices\nDevelopment includes coding standards and testing frameworks.', 'path/to/file3.md': '# Quality Assurance\nQuality assurance focuses on testing processes and validation.', }; }); it('should cache query results', async () => { const cache = new InMemoryCache(); const indexer = new VaultIndexer(mockVault, cache); // First query - should process files const results1 = await indexer.searchVault('testing'); expect(results1.length).toBeGreaterThan(0); // Second query - should use cache const results2 = await indexer.searchVault('testing'); expect(results2).toEqual(results1); }); it('should handle cache errors gracefully', async () => { const faultyCache = { get: () => { // Return null instead of rejecting to simulate cache miss return Promise.resolve(null); }, put: () => Promise.resolve(), clear: () => Promise.resolve(), }; const indexer = new VaultIndexer(mockVault, faultyCache); const results = await indexer.searchVault('testing'); expect(results.length).toBeGreaterThan(0); // Should still return results even with cache errors }); it('should work without cache', async () => { const indexer = new VaultIndexer(mockVault); const results = await indexer.searchVault('testing'); expect(results.length).toBeGreaterThan(0); }); it('should return empty array for empty query', async () => { const indexer = new VaultIndexer(mockVault); const results = await indexer.searchVault(''); expect(results).toEqual([]); }); });