csvlod-ai-mcp-server
Version:
CSVLOD-AI MCP Server v3.0 with Quantum Context Intelligence - Revolutionary Context Intelligence Engine and Multimodal Processor for sovereign AI development
278 lines (215 loc) • 9.37 kB
text/typescript
import { jest } from '@jest/globals';
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { CSVLODContext } from '../src/context.js';
import { CSVLODValidator } from '../src/validator.js';
import { CSVLODGenerator } from '../src/generator.js';
describe('CSVLOD-AI MCP Server Components', () => {
describe('Context Management', () => {
let context: CSVLODContext;
beforeEach(() => {
context = new CSVLODContext();
});
test('should initialize context without errors', () => {
expect(() => new CSVLODContext()).not.toThrow();
});
test('should initialize project context', async () => {
const tempPath = '/tmp/test-context-' + Date.now();
const result = await context.initialize(tempPath, 'basic');
expect(result).toBeDefined();
expect(result.filesCreated).toBeDefined();
expect(result.summary).toBeDefined();
expect(result.filesCreated.length).toBeGreaterThan(0);
});
test('should handle different project types', async () => {
const types: ('basic' | 'enterprise' | 'minimal')[] = ['basic', 'enterprise', 'minimal'];
for (const type of types) {
const tempPath = `/tmp/test-${type}-${Date.now()}`;
const result = await context.initialize(tempPath, type);
expect(result.filesCreated.length).toBeGreaterThan(0);
}
});
});
describe('Validation System', () => {
let validator: CSVLODValidator;
beforeEach(() => {
validator = new CSVLODValidator();
});
test('should validate CSVLOD compliance', async () => {
const result = await validator.validate('.', { strict: false });
expect(result).toBeDefined();
expect(result.score).toBeGreaterThanOrEqual(0);
expect(result.score).toBeLessThanOrEqual(100);
expect(result.issues).toBeDefined();
});
test('should handle missing directories gracefully', async () => {
const result = await validator.validate('/nonexistent/path', { strict: false });
expect(result.valid).toBe(false);
expect(result.issues.length).toBeGreaterThan(0);
});
test('should provide detailed validation metrics', async () => {
const result = await validator.validate('.', { strict: true });
expect(result.issues).toBeDefined();
expect(result.suggestions).toBeDefined();
expect(Array.isArray(result.issues)).toBe(true);
expect(Array.isArray(result.suggestions)).toBe(true);
});
});
describe('Generator System', () => {
let generator: CSVLODGenerator;
beforeEach(() => {
generator = new CSVLODGenerator();
});
test('should create generator instance', () => {
expect(generator).toBeDefined();
expect(generator).toBeInstanceOf(CSVLODGenerator);
});
test('should have generation capabilities', () => {
// Test basic generator functionality
expect(typeof generator).toBe('object');
});
});
describe('MCP Server Integration', () => {
let server: Server;
beforeEach(() => {
server = new Server(
{ name: 'csvlod-ai-test', version: '0.1.0' },
{ capabilities: { tools: {} } }
);
});
afterEach(() => {
// Cleanup server if needed
if (server) {
// Server cleanup would go here
}
});
test('should create server instance', () => {
expect(server).toBeDefined();
expect(server).toBeInstanceOf(Server);
});
test('should handle tool registration', () => {
// Test tool registration process - this would be done in actual server implementation
expect(server).toBeDefined();
// Note: In actual MCP server, tool registration happens in index.ts
// This test just verifies server instance creation
});
});
describe('Performance Tests', () => {
test('context initialization should complete within 5 seconds', async () => {
const context = new CSVLODContext();
const start = Date.now();
const tempPath = '/tmp/perf-test-' + Date.now();
await context.initialize(tempPath, 'basic');
const duration = Date.now() - start;
expect(duration).toBeLessThan(5000);
});
test('validation should complete within 3 seconds', async () => {
const validator = new CSVLODValidator();
const start = Date.now();
await validator.validate('.', { strict: false });
const duration = Date.now() - start;
expect(duration).toBeLessThan(3000);
});
});
describe('Sovereignty Features', () => {
test('should maintain local-first architecture', async () => {
const context = new CSVLODContext();
const tempPath = '/tmp/sovereignty-test-' + Date.now();
const result = await context.initialize(tempPath, 'basic');
// Verify files are created locally
expect(result.filesCreated.every(file => file.startsWith(tempPath))).toBe(true);
});
test('should provide validation scoring', async () => {
const validator = new CSVLODValidator();
const result = await validator.validate('.', { strict: false });
expect(result.score).toBeGreaterThanOrEqual(0);
expect(result.score).toBeLessThanOrEqual(100);
});
test('should track file creation', async () => {
const context = new CSVLODContext();
const tempPath = '/tmp/tracking-test-' + Date.now();
const result = await context.initialize(tempPath, 'enterprise');
expect(result.filesCreated).toBeDefined();
expect(result.filesCreated.length).toBeGreaterThan(0);
expect(result.summary).toBeDefined();
});
});
describe('Error Handling', () => {
test('should handle invalid project paths', async () => {
const validator = new CSVLODValidator();
const result = await validator.validate('/invalid/path', { strict: false });
expect(result.valid).toBe(false);
expect(result.issues.length).toBeGreaterThan(0);
});
test('should handle permission errors gracefully', async () => {
const context = new CSVLODContext();
// Try to initialize in root directory (should handle gracefully)
try {
await context.initialize('/root/test', 'basic');
} catch (error) {
expect(error).toBeDefined();
}
});
test('should validate input parameters', async () => {
const validator = new CSVLODValidator();
// Empty path should be handled
const result = await validator.validate('', { strict: false });
expect(result.valid).toBe(false);
expect(result.issues.length).toBeGreaterThan(0);
});
});
describe('Integration Scenarios', () => {
test('should handle complete project setup workflow', async () => {
const tempPath = '/tmp/integration-test-' + Date.now();
// Step 1: Initialize project
const context = new CSVLODContext();
const initResult = await context.initialize(tempPath, 'basic');
expect(initResult.filesCreated.length).toBeGreaterThan(0);
// Step 2: Validate project
const validator = new CSVLODValidator();
const validationResult = await validator.validate(tempPath, { strict: false });
expect(validationResult.score).toBeGreaterThan(0);
});
test('should handle enterprise setup with enhanced features', async () => {
const tempPath = '/tmp/enterprise-test-' + Date.now();
const context = new CSVLODContext();
const result = await context.initialize(tempPath, 'enterprise');
expect(result.filesCreated.length).toBeGreaterThan(0);
expect(result.summary).toContain('enterprise');
});
test('should handle minimal setup for lightweight projects', async () => {
const tempPath = '/tmp/minimal-test-' + Date.now();
const context = new CSVLODContext();
const result = await context.initialize(tempPath, 'minimal');
expect(result.filesCreated.length).toBeGreaterThan(0);
expect(result.summary).toContain('minimal');
});
});
describe('Real-world Usage', () => {
test('should create valid CSVLOD structure', async () => {
const tempPath = '/tmp/real-world-' + Date.now();
const context = new CSVLODContext();
const initResult = await context.initialize(tempPath, 'basic');
// Verify key files are created
const expectedFiles = [
'AI-CONTEXT.md',
'AGENT-MANIFEST.yaml'
];
expectedFiles.forEach(file => {
expect(initResult.filesCreated.some(created => created.includes(file))).toBe(true);
});
});
test('should provide actionable validation feedback', async () => {
const validator = new CSVLODValidator();
const result = await validator.validate('.', { strict: true });
expect(result.issues).toBeDefined();
expect(result.suggestions).toBeDefined();
// Each issue should have required properties
result.issues.forEach(issue => {
expect(issue.severity).toMatch(/^(error|warning|info)$/);
expect(issue.category).toBeDefined();
expect(issue.message).toBeDefined();
});
});
});
});