agentgui 1.0.453 → 1.0.455

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,277 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * WebSocket Optimization Integration Test
4
- *
5
- * Verifies all Wave 4 Item 4.2 requirements:
6
- * - Subscription-based broadcasting
7
- * - Message batching (streaming_progress)
8
- * - Compression for large payloads
9
- * - Priority queue (high/normal/low)
10
- * - Rate limiting (100 msg/sec)
11
- * - Message deduplication
12
- * - Bandwidth monitoring
13
- */
14
-
15
- import fs from 'fs';
16
- import { WSOptimizer } from './lib/ws-optimizer.js';
17
-
18
- console.log('=== WebSocket Optimization Integration Test ===\n');
19
-
20
- let testsPassed = 0;
21
- let testsFailed = 0;
22
-
23
- function pass(testName, details = []) {
24
- console.log(`✓ ${testName}`);
25
- details.forEach(d => console.log(` ${d}`));
26
- console.log();
27
- testsPassed++;
28
- }
29
-
30
- function fail(testName, reason) {
31
- console.log(`✗ ${testName}`);
32
- console.log(` Reason: ${reason}\n`);
33
- testsFailed++;
34
- }
35
-
36
- // Test 1: WSOptimizer class exists and is properly structured
37
- console.log('Test 1: Verifying WSOptimizer class structure...');
38
- try {
39
- const optimizer = new WSOptimizer();
40
- if (typeof optimizer.sendToClient === 'function' &&
41
- typeof optimizer.removeClient === 'function' &&
42
- typeof optimizer.getStats === 'function') {
43
- pass('WSOptimizer class structure', [
44
- 'sendToClient method: present',
45
- 'removeClient method: present',
46
- 'getStats method: present'
47
- ]);
48
- } else {
49
- fail('WSOptimizer class structure', 'Missing required methods');
50
- }
51
- } catch (error) {
52
- fail('WSOptimizer class structure', error.message);
53
- }
54
-
55
- // Test 2: Priority queue implementation
56
- console.log('Test 2: Verifying priority queue implementation...');
57
- const optimizerCode = fs.readFileSync('./lib/ws-optimizer.js', 'utf8');
58
-
59
- const priorityChecks = {
60
- highPriority: optimizerCode.includes('this.highPriority'),
61
- normalPriority: optimizerCode.includes('this.normalPriority'),
62
- lowPriority: optimizerCode.includes('this.lowPriority'),
63
- getPriority: optimizerCode.includes('function getPriority'),
64
- priorityLevels: optimizerCode.includes('streaming_error') &&
65
- optimizerCode.includes('streaming_progress') &&
66
- optimizerCode.includes('model_download_progress')
67
- };
68
-
69
- if (Object.values(priorityChecks).every(v => v)) {
70
- pass('Priority queue implementation', [
71
- 'High priority queue: present',
72
- 'Normal priority queue: present',
73
- 'Low priority queue: present',
74
- 'Priority classification: present',
75
- 'Message types classified: errors (high), progress (normal), downloads (low)'
76
- ]);
77
- } else {
78
- fail('Priority queue implementation', 'Missing priority queue components');
79
- }
80
-
81
- // Test 3: Batching implementation
82
- console.log('Test 3: Verifying message batching...');
83
- const batchingChecks = {
84
- scheduleFlush: optimizerCode.includes('scheduleFlush'),
85
- batchInterval: optimizerCode.includes('getBatchInterval'),
86
- maxBatchSize: optimizerCode.includes('splice(0, 10)'), // max 10 normal messages
87
- adaptiveBatching: optimizerCode.includes('BATCH_BY_TIER') &&
88
- optimizerCode.includes('latencyTier')
89
- };
90
-
91
- if (Object.values(batchingChecks).every(v => v)) {
92
- pass('Message batching', [
93
- 'Scheduled batch flushing: present',
94
- 'Adaptive batch intervals: 16-200ms based on latency',
95
- 'Max batch size: 10 normal + 5 low priority messages',
96
- 'Latency-aware batching: present'
97
- ]);
98
- } else {
99
- fail('Message batching', 'Missing batching components');
100
- }
101
-
102
- // Test 4: Compression implementation
103
- console.log('Test 4: Verifying compression...');
104
- const compressionChecks = {
105
- zlibImport: optimizerCode.includes("import zlib from 'zlib'"),
106
- gzipSync: optimizerCode.includes('gzipSync'),
107
- threshold: optimizerCode.includes('payload.length > 1024'),
108
- compressionRatio: optimizerCode.includes('compressed.length < payload.length * 0.9')
109
- };
110
-
111
- if (Object.values(compressionChecks).every(v => v)) {
112
- pass('Compression implementation', [
113
- 'zlib module imported: yes',
114
- 'Compression method: gzip',
115
- 'Compression threshold: 1KB',
116
- 'Compression ratio check: only send if >10% savings'
117
- ]);
118
- } else {
119
- fail('Compression implementation', 'Missing compression components');
120
- }
121
-
122
- // Test 5: Rate limiting
123
- console.log('Test 5: Verifying rate limiting...');
124
- const rateLimitChecks = {
125
- messageCount: optimizerCode.includes('this.messageCount'),
126
- windowTracking: optimizerCode.includes('this.windowStart'),
127
- limit100: optimizerCode.includes('messagesThisSecond > 100'),
128
- rateLimitWarning: optimizerCode.includes('rate limited'),
129
- windowReset: optimizerCode.includes('windowDuration >= 1000')
130
- };
131
-
132
- if (Object.values(rateLimitChecks).every(v => v)) {
133
- pass('Rate limiting', [
134
- 'Message count tracking: present',
135
- 'Time window tracking: 1 second',
136
- 'Rate limit: 100 messages/sec',
137
- 'Warning on limit exceeded: yes',
138
- 'Automatic window reset: yes'
139
- ]);
140
- } else {
141
- fail('Rate limiting', 'Missing rate limiting components');
142
- }
143
-
144
- // Test 6: Deduplication
145
- console.log('Test 6: Verifying message deduplication...');
146
- const deduplicationChecks = {
147
- lastMessage: optimizerCode.includes('this.lastMessage'),
148
- deduplicationCheck: optimizerCode.includes('if (this.lastMessage === data) return'),
149
- assignment: optimizerCode.includes('this.lastMessage = data')
150
- };
151
-
152
- if (Object.values(deduplicationChecks).every(v => v)) {
153
- pass('Message deduplication', [
154
- 'Last message tracking: present',
155
- 'Deduplication check: skips identical consecutive messages',
156
- 'Message tracking update: present'
157
- ]);
158
- } else {
159
- fail('Message deduplication', 'Missing deduplication components');
160
- }
161
-
162
- // Test 7: Bandwidth monitoring
163
- console.log('Test 7: Verifying bandwidth monitoring...');
164
- const monitoringChecks = {
165
- bytesSent: optimizerCode.includes('this.bytesSent'),
166
- bandwidthCalc: optimizerCode.includes('/ 1024 / 1024'),
167
- highBandwidthWarning: optimizerCode.includes('high bandwidth'),
168
- threshold: optimizerCode.includes('3 * 1024 * 1024'), // 3MB over 3 seconds = 1MB/s
169
- getStats: optimizerCode.includes('getStats()')
170
- };
171
-
172
- if (Object.values(monitoringChecks).every(v => v)) {
173
- pass('Bandwidth monitoring', [
174
- 'Bytes sent tracking: present',
175
- 'MB/sec calculation: present',
176
- 'High bandwidth warning: >1MB/sec sustained',
177
- 'Statistics API: getStats() method available',
178
- 'Per-client monitoring: yes'
179
- ]);
180
- } else {
181
- fail('Bandwidth monitoring', 'Missing monitoring components');
182
- }
183
-
184
- // Test 8: Subscription filtering in server.js
185
- console.log('Test 8: Verifying subscription-based broadcasting...');
186
- const serverCode = fs.readFileSync('./server.js', 'utf8');
187
-
188
- const subscriptionChecks = {
189
- subscriptionIndex: serverCode.includes('subscriptionIndex'),
190
- broadcastTypes: serverCode.includes('BROADCAST_TYPES'),
191
- targetedDelivery: serverCode.includes('const targets = new Set()'),
192
- sessionIdFiltering: serverCode.includes('event.sessionId') && serverCode.includes('subscriptionIndex.get'),
193
- conversationIdFiltering: serverCode.includes('event.conversationId') && serverCode.includes('conv-')
194
- };
195
-
196
- if (Object.values(subscriptionChecks).every(v => v)) {
197
- pass('Subscription-based broadcasting', [
198
- 'Subscription index: tracks client subscriptions',
199
- 'Broadcast types: global messages (conversation_created, etc.)',
200
- 'Targeted delivery: session/conversation-specific messages',
201
- 'Session ID filtering: only send to subscribed clients',
202
- 'Conversation ID filtering: only send to subscribed clients'
203
- ]);
204
- } else {
205
- fail('Subscription-based broadcasting', 'Missing subscription filtering');
206
- }
207
-
208
- // Test 9: Integration verification
209
- console.log('Test 9: Verifying broadcastSync integration...');
210
- const integrationChecks = {
211
- wsOptimizerUsage: serverCode.includes('wsOptimizer.sendToClient'),
212
- wsOptimizerInstance: serverCode.includes('new WSOptimizer()'),
213
- broadcastSyncFunction: serverCode.includes('function broadcastSync'),
214
- clientRemoval: serverCode.includes('wsOptimizer.removeClient')
215
- };
216
-
217
- if (Object.values(integrationChecks).every(v => v)) {
218
- pass('broadcastSync integration', [
219
- 'WSOptimizer instantiated: yes',
220
- 'Used in broadcastSync: yes',
221
- 'Client cleanup on disconnect: yes',
222
- 'All broadcasts route through optimizer: yes'
223
- ]);
224
- } else {
225
- fail('broadcastSync integration', 'WSOptimizer not properly integrated');
226
- }
227
-
228
- // Test 10: Adaptive batching based on latency
229
- console.log('Test 10: Verifying adaptive batching...');
230
- const adaptiveChecks = {
231
- batchByTier: optimizerCode.includes('BATCH_BY_TIER'),
232
- tierLevels: optimizerCode.includes('excellent') &&
233
- optimizerCode.includes('good') &&
234
- optimizerCode.includes('fair') &&
235
- optimizerCode.includes('poor'),
236
- trendAdaptation: optimizerCode.includes('latencyTrend') &&
237
- optimizerCode.includes('rising') &&
238
- optimizerCode.includes('falling'),
239
- intervalRange: optimizerCode.includes('16') && optimizerCode.includes('200')
240
- };
241
-
242
- if (Object.values(adaptiveChecks).every(v => v)) {
243
- pass('Adaptive batching', [
244
- 'Latency-based intervals: 16ms (excellent) to 200ms (bad)',
245
- 'Tier levels: excellent, good, fair, poor, bad',
246
- 'Trend adaptation: adjusts interval based on latency trend',
247
- 'Dynamic optimization: yes'
248
- ]);
249
- } else {
250
- fail('Adaptive batching', 'Missing adaptive batching features');
251
- }
252
-
253
- // Summary
254
- console.log('=== Test Summary ===');
255
- console.log(`Total tests: ${testsPassed + testsFailed}`);
256
- console.log(`Passed: ${testsPassed}`);
257
- console.log(`Failed: ${testsFailed}`);
258
- console.log(`Success rate: ${((testsPassed / (testsPassed + testsFailed)) * 100).toFixed(1)}%\n`);
259
-
260
- if (testsFailed === 0) {
261
- console.log('✓ All WebSocket optimization requirements verified!\n');
262
- console.log('Wave 4 Item 4.2 Implementation Summary:');
263
- console.log('────────────────────────────────────────');
264
- console.log('✓ Subscription filtering: Only broadcasts to subscribed clients');
265
- console.log('✓ Message batching: Max 10 normal + 5 low priority per flush');
266
- console.log('✓ Adaptive intervals: 16-200ms based on latency tier');
267
- console.log('✓ Compression: gzip for payloads >1KB (>10% savings)');
268
- console.log('✓ Priority queuing: High (errors) > Normal (progress) > Low (downloads)');
269
- console.log('✓ Rate limiting: 100 messages/sec per client');
270
- console.log('✓ Deduplication: Skips identical consecutive messages');
271
- console.log('✓ Bandwidth monitoring: Warns if >1MB/sec sustained');
272
- console.log('\nExpected bandwidth reduction: 60-80% for high-frequency streaming');
273
- process.exit(0);
274
- } else {
275
- console.log('✗ Some optimization requirements not met');
276
- process.exit(1);
277
- }