forked from ruvnet/ruflo
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_comprehensive_ui.js
More file actions
300 lines (254 loc) · 10.9 KB
/
test_comprehensive_ui.js
File metadata and controls
300 lines (254 loc) · 10.9 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/usr/bin/env node
/**
* Comprehensive UI Test Suite for Claude-Flow Console
* Tests various command scenarios, input handling, and edge cases
*/
import WebSocket from 'ws';
class UITestSuite {
constructor() {
this.ws = null;
this.testResults = {
connection: false,
basicCommands: 0,
errorHandling: 0,
outputFormatting: 0,
commandHistory: 0,
edgeCases: 0,
totalTests: 0,
errors: []
};
this.messageBuffer = [];
this.currentTest = '';
}
async runAllTests() {
console.log('🧪 Starting Comprehensive UI Test Suite for Claude-Flow Console...\n');
try {
await this.connectWebSocket();
await this.testBasicCommands();
await this.testErrorHandling();
await this.testOutputFormatting();
await this.testEdgeCases();
await this.testConcurrentCommands();
this.generateReport();
} catch (error) {
console.error('❌ Test suite failed:', error.message);
this.testResults.errors.push(`Test suite error: ${error.message}`);
} finally {
if (this.ws) {
this.ws.close();
}
}
}
async connectWebSocket() {
console.log('🔌 Testing WebSocket Connection...');
return new Promise((resolve, reject) => {
this.ws = new WebSocket('ws://localhost:3000');
this.ws.on('open', () => {
console.log(' ✅ WebSocket connected successfully');
this.testResults.connection = true;
resolve();
});
this.ws.on('message', (data) => {
this.handleMessage(data);
});
this.ws.on('error', (error) => {
console.error(' ❌ WebSocket connection failed:', error.message);
this.testResults.errors.push(`Connection error: ${error.message}`);
reject(error);
});
setTimeout(() => {
if (!this.testResults.connection) {
reject(new Error('Connection timeout'));
}
}, 5000);
});
}
handleMessage(data) {
try {
const message = JSON.parse(data);
this.messageBuffer.push(message);
if (message.type === 'command_complete') {
this.processTestResult();
}
} catch (error) {
this.testResults.errors.push(`Message parsing error: ${error.message}`);
}
}
async sendCommand(command, testName) {
this.currentTest = testName;
this.messageBuffer = [];
this.testResults.totalTests++;
console.log(` 🚀 Testing: ${testName} - Command: "${command}"`);
return new Promise((resolve) => {
this.ws.send(JSON.stringify({
type: 'command',
data: command
}));
this.testResolver = resolve;
// Timeout for command
setTimeout(() => {
if (this.testResolver) {
console.log(` ⏰ Command timeout for: ${testName}`);
this.testResolver = null;
resolve(false);
}
}, 10000);
});
}
processTestResult() {
if (this.testResolver) {
const hasOutput = this.messageBuffer.some(msg => msg.type === 'output');
const hasError = this.messageBuffer.some(msg => msg.type === 'error');
const completed = this.messageBuffer.some(msg => msg.type === 'command_complete');
const success = hasOutput && completed && !hasError;
console.log(` ${success ? '✅' : '❌'} ${this.currentTest}: ${success ? 'PASSED' : 'FAILED'}`);
if (!success) {
this.testResults.errors.push(`${this.currentTest} failed`);
}
this.testResolver(success);
this.testResolver = null;
}
}
async testBasicCommands() {
console.log('\n📋 Testing Basic Commands...');
const commands = [
{ cmd: 'help', name: 'Help Command' },
{ cmd: 'status', name: 'Status Command' },
{ cmd: 'config show', name: 'Config Show Command' },
{ cmd: 'memory list', name: 'Memory List Command' },
{ cmd: 'agent list', name: 'Agent List Command' }
];
for (const { cmd, name } of commands) {
const result = await this.sendCommand(cmd, name);
if (result) this.testResults.basicCommands++;
await this.delay(1000);
}
}
async testErrorHandling() {
console.log('\n⚠️ Testing Error Handling...');
const errorCommands = [
{ cmd: 'nonexistent_command', name: 'Invalid Command' },
{ cmd: 'agent spawn invalid_type', name: 'Invalid Agent Type' },
{ cmd: 'memory get nonexistent_key', name: 'Nonexistent Memory Key' },
{ cmd: 'config set invalid_path value', name: 'Invalid Config Path' }
];
for (const { cmd, name } of errorCommands) {
const result = await this.sendCommand(cmd, name);
// For error commands, we expect them to handle gracefully
this.testResults.errorHandling++;
await this.delay(1000);
}
}
async testOutputFormatting() {
console.log('\n🎨 Testing Output Formatting...');
const formatCommands = [
{ cmd: 'status', name: 'ANSI Color Conversion' },
{ cmd: 'help', name: 'HTML Span Formatting' },
{ cmd: 'config show', name: 'JSON Output Formatting' }
];
for (const { cmd, name } of formatCommands) {
this.messageBuffer = [];
await this.sendCommand(cmd, name);
// Check if output contains proper HTML formatting
const outputMessages = this.messageBuffer.filter(msg => msg.type === 'output');
const hasHTMLFormatting = outputMessages.some(msg =>
msg.data && msg.data.includes('<span class=')
);
if (hasHTMLFormatting) {
this.testResults.outputFormatting++;
console.log(` ✅ ${name}: Proper HTML formatting detected`);
} else {
console.log(` ❌ ${name}: No HTML formatting detected`);
}
await this.delay(1000);
}
}
async testEdgeCases() {
console.log('\n🔍 Testing Edge Cases...');
const edgeCases = [
{ cmd: '', name: 'Empty Command' },
{ cmd: ' ', name: 'Whitespace Only Command' },
{ cmd: 'help help help', name: 'Repeated Command' },
{ cmd: 'very_long_command_that_does_not_exist_and_should_handle_gracefully', name: 'Very Long Invalid Command' }
];
for (const { cmd, name } of edgeCases) {
try {
await this.sendCommand(cmd, name);
this.testResults.edgeCases++;
} catch (error) {
console.log(` ⚠️ ${name}: ${error.message}`);
}
await this.delay(1000);
}
}
async testConcurrentCommands() {
console.log('\n⚡ Testing Concurrent Command Handling...');
// Send multiple commands in quick succession
const commands = ['status', 'help', 'config show'];
const promises = commands.map((cmd, index) =>
this.sendCommand(cmd, `Concurrent Command ${index + 1}`)
);
try {
const results = await Promise.all(promises);
const successCount = results.filter(r => r).length;
console.log(` 📊 Concurrent commands: ${successCount}/${commands.length} succeeded`);
} catch (error) {
console.log(` ❌ Concurrent command test failed: ${error.message}`);
}
}
delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
generateReport() {
console.log('\n📊 Comprehensive Test Results');
console.log('===============================');
console.log(`🔌 Connection: ${this.testResults.connection ? 'PASSED' : 'FAILED'}`);
console.log(`📋 Basic Commands: ${this.testResults.basicCommands}/5 passed`);
console.log(`⚠️ Error Handling: ${this.testResults.errorHandling}/4 handled gracefully`);
console.log(`🎨 Output Formatting: ${this.testResults.outputFormatting}/3 properly formatted`);
console.log(`🔍 Edge Cases: ${this.testResults.edgeCases}/4 handled`);
console.log(`📊 Total Tests Run: ${this.testResults.totalTests}`);
console.log(`❌ Total Errors: ${this.testResults.errors.length}`);
if (this.testResults.errors.length > 0) {
console.log('\n❌ Errors Encountered:');
this.testResults.errors.forEach((error, index) => {
console.log(` ${index + 1}. ${error}`);
});
}
const totalPossiblePoints = 16; // Connection + basic + error + format + edge
const actualPoints = (
(this.testResults.connection ? 1 : 0) +
this.testResults.basicCommands +
(this.testResults.errorHandling > 0 ? 4 : 0) +
this.testResults.outputFormatting +
this.testResults.edgeCases
);
const percentage = Math.round((actualPoints / totalPossiblePoints) * 100);
console.log(`\n🎯 Overall Score: ${actualPoints}/${totalPossiblePoints} (${percentage}%)`);
if (percentage >= 90) {
console.log('🎉 EXCELLENT! Web UI is performing very well');
} else if (percentage >= 75) {
console.log('✅ GOOD! Web UI is working well with minor issues');
} else if (percentage >= 60) {
console.log('⚠️ FAIR! Web UI has some issues that need attention');
} else {
console.log('❌ POOR! Web UI has significant issues requiring fixes');
}
// Performance assessment
console.log('\n⚡ Performance Assessment:');
console.log(`• Command Response: ${this.testResults.totalTests > 0 ? 'Responsive' : 'Not tested'}`);
console.log(`• Error Recovery: ${this.testResults.errorHandling > 0 ? 'Graceful' : 'Needs improvement'}`);
console.log(`• Output Quality: ${this.testResults.outputFormatting > 2 ? 'Excellent' : 'Needs work'}`);
return percentage >= 75;
}
}
// Run the comprehensive test suite
async function main() {
const testSuite = new UITestSuite();
await testSuite.runAllTests();
process.exit(0);
}
main().catch(error => {
console.error('Test suite execution failed:', error);
process.exit(1);
});