Skip to main content
Glama
vector-search-channel-mocked.test.ts4.14 kB
/** * VectorSearchChannel - Mock-based Tests * Tests without requiring actual GDS plugin */ import { describe, it, expect, beforeEach, vi } from 'vitest'; import { VectorSearchChannel } from '../../../../src/infrastructure/services/search/vector-search-channel'; describe('VectorSearchChannel - Mock Tests', () => { let channel: VectorSearchChannel; let mockSession: any; beforeEach(() => { mockSession = { run: vi.fn() }; channel = new VectorSearchChannel(mockSession); }); describe('GDS Detection Logic', () => { it('should require GDS for vector operations', async () => { // Mock GDS check to fail mockSession.run.mockRejectedValueOnce(new Error('GDS not available')); await expect(channel.search('test query', 10, 0.5)) .rejects.toThrow('Neo4j Graph Data Science (GDS) plugin is required'); }); it('should provide setup instructions when GDS unavailable', async () => { mockSession.run.mockRejectedValueOnce(new Error('Unknown function')); await expect(channel.search('test', 10, 0.5)) .rejects.toThrow('Neo4j Graph Data Science (GDS) plugin'); }); }); describe('GDS Verification Status', () => { it('should track GDS verification status', () => { // Initially should be null (not checked yet) expect(channel.isGDSVerified()).toBe(null); }); it('should handle invalid GDS responses', async () => { // Mock invalid response from GDS check mockSession.run.mockResolvedValueOnce({ records: [{ get: () => null }] }); await expect(channel.search('test', 10, 0.5)) .rejects.toThrow('Neo4j Graph Data Science (GDS) plugin'); }); }); describe('Query Construction Logic', () => { it('should construct proper GDS queries when available', async () => { // Mock successful GDS verification mockSession.run .mockResolvedValueOnce({ records: [{ get: () => 0.5 }] }) // GDS check .mockResolvedValueOnce({ records: [] }); // Search query // Mock embedding calculation const mockCalculateEmbedding = vi.fn().mockResolvedValue([0.1, 0.2, 0.3]); vi.doMock('../../../../src/infrastructure/utilities', () => ({ calculateEmbedding: mockCalculateEmbedding })); try { await channel.search('test', 10, 0.5); // Should have called the search query with GDS functions expect(mockSession.run).toHaveBeenCalledWith( expect.stringContaining('gds.similarity.cosine'), expect.objectContaining({ queryVector: [0.1, 0.2, 0.3], threshold: 0.5, limit: expect.any(Object) }) ); } catch (error) { // Expected to fail in test environment expect(error).toBeDefined(); } }); it('should include memory type filtering in queries', async () => { mockSession.run .mockResolvedValueOnce({ records: [{ get: () => 0.8 }] }) // GDS check .mockResolvedValueOnce({ records: [] }); // Search query try { await channel.search('test', 5, 0.3, ['project', 'note']); expect(mockSession.run).toHaveBeenCalledWith( expect.stringContaining('WHERE m.memoryType IN $memoryTypes'), expect.objectContaining({ memoryTypes: ['project', 'note'] }) ); } catch (error) { // Expected to fail without actual GDS expect(error).toBeDefined(); } }); }); describe('Zero-Fallback Architecture', () => { it('should fail fast rather than provide degraded service', async () => { mockSession.run.mockRejectedValue(new Error('GDS unavailable')); await expect(channel.search('test', 10, 0.5)) .rejects.toThrow('Neo4j Graph Data Science (GDS) plugin is required'); }); it('should not attempt in-memory fallbacks', async () => { mockSession.run.mockRejectedValue(new Error('Function not found')); await expect(channel.search('test', 10, 0.5)) .rejects.toThrow('Neo4j Graph Data Science (GDS) plugin'); }); }); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sylweriusz/mcp-neo4j-memory-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server