forked from ruvnet/ruflo
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_output_streaming.js
More file actions
132 lines (106 loc) · 5.11 KB
/
test_output_streaming.js
File metadata and controls
132 lines (106 loc) · 5.11 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
#!/usr/bin/env node
/**
* Output Streaming Test for Claude-Flow Console
* Tests real-time output streaming and ANSI color conversion
*/
import WebSocket from 'ws';
async function testOutputStreaming() {
console.log('🎨 Testing Output Streaming and ANSI Color Conversion...\n');
return new Promise((resolve) => {
const ws = new WebSocket('ws://localhost:3000');
const testResults = {
streamingWorks: false,
ansiConversion: false,
htmlFormatting: false,
realTimeDelivery: false,
outputMessages: [],
timestamps: []
};
ws.on('open', () => {
console.log('✅ Connected to WebSocket');
// Send a command that should produce formatted output
console.log('🚀 Sending command: "status"');
testResults.timestamps.push(Date.now());
ws.send(JSON.stringify({
type: 'command',
data: 'status'
}));
});
ws.on('message', (data) => {
const message = JSON.parse(data);
testResults.timestamps.push(Date.now());
if (message.type === 'output') {
testResults.outputMessages.push(message.data);
testResults.streamingWorks = true;
console.log('📨 Output received:', message.data.substring(0, 100) + '...');
// Check for ANSI conversion to HTML
if (message.data.includes('<span class=')) {
testResults.ansiConversion = true;
console.log(' ✅ ANSI to HTML conversion detected');
}
// Check for specific color classes
if (message.data.match(/<span class="(success|error|warning|info|dim)"/)) {
testResults.htmlFormatting = true;
console.log(' ✅ Proper HTML color formatting detected');
}
// Check for timestamp formatting
if (message.data.includes('<span class="dim">')) {
console.log(' ✅ Timestamp formatting detected');
}
}
if (message.type === 'command_complete') {
console.log('🏁 Command completed');
// Check real-time delivery (should be fast)
const totalTime = testResults.timestamps[testResults.timestamps.length - 1] - testResults.timestamps[0];
testResults.realTimeDelivery = totalTime < 5000; // Less than 5 seconds
console.log(`⏱️ Total response time: ${totalTime}ms`);
ws.close();
}
});
ws.on('close', () => {
console.log('\n📊 Output Streaming Test Results:');
console.log('===================================');
console.log('✅ Streaming Works:', testResults.streamingWorks);
console.log('✅ ANSI Conversion:', testResults.ansiConversion);
console.log('✅ HTML Formatting:', testResults.htmlFormatting);
console.log('✅ Real-time Delivery:', testResults.realTimeDelivery);
console.log('📨 Output Messages:', testResults.outputMessages.length);
if (testResults.outputMessages.length > 0) {
console.log('\n🎨 Sample Formatted Output:');
console.log('----------------------------');
console.log(testResults.outputMessages[0]);
console.log('\n🔍 HTML Elements Found:');
const spans = testResults.outputMessages.join('').match(/<span class="[^"]*">/g) || [];
const uniqueClasses = [...new Set(spans.map(span => span.match(/class="([^"]*)"/)?.[1]))];
uniqueClasses.forEach(cls => console.log(` • ${cls}`));
}
const score = [
testResults.streamingWorks,
testResults.ansiConversion,
testResults.htmlFormatting,
testResults.realTimeDelivery
].filter(Boolean).length;
console.log(`\n🎯 Score: ${score}/4 streaming tests passed`);
if (score === 4) {
console.log('🎉 Output streaming is working PERFECTLY!');
} else if (score >= 3) {
console.log('✅ Output streaming is working WELL!');
} else {
console.log('⚠️ Output streaming needs improvement');
}
resolve(testResults);
});
ws.on('error', (error) => {
console.error('❌ WebSocket error:', error.message);
resolve(testResults);
});
});
}
// Run the test
testOutputStreaming().then(() => {
console.log('\n✅ Output streaming test completed');
process.exit(0);
}).catch(error => {
console.error('❌ Test failed:', error.message);
process.exit(1);
});