devin-workflow
Version:
~Devin AI workflow automation
167 lines (130 loc) ⢠5.17 kB
JavaScript
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 };