UNPKG

php-universal-mcp-server

Version:

Servidor MCP universal para desenvolvimento PHP e criação de sites em qualquer provedor de hospedagem

123 lines (103 loc) 3.39 kB
/** * Testes para o PHP Universal MCP Server */ const { createServer, MCPServer } = require('../src'); describe('MCPServer', () => { let server; beforeEach(() => { server = createServer({ mode: 'offline', // Garante que os testes rodem em modo offline apiKey: '', providerType: 'mock' }); }); afterEach(() => { if (server && server.state.isRunning) { server.stop(); } }); test('deve criar uma instância válida do MCPServer', () => { expect(server).toBeInstanceOf(MCPServer); }); test('deve iniciar o servidor corretamente', () => { const result = server.start(); expect(result.status).toBe('running'); expect(server.state.isRunning).toBe(true); }); test('deve parar o servidor corretamente', () => { server.start(); const result = server.stop(); expect(result.status).toBe('stopped'); expect(server.state.isRunning).toBe(false); }); test('deve responder ao comando status', () => { server.start(); const result = server.processCommand({ type: 'status' }); expect(result.status).toBe('success'); expect(result.serverStatus).toBe('running'); }); test('deve executar comandos corretamente', () => { server.start(); const result = server.processCommand({ type: 'execute', payload: { action: 'createSite', domain: 'test.com' } }); expect(result.status).toBe('success'); expect(result.sessionId).toBeDefined(); expect(result.result).toBeDefined(); }); test('deve rejeitar comandos quando o servidor estiver parado', () => { // Não inicia o servidor const result = server.processCommand({ type: 'status' }); expect(result.status).toBe('error'); expect(result.error).toBe('Server not running'); }); test('deve rejeitar comandos inválidos', () => { server.start(); const result = server.processCommand({ type: 'invalidCommand' }); expect(result.status).toBe('error'); expect(result.error).toContain('Unsupported MCP command'); }); test('deve permitir registrar handlers personalizados', () => { server.start(); // Registra um handler personalizado server.registerHandler('customCommand', () => ({ status: 'success', message: 'Custom command executed' })); // Executa o comando personalizado const result = server.processCommand({ type: 'customCommand' }); expect(result.status).toBe('success'); expect(result.message).toBe('Custom command executed'); }); test('deve iniciar streams corretamente', () => { server.start(); const result = server.processCommand({ type: 'stream', payload: { action: 'deployFiles', files: ['test.php'] } }); expect(result.status).toBe('success'); expect(result.sessionId).toBeDefined(); }); test('deve cancelar sessões corretamente', () => { server.start(); // Inicia um stream const streamResult = server.processCommand({ type: 'stream', payload: { action: 'test' } }); // Cancela o stream const cancelResult = server.processCommand({ type: 'cancel', payload: { sessionId: streamResult.sessionId } }); expect(cancelResult.status).toBe('success'); expect(server.state.activeSessions.has(streamResult.sessionId)).toBe(false); }); });