UNPKG

devin-workflow

Version:

~Devin AI workflow automation

167 lines (130 loc) • 5.17 kB
#!/usr/bin/env node import { TestRunner } from './test-runner.js'; import { spawn } from 'child_process'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); class TestFlow { constructor() { this.mockServer = null; } async startMockServer() { console.log('šŸ”§ Starting Mock Devin API Server...'); return new Promise((resolve, reject) => { const mockServerPath = join(__dirname, 'mock-devin-api.js'); this.mockServer = spawn('node', [mockServerPath], { stdio: ['inherit', 'pipe', 'pipe'] }); this.mockServer.stdout.on('data', (data) => { const output = data.toString(); console.log(`šŸ“” Mock API: ${output.trim()}`); if (output.includes('Mock Devin API running')) { console.log('āœ… Mock server started successfully\n'); resolve(); } }); this.mockServer.stderr.on('data', (data) => { console.error(`Mock API Error: ${data}`); }); this.mockServer.on('error', (error) => { reject(error); }); // Give the server time to start setTimeout(() => { resolve(); }, 2000); }); } async stopMockServer() { if (this.mockServer) { console.log('\nšŸ›‘ Stopping Mock Server...'); this.mockServer.kill(); } } async runFullTest() { try { console.log('šŸš€ Starting Full MCP Server Test Flow\n'); console.log('=====================================\n'); // Start mock server await this.startMockServer(); // Wait a moment for server to be ready await this.sleep(3000); // Run all basic tests const testRunner = new TestRunner(); await testRunner.runAllTests(); console.log('\nšŸŽÆ Testing MCP Tool Integration...'); await this.testMCPTools(); console.log('\nāœ… Basic test flow completed successfully!'); console.log('\nšŸ“ Note: For complex workflow tests, run: node test/complex-workflow-tests.js'); } catch (error) { console.error('āŒ Test flow failed:', error.message); process.exit(1); } finally { await this.stopMockServer(); } } async testMCPTools() { // Test the actual MCP tools as they would be called const { WorkflowParser } = await import('../src/workflow-parser.js'); const { DevinClient } = await import('../src/devin-client.js'); const { HandoffManager } = await import('../src/handoff-manager.js'); const parser = new WorkflowParser(); const client = new DevinClient(); const handoffManager = new HandoffManager(client); // Set up mock mode client.setMockMode(true); client.setApiKey('test-key-mcp-tools'); console.log(' šŸ“‹ Testing parse_workflow tool...'); const sampleWorkflow = `## Step 1 ## - Playbook: test-flow - Prompt: Execute test workflow - Handoff: Provide test results ## Step 2 ## - RelyPreviousStep: yes - Prompt: Generate final report - Handoff: Create summary document`; const parsedSteps = parser.parse(sampleWorkflow); console.log(` āœ… Parsed ${parsedSteps.length} steps`); console.log(' šŸ”— Testing create_devin_session tool...'); const session = await client.createSession( 'Test MCP tool integration', 'test-playbook', 'MCP Integration Test' ); console.log(` āœ… Created session: ${session.session_id}`); console.log(' šŸ’¬ Testing chat_devin_session tool...'); await client.chatSession(session.session_id, 'Test message for MCP integration'); console.log(' āœ… Message sent successfully'); console.log(' šŸ“Š Testing get_session_status tool...'); const status = await client.getSession(session.session_id); console.log(` āœ… Session status: ${status.status}`); console.log(' āš™ļø Testing execute_workflow tool...'); // Use faster settings for testing handoffManager.setPollingInterval(1000); // 1 second for testing handoffManager.setTimeout(30000); // 30 seconds timeout for testing const results = await handoffManager.executeWorkflow(parsedSteps); console.log(` āœ… Executed workflow with ${results.length} steps`); // Validate that all steps completed successfully const successfulSteps = results.filter(r => r.success).length; console.log(` šŸ“Š Successful steps: ${successfulSteps}/${results.length}`); if (successfulSteps !== results.length) { throw new Error(`Only ${successfulSteps} out of ${results.length} steps completed successfully`); } } sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } } // Run the test flow if this script is executed directly if (import.meta.url === `file://${process.argv[1]}`) { const testFlow = new TestFlow(); // Handle cleanup on exit process.on('SIGINT', async () => { console.log('\nšŸ›‘ Received interrupt signal, cleaning up...'); await testFlow.stopMockServer(); process.exit(0); }); testFlow.runFullTest().catch(console.error); } export { TestFlow };