-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-mvp-flow.js
More file actions
177 lines (145 loc) · 5.88 KB
/
test-mvp-flow.js
File metadata and controls
177 lines (145 loc) · 5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env node
/**
* HackMate MVP Test Script
* Tests the complete autonomous flow: Problem → Plan → Code → PR → Slack
*/
import dotenv from 'dotenv';
import { TaskRunner } from './lib/core/task-runner.js';
// Load environment variables
dotenv.config({ path: '.env.local' });
async function testMVPFlow() {
console.log('🚀 Testing HackMate MVP Flow...\n');
// Check required environment variables
const requiredEnvs = {
'GEMINI_API_KEY': process.env.GEMINI_API_KEY,
'GITHUB_TOKEN': process.env.GITHUB_TOKEN,
'GITHUB_OWNER': process.env.GITHUB_OWNER,
'GITHUB_REPO': process.env.GITHUB_REPO,
'SLACK_WEBHOOK_URL': process.env.SLACK_WEBHOOK_URL
};
console.log('📋 Environment Check:');
for (const [key, value] of Object.entries(requiredEnvs)) {
const status = value ? '✅' : '❌';
const display = value ? `${value.substring(0, 10)}...` : 'Not set';
console.log(` ${status} ${key}: ${display}`);
}
console.log();
// Initialize TaskRunner
const taskRunner = new TaskRunner({
enableAI: !!process.env.GEMINI_API_KEY,
enableGitHub: !!(process.env.GITHUB_TOKEN && process.env.GITHUB_OWNER && process.env.GITHUB_REPO),
enableSlack: !!process.env.SLACK_WEBHOOK_URL,
enableMemory: true
});
try {
// Initialize the system
console.log('🔧 Initializing TaskRunner...');
await taskRunner.initialize();
console.log('✅ TaskRunner initialized\n');
// Check agent status
console.log('🤖 Agent Status:');
const status = taskRunner.getAgentStatus();
for (const [agent, info] of Object.entries(status)) {
if (typeof info === 'object' && info.name) {
const statusIcon = info.status === 'ready' ? '✅' : '❌';
console.log(` ${statusIcon} ${info.name}: ${info.status}`);
// Show capabilities
if (info.capabilities) {
console.log(` Capabilities: ${info.capabilities.join(', ')}`);
}
// Show integration status
if (info.aiEnabled !== undefined) {
console.log(` AI: ${info.aiEnabled ? '✅' : '❌'}`);
}
if (info.githubEnabled !== undefined) {
console.log(` GitHub: ${info.githubEnabled ? '✅' : '❌'}`);
}
if (info.slackEnabled !== undefined) {
console.log(` Slack: ${info.slackEnabled ? '✅' : '❌'}`);
}
}
}
console.log();
// Test the autonomous flow
console.log('🎯 Starting Autonomous Flow Test...');
const testProblem = "Add a /health endpoint to check server status";
console.log(`Problem: "${testProblem}"\n`);
// Create tasks from problem
console.log('📝 Creating tasks from problem...');
const taskId = await taskRunner.createTaskFromProblem(testProblem);
console.log(`✅ Tasks created, starting with: ${taskId}\n`);
// Monitor task execution
console.log('⏳ Monitoring task execution...');
let attempts = 0;
const maxAttempts = 30; // 30 seconds timeout
while (attempts < maxAttempts) {
const tasks = await taskRunner.getAllTasks();
const inProgress = tasks.filter(t => t.status === 'in_progress').length;
const completed = tasks.filter(t => t.status === 'done').length;
const failed = tasks.filter(t => t.status === 'failed').length;
const queued = tasks.filter(t => t.status === 'queued').length;
console.log(` 📊 Status: ${queued} queued, ${inProgress} in progress, ${completed} completed, ${failed} failed`);
// Show recent logs
const recentTask = tasks.find(t => t.status === 'in_progress' || (t.logs.length > 1 && t.updatedAt));
if (recentTask && recentTask.logs.length > 0) {
const lastLog = recentTask.logs[recentTask.logs.length - 1];
console.log(` 📝 Latest: ${recentTask.title} - ${lastLog}`);
}
// Check if all tasks are done or failed
if (inProgress === 0 && queued === 0) {
console.log('\n🎉 All tasks completed!');
break;
}
await new Promise(resolve => setTimeout(resolve, 1000));
attempts++;
}
// Final status report
console.log('\n📊 Final Results:');
const finalTasks = await taskRunner.getAllTasks();
for (const task of finalTasks) {
const statusIcon = {
'done': '✅',
'failed': '❌',
'in_progress': '⏳',
'queued': '📋'
}[task.status] || '❓';
console.log(` ${statusIcon} ${task.title} (${task.agent})`);
// Show PR URL if available
if (task.metadata?.result?.prUrl) {
console.log(` 🔗 PR: ${task.metadata.result.prUrl}`);
}
// Show last log entry
if (task.logs.length > 0) {
console.log(` 📝 ${task.logs[task.logs.length - 1]}`);
}
}
// Success metrics
const completedTasks = finalTasks.filter(t => t.status === 'done').length;
const totalTasks = finalTasks.length;
const successRate = totalTasks > 0 ? (completedTasks / totalTasks * 100).toFixed(1) : '0';
console.log(`\n🎯 Success Rate: ${successRate}% (${completedTasks}/${totalTasks} tasks completed)`);
// Check for PR creation
const coderTasks = finalTasks.filter(t => t.agent === 'coder' && t.status === 'done');
const prsCreated = coderTasks.filter(t => t.metadata?.result?.prUrl).length;
if (prsCreated > 0) {
console.log(`🚀 GitHub PRs Created: ${prsCreated}`);
coderTasks.forEach(task => {
if (task.metadata?.result?.prUrl) {
console.log(` - ${task.metadata.result.prUrl}`);
}
});
}
console.log('\n✅ MVP Flow Test Complete!');
} catch (error) {
console.error('❌ Test failed:', error.message);
console.error(error.stack);
} finally {
// Cleanup
await taskRunner.shutdown();
}
}
// Run the test
if (import.meta.url === `file://${process.argv[1]}`) {
testMVPFlow().catch(console.error);
}
export { testMVPFlow };