Skip to main content
Glama
KnowledgeGraphManagerEnhancedRelations.test.ts2.81 kB
/** * Test file for KnowledgeGraphManager with enhanced relations */ import { describe, it, expect, vi } from 'vitest'; import { KnowledgeGraphManager, Relation } from '../KnowledgeGraphManager.js'; import { StorageProvider } from '../storage/StorageProvider.js'; import type { RelationMetadata } from '../types/relation.js'; describe('KnowledgeGraphManager with Enhanced Relations', () => { it('should use StorageProvider getRelation for retrieving a relation', async () => { const timestamp = Date.now(); const enhancedRelation: Relation = { from: 'entity1', to: 'entity2', relationType: 'knows', strength: 0.8, confidence: 0.9, metadata: { createdAt: timestamp, updatedAt: timestamp, inferredFrom: [], // Correct property according to RelationMetadata lastAccessed: timestamp, }, }; const mockProvider: Partial<StorageProvider> = { loadGraph: vi.fn(), saveGraph: vi.fn(), searchNodes: vi.fn(), openNodes: vi.fn(), createRelations: vi.fn(), addObservations: vi.fn(), getRelation: vi.fn().mockResolvedValue(enhancedRelation), }; const manager = new KnowledgeGraphManager({ storageProvider: mockProvider as StorageProvider }); // Call getRelation method const relation = await manager.getRelation('entity1', 'entity2', 'knows'); // Verify the provider's getRelation was called with the right parameters expect(mockProvider.getRelation).toHaveBeenCalledWith('entity1', 'entity2', 'knows'); // Verify we got the expected relation back expect(relation).toEqual(enhancedRelation); }); it('should use StorageProvider updateRelation for updating a relation', async () => { const timestamp = Date.now(); const updatedRelation: Relation = { from: 'entity1', to: 'entity2', relationType: 'knows', strength: 0.9, // Updated strength confidence: 0.95, // Updated confidence metadata: { createdAt: timestamp, updatedAt: timestamp + 1000, // Updated timestamp inferredFrom: [], lastAccessed: timestamp, }, }; const mockProvider: Partial<StorageProvider> = { loadGraph: vi.fn(), saveGraph: vi.fn(), searchNodes: vi.fn(), openNodes: vi.fn(), createRelations: vi.fn(), addObservations: vi.fn(), updateRelation: vi.fn().mockResolvedValue(undefined), }; const manager = new KnowledgeGraphManager({ storageProvider: mockProvider as StorageProvider }); // Call updateRelation method await manager.updateRelation(updatedRelation); // Verify the provider's updateRelation was called with the right parameters expect(mockProvider.updateRelation).toHaveBeenCalledWith(updatedRelation); }); });

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/gannonh/memento-mcp'

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