-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-intent-broadcast-migration.html
More file actions
572 lines (462 loc) · 25.5 KB
/
test-intent-broadcast-migration.html
File metadata and controls
572 lines (462 loc) · 25.5 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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🚀 Intent 1対多ブロードキャスト移行テスト</title>
<style>
body {
font-family: monospace;
padding: 20px;
background-color: #1e1e1e;
color: #d4d4d4;
}
.test-section {
margin: 20px 0;
padding: 15px;
border: 1px solid #3e3e42;
border-radius: 5px;
}
.test-result {
padding: 10px;
margin: 5px 0;
border-radius: 3px;
}
.success { background-color: #0e5d1e; }
.error { background-color: #5d1e1e; }
.info { background-color: #1e3a5d; }
button {
padding: 10px 15px;
margin: 5px;
background-color: #007acc;
color: white;
border: none;
border-radius: 3px;
cursor: pointer;
}
button:hover { background-color: #005a9e; }
.disabled { background-color: #666; cursor: not-allowed; }
#log {
height: 300px;
overflow-y: auto;
background-color: #2d2d30;
padding: 10px;
border: 1px solid #3e3e42;
white-space: pre-wrap;
}
</style>
</head>
<body>
<h1>🚀 Intent 1対多ブロードキャスト移行テスト</h1>
<p>UnifiedIntentHandler の Map<string, Function> → Map<string, Function[]> 移行テスト</p>
<!-- Phase 0.1: テスト準備 -->
<div class="test-section">
<h2>📋 Phase 0.1: テスト準備</h2>
<button onclick="initializeTest()">🔧 テスト環境初期化</button>
<button onclick="checkCurrentBehavior()">🔍 現在の動作確認</button>
<div id="preparation-results"></div>
</div>
<!-- Phase 0.2: 単体テスト -->
<div class="test-section">
<h2>🧪 Phase 0.2: 単体テスト</h2>
<button onclick="testSingleHandler()">🎯 1対1 Intent(従来動作)</button>
<button onclick="testMultipleHandlers()">📡 1対多 Intent(新機能)</button>
<button onclick="testHandlerRegistration()">📥 ハンドラー登録・削除</button>
<button onclick="testErrorHandling()">❌ エラーハンドリング</button>
<div id="unit-test-results"></div>
</div>
<!-- Phase 0.3: 統合テスト -->
<div class="test-section">
<h2>🌐 Phase 0.3: 統合テスト</h2>
<button onclick="testHTTPRequestToMultiplePlugins()">🔗 HTTP Request → 複数プラグイン</button>
<button onclick="testCharmFlowCoreIntegration()">⚙️ CharmFlowCore統合</button>
<button onclick="testPluginWrapperIntegration()">🎁 PluginWrapper統合</button>
<div id="integration-test-results"></div>
</div>
<!-- Phase 0.4: パフォーマンステスト -->
<div class="test-section">
<h2>⚡ Phase 0.4: パフォーマンステスト</h2>
<button onclick="testPerformanceBaseline()">📊 ベースライン測定</button>
<button onclick="testLargeNumberOfHandlers()">🔥 大量ハンドラー(100個)</button>
<button onclick="testConcurrentExecution()">⚡ 並列実行性能</button>
<div id="performance-test-results"></div>
</div>
<!-- Phase 0.5: 統計・デバッグテスト -->
<div class="test-section">
<h2>📈 Phase 0.5: 統計・デバッグテスト</h2>
<button onclick="testStatistics()">📊 統計情報テスト</button>
<button onclick="testDebugFeatures()">🐛 デバッグ機能テスト</button>
<button onclick="generateTestReport()">📋 テスト結果レポート生成</button>
<div id="statistics-test-results"></div>
</div>
<!-- ログ出力エリア -->
<div class="test-section">
<h2>📝 ログ出力</h2>
<button onclick="clearLog()">🧹 ログクリア</button>
<button onclick="exportLog()">💾 ログエクスポート</button>
<div id="log"></div>
</div>
<script type="module">
import { NyaCore } from './src/core/nyacore.js';
import { Message } from './src/messaging/message.js';
import { DefaultTransport } from './src/messaging/transport.js';
// グローバル変数
window.testState = {
nyaCore: null,
testResults: [],
startTime: Date.now(),
testHandlers: new Map(),
performanceData: []
};
// ログ出力ヘルパー
window.log = function(message, type = 'info') {
const timestamp = new Date().toISOString().split('T')[1].split('.')[0];
const logElement = document.getElementById('log');
const entry = `[${timestamp}] ${type.toUpperCase()}: ${message}\\n`;
logElement.textContent += entry;
logElement.scrollTop = logElement.scrollHeight;
console.log(entry);
};
// テスト結果表示ヘルパー
window.showResult = function(sectionId, message, isSuccess = true) {
const section = document.getElementById(sectionId);
const div = document.createElement('div');
div.className = `test-result ${isSuccess ? 'success' : 'error'}`;
div.textContent = message;
section.appendChild(div);
};
// ===========================================
// Phase 0.1: テスト準備
// ===========================================
window.initializeTest = async function() {
log('🔧 テスト環境初期化開始');
try {
const transport = new DefaultTransport();
window.testState.nyaCore = new NyaCore(transport, {
enableDebug: true,
enableStats: true
});
await window.testState.nyaCore.initPromise;
log('✅ NyaCore初期化完了');
showResult('preparation-results', '✅ テスト環境初期化成功', true);
// ベースライン測定
const stats = window.testState.nyaCore.unifiedIntentHandler.getStats();
log(`📊 初期統計: ${JSON.stringify(stats, null, 2)}`);
} catch (error) {
log(`❌ 初期化エラー: ${error.message}`, 'error');
showResult('preparation-results', `❌ 初期化失敗: ${error.message}`, false);
}
};
window.checkCurrentBehavior = async function() {
log('🔍 現在の動作確認開始');
try {
const handler = window.testState.nyaCore.unifiedIntentHandler;
// 現在のhandlerタイプ確認
const testAction = 'test.current.behavior';
const testHandler1 = () => ({ handler: 1 });
const testHandler2 = () => ({ handler: 2 });
// 登録テスト
handler.registerIntentHandler(testAction, testHandler1);
handler.registerIntentHandler(testAction, testHandler2);
// 取得テスト
const retrievedHandler = handler.intentHandlers.get(testAction);
const isArray = Array.isArray(retrievedHandler);
log(`📊 ハンドラータイプ: ${isArray ? 'Array (新)' : 'Function (旧)'}`);
log(`📊 登録状態: ${typeof retrievedHandler}`);
showResult('preparation-results',
`現在の実装: ${isArray ? '配列対応済み' : '単一ハンドラー(要修正)'}`,
isArray);
} catch (error) {
log(`❌ 動作確認エラー: ${error.message}`, 'error');
showResult('preparation-results', `❌ 動作確認失敗: ${error.message}`, false);
}
};
// ===========================================
// Phase 0.2: 単体テスト
// ===========================================
window.testSingleHandler = async function() {
log('🎯 1対1 Intent テスト開始');
try {
const handler = window.testState.nyaCore.unifiedIntentHandler;
const testAction = 'test.single.handler';
let executionCount = 0;
const testHandler = (payload) => {
executionCount++;
return { success: true, executionCount, payload };
};
// 登録
handler.registerIntentHandler(testAction, testHandler);
// 実行
const intentMessage = {
action: testAction,
payload: { data: 'test data' }
};
const result = await handler.processIntent(intentMessage);
log(`📊 実行結果: ${JSON.stringify(result, null, 2)}`);
const success = executionCount === 1 && result.success;
showResult('unit-test-results',
`1対1 Intent: ${success ? '成功' : '失敗'}`,
success);
} catch (error) {
log(`❌ 1対1テストエラー: ${error.message}`, 'error');
showResult('unit-test-results', `❌ 1対1テスト失敗: ${error.message}`, false);
}
};
window.testMultipleHandlers = async function() {
log('📡 1対多 Intent テスト開始');
try {
const handler = window.testState.nyaCore.unifiedIntentHandler;
const testAction = 'test.multiple.handlers';
const executionResults = [];
// 複数ハンドラー作成
const handler1 = (payload) => {
executionResults.push({ handler: 1, payload });
return { handlerId: 1, processed: true };
};
const handler2 = (payload) => {
executionResults.push({ handler: 2, payload });
return { handlerId: 2, processed: true };
};
const handler3 = (payload) => {
executionResults.push({ handler: 3, payload });
return { handlerId: 3, processed: true };
};
// 登録
handler.registerIntentHandler(testAction, handler1);
handler.registerIntentHandler(testAction, handler2);
handler.registerIntentHandler(testAction, handler3);
// 実行
const intentMessage = {
action: testAction,
payload: { data: 'broadcast test' }
};
const result = await handler.processIntent(intentMessage);
log(`📊 実行結果: ${JSON.stringify(result, null, 2)}`);
log(`📊 各ハンドラー実行: ${JSON.stringify(executionResults, null, 2)}`);
const success = executionResults.length === 3 &&
result.status === 'broadcasted' &&
result.totalHandlers === 3;
showResult('unit-test-results',
`1対多 Intent: ${success ? '成功' : '失敗'} (${executionResults.length}/3 handlers)`,
success);
} catch (error) {
log(`❌ 1対多テストエラー: ${error.message}`, 'error');
showResult('unit-test-results', `❌ 1対多テスト失敗: ${error.message}`, false);
}
};
window.testHandlerRegistration = async function() {
log('📥 ハンドラー登録・削除テスト開始');
try {
const handler = window.testState.nyaCore.unifiedIntentHandler;
const testAction = 'test.handler.registration';
const testHandler1 = () => ({ id: 1 });
const testHandler2 = () => ({ id: 2 });
// 登録テスト
handler.registerIntentHandler(testAction, testHandler1);
const afterFirst = handler.intentHandlers.get(testAction);
handler.registerIntentHandler(testAction, testHandler2);
const afterSecond = handler.intentHandlers.get(testAction);
// 削除テスト(unregisterIntentHandlerが実装されている場合)
if (handler.unregisterIntentHandler) {
const unregisterResult = handler.unregisterIntentHandler(testAction, testHandler1);
const afterUnregister = handler.intentHandlers.get(testAction);
log(`📊 削除結果: ${unregisterResult}`);
log(`📊 削除後ハンドラー数: ${Array.isArray(afterUnregister) ? afterUnregister.length : 'N/A'}`);
}
log(`📊 1個目登録後: ${Array.isArray(afterFirst) ? afterFirst.length : typeof afterFirst}`);
log(`📊 2個目登録後: ${Array.isArray(afterSecond) ? afterSecond.length : typeof afterSecond}`);
const isArrayImplementation = Array.isArray(afterSecond);
const correctCount = isArrayImplementation ? afterSecond.length === 2 : true;
showResult('unit-test-results',
`ハンドラー登録: ${correctCount ? '成功' : '失敗'} (実装: ${isArrayImplementation ? '配列' : '単一'})`,
correctCount);
} catch (error) {
log(`❌ 登録テストエラー: ${error.message}`, 'error');
showResult('unit-test-results', `❌ 登録テスト失敗: ${error.message}`, false);
}
};
window.testErrorHandling = async function() {
log('❌ エラーハンドリングテスト開始');
try {
const handler = window.testState.nyaCore.unifiedIntentHandler;
const testAction = 'test.error.handling';
const successHandler = () => ({ success: true });
const errorHandler = () => { throw new Error('Test error'); };
// 成功・失敗ハンドラー混在
handler.registerIntentHandler(testAction, successHandler);
handler.registerIntentHandler(testAction, errorHandler);
handler.registerIntentHandler(testAction, successHandler);
const intentMessage = {
action: testAction,
payload: { data: 'error test' }
};
const result = await handler.processIntent(intentMessage);
log(`📊 エラー処理結果: ${JSON.stringify(result, null, 2)}`);
// エラーが発生しても他のハンドラーが実行される
const hasErrorHandling = result.status !== 'failed';
showResult('unit-test-results',
`エラーハンドリング: ${hasErrorHandling ? '成功(エラー分離)' : '失敗'}`,
hasErrorHandling);
} catch (error) {
log(`❌ エラーハンドリングテストエラー: ${error.message}`, 'error');
showResult('unit-test-results', `❌ エラーハンドリングテスト失敗: ${error.message}`, false);
}
};
// ===========================================
// Phase 0.3: 統合テスト
// ===========================================
window.testHTTPRequestToMultiplePlugins = async function() {
log('🔗 HTTP Request → 複数プラグイン統合テスト開始');
try {
const handler = window.testState.nyaCore.unifiedIntentHandler;
const httpResponseIntent = 'http.response.ready';
const receivedData = [];
// HTML Parser模擬
const htmlParserHandler = (payload) => {
receivedData.push({ plugin: 'html-parser', data: payload });
return { plugin: 'html-parser', processed: true };
};
// Output Console模擬
const outputConsoleHandler = (payload) => {
receivedData.push({ plugin: 'output-console', data: payload });
return { plugin: 'output-console', displayed: true };
};
// Text Note模擬
const textNoteHandler = (payload) => {
receivedData.push({ plugin: 'text-note', data: payload });
return { plugin: 'text-note', saved: true };
};
// 複数プラグインを同一Intentに登録
handler.registerIntentHandler(httpResponseIntent, htmlParserHandler);
handler.registerIntentHandler(httpResponseIntent, outputConsoleHandler);
handler.registerIntentHandler(httpResponseIntent, textNoteHandler);
// HTTP Response模擬
const httpResponseData = {
success: true,
url: 'https://example.com',
data: '<html><body><h1>Test</h1></body></html>',
timestamp: Date.now()
};
const intentMessage = {
action: httpResponseIntent,
payload: httpResponseData
};
const result = await handler.processIntent(intentMessage);
log(`📊 統合テスト結果: ${JSON.stringify(result, null, 2)}`);
log(`📊 受信データ: ${JSON.stringify(receivedData, null, 2)}`);
const success = receivedData.length === 3 &&
result.status === 'broadcasted' &&
result.successCount === 3;
showResult('integration-test-results',
`HTTP Request統合: ${success ? '成功' : '失敗'} (${receivedData.length}/3 plugins)`,
success);
} catch (error) {
log(`❌ 統合テストエラー: ${error.message}`, 'error');
showResult('integration-test-results', `❌ 統合テスト失敗: ${error.message}`, false);
}
};
// ===========================================
// Phase 0.4: パフォーマンステスト
// ===========================================
window.testPerformanceBaseline = async function() {
log('📊 ベースライン性能測定開始');
try {
const handler = window.testState.nyaCore.unifiedIntentHandler;
const testAction = 'test.performance.baseline';
// シンプルハンドラー
const simpleHandler = () => ({ processed: true });
handler.registerIntentHandler(testAction, simpleHandler);
const iterations = 1000;
const startTime = performance.now();
for (let i = 0; i < iterations; i++) {
await handler.processIntent({
action: testAction,
payload: { iteration: i }
});
}
const endTime = performance.now();
const totalTime = endTime - startTime;
const avgTime = totalTime / iterations;
window.testState.performanceData.push({
test: 'baseline',
iterations,
totalTime,
avgTime
});
log(`📊 ベースライン: ${totalTime.toFixed(2)}ms total, ${avgTime.toFixed(3)}ms avg`);
showResult('performance-test-results',
`ベースライン: ${avgTime.toFixed(3)}ms/call (${iterations} calls)`,
avgTime < 1); // 1ms未満を合格とする
} catch (error) {
log(`❌ ベースラインテストエラー: ${error.message}`, 'error');
showResult('performance-test-results', `❌ ベースラインテスト失敗: ${error.message}`, false);
}
};
window.testLargeNumberOfHandlers = async function() {
log('🔥 大量ハンドラー性能テスト開始');
try {
const handler = window.testState.nyaCore.unifiedIntentHandler;
const testAction = 'test.performance.large';
const handlerCount = 100;
// 100個のハンドラー登録
for (let i = 0; i < handlerCount; i++) {
const testHandler = (payload) => ({ handlerId: i, processed: true });
handler.registerIntentHandler(testAction, testHandler);
}
const startTime = performance.now();
const result = await handler.processIntent({
action: testAction,
payload: { data: 'large scale test' }
});
const endTime = performance.now();
const processingTime = endTime - startTime;
log(`📊 大量処理: ${processingTime.toFixed(2)}ms for ${handlerCount} handlers`);
log(`📊 結果: ${JSON.stringify({...result, results: '...'}, null, 2)}`);
const success = processingTime < 1000 && // 1秒未満
result.totalHandlers === handlerCount &&
result.successCount === handlerCount;
showResult('performance-test-results',
`大量ハンドラー: ${success ? '成功' : '失敗'} (${processingTime.toFixed(2)}ms, ${handlerCount} handlers)`,
success);
} catch (error) {
log(`❌ 大量ハンドラーテストエラー: ${error.message}`, 'error');
showResult('performance-test-results', `❌ 大量ハンドラーテスト失敗: ${error.message}`, false);
}
};
// ===========================================
// ユーティリティ関数
// ===========================================
window.clearLog = function() {
document.getElementById('log').textContent = '';
};
window.exportLog = function() {
const logContent = document.getElementById('log').textContent;
const blob = new Blob([logContent], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `intent-broadcast-test-${Date.now()}.txt`;
a.click();
URL.revokeObjectURL(url);
};
window.generateTestReport = function() {
const report = {
timestamp: new Date().toISOString(),
testDuration: Date.now() - window.testState.startTime,
performanceData: window.testState.performanceData,
systemInfo: {
userAgent: navigator.userAgent,
platform: navigator.platform
}
};
log(`📋 テストレポート: ${JSON.stringify(report, null, 2)}`);
showResult('statistics-test-results', '📋 テストレポート生成完了', true);
};
// 自動初期化
document.addEventListener('DOMContentLoaded', function() {
log('🚀 Intent 1対多ブロードキャスト移行テストページ準備完了');
log('⚠️ 注意: まず【テスト環境初期化】ボタンを押してください');
});
</script>
</body>
</html>