File size: 9,620 Bytes
1d3f990 | 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 | /**
* Ahmad Bot Integration Test
* Run this in the browser console to verify full setup
*
* Usage:
* 1. Open index-app.html
* 2. Open DevTools (F12)
* 3. Copy-paste this into Console
* 4. Follow test output
*/
const AhmadBotTest = {
/**
* Run all tests
*/
async runAll() {
console.clear();
console.log('%c=== Ahmad Bot Integration Test ===', 'color: #00d9ff; font-weight: bold; font-size: 14px;');
console.log('');
let passed = 0;
let failed = 0;
// Test 1: Check WebLLM loaded
console.log('%cTest 1: WebLLM Library', 'color: #ffd700; font-weight: bold;');
if (typeof window.webllm !== 'undefined') {
console.log('β WebLLM loaded:', window.webllm);
passed++;
} else {
console.error('β WebLLM not available');
failed++;
}
console.log('');
// Test 2: Check Engine class
console.log('%cTest 2: AhmadWebLLMEngine Class', 'color: #ffd700; font-weight: bold;');
if (typeof AhmadWebLLMEngine !== 'undefined') {
console.log('β AhmadWebLLMEngine loaded');
const engine = new AhmadWebLLMEngine();
console.log(' - Status:', engine.status);
console.log(' - Model:', engine.modelId);
console.log(' - Supported models:', engine.getSupportedModels().length);
passed++;
} else {
console.error('β AhmadWebLLMEngine not found');
failed++;
}
console.log('');
// Test 3: Check UI class
console.log('%cTest 3: AhmadBotUI Class', 'color: #ffd700; font-weight: bold;');
if (typeof AhmadBotUI !== 'undefined') {
console.log('β AhmadBotUI loaded');
console.log(' - Global instance:', window.ahmadBotUI);
passed++;
} else {
console.error('β AhmadBotUI not found');
failed++;
}
console.log('');
// Test 4: Check DOM elements
console.log('%cTest 4: DOM Elements', 'color: #ffd700; font-weight: bold;');
const elements = {
launcher: '#jit-launcher',
button: '#jit-toggle',
panel: '#jit-panel',
messages: '#jit-messages',
input: '#jit-input',
send: '#jit-send',
};
let domPassed = true;
for (const [name, selector] of Object.entries(elements)) {
const elem = document.querySelector(selector);
if (elem) {
console.log(`β ${name}: ${selector}`);
} else {
console.error(`β ${name}: ${selector} NOT FOUND`);
domPassed = false;
}
}
if (domPassed) passed++; else failed++;
console.log('');
// Test 5: Check NotebookPageReader
console.log('%cTest 5: Notebook Context Reader', 'color: #ffd700; font-weight: bold;');
if (typeof NotebookPageReader !== 'undefined') {
console.log('β NotebookPageReader loaded');
const cells = NotebookPageReader.extractCells();
console.log(` - Cells found: ${cells.length}`);
const meta = NotebookPageReader.getNotebookMetadata();
console.log(` - Notebook: "${meta.title}"`);
if (cells.length > 0) {
passed++;
} else {
console.warn('β No cells found (notebook may be empty)');
}
} else {
console.error('β NotebookPageReader not found');
failed++;
}
console.log('');
// Test 6: Check NotebookContextIndex
console.log('%cTest 6: Context Index', 'color: #ffd700; font-weight: bold;');
if (typeof NotebookContextIndex !== 'undefined') {
console.log('β NotebookContextIndex loaded');
const index = new NotebookContextIndex();
console.log(` - Indexed cells: ${index.getAllCells().length}`);
const relevant = index.findRelevant('Unicode', 3);
console.log(` - Relevant cells for "Unicode": ${relevant.length}`);
passed++;
} else {
console.error('β NotebookContextIndex not found');
failed++;
}
console.log('');
// Test 7: CSS loaded
console.log('%cTest 7: Styles', 'color: #ffd700; font-weight: bold;');
const styleSheet = Array.from(document.styleSheets).find(s =>
s.href?.includes('ahmad-bot.css') || s.textContent?.includes('--ahmad-')
);
if (styleSheet || document.querySelector('style[data-ahmad-bot-styles]')) {
console.log('β Ahmad Bot CSS loaded');
const primary = getComputedStyle(document.documentElement).getPropertyValue('--ahmad-primary');
console.log(' - Theme colors detected');
passed++;
} else {
console.warn('β Ahmad Bot CSS may not be loaded (check stylesheet)');
}
console.log('');
// Test 8: WebGPU support
console.log('%cTest 8: Hardware Acceleration', 'color: #ffd700; font-weight: bold;');
const hasWebGPU = AhmadWebLLMEngine?.hasWebGPU?.();
if (hasWebGPU) {
console.log('β WebGPU available (GPU acceleration enabled)');
} else {
console.log('β WebGPU not available (CPU mode will be used)');
}
console.log(` - Navigator.gpu: ${!!navigator.gpu}`);
passed++;
console.log('');
// Summary
console.log('%c=== Test Summary ===', 'color: #00d9ff; font-weight: bold; font-size: 14px;');
console.log(`Passed: %c${passed}`, 'color: #10b981; font-weight: bold;');
console.log(`Failed: %c${failed}`, failed > 0 ? 'color: #ef4444; font-weight: bold;' : 'color: #10b981;');
console.log('');
if (failed === 0) {
console.log('%cβ All systems ready. Click Ξ© to start Ahmad Bot!', 'color: #10b981; font-weight: bold; font-size: 12px;');
} else {
console.error('%cβ Some tests failed. Check errors above.', 'color: #ef4444; font-weight: bold;');
}
return { passed, failed };
},
/**
* Test UI interaction
*/
testUI() {
console.log('%cTesting UI...', 'color: #ffd700; font-weight: bold;');
if (!window.ahmadBotUI) {
console.error('UI not initialized');
return;
}
const ui = window.ahmadBotUI;
console.log('Current state:', ui.getStats());
// Open panel
console.log('Opening panel...');
ui.openPanel();
console.log('Panel should now be visible. Status should be OFFLINE.');
console.log('Wait for model to initialize (LOADING β READY)');
console.log('Then type a message and press Send');
},
/**
* Test engine directly
*/
async testEngine() {
console.log('%cTesting Engine...', 'color: #ffd700; font-weight: bold;');
try {
const engine = new AhmadWebLLMEngine();
console.log('Engine created:', engine.status);
if (!AhmadWebLLMEngine.hasWebLLM()) {
console.error('WebLLM not available');
return;
}
console.log('WebLLM available, initializing...');
await engine.initialize('TinyLlama-1.1B-Chat-v0.4-q4f16_1-1k');
console.log('Engine ready:', engine.isReady());
if (engine.isReady()) {
console.log('Engine is ready for generation');
console.log('Try: engine.generate("Hello", "You are helpful.")');
}
return engine;
} catch (error) {
console.error('Engine test failed:', error.message);
}
},
/**
* Print configuration
*/
printConfig() {
console.log('%c=== Ahmad Bot Configuration ===', 'color: #00d9ff; font-weight: bold;');
if (window.ahmadBotUI?.engine) {
const status = window.ahmadBotUI.engine.getStatus();
console.table(status);
} else {
console.log('Engine not initialized yet');
console.log('Click Ξ© and wait for READY status');
}
},
/**
* Get help
*/
help() {
console.log('%c=== Ahmad Bot Test Commands ===', 'color: #00d9ff; font-weight: bold;');
console.log('');
console.log('AhmadBotTest.runAll() β Run full integration test');
console.log('AhmadBotTest.testUI() β Test UI interaction');
console.log('AhmadBotTest.testEngine() β Test engine (async)');
console.log('AhmadBotTest.printConfig() β Show current config');
console.log('AhmadBotTest.help() β Show this help');
console.log('');
console.log('Quick start:');
console.log('1. AhmadBotTest.runAll()');
console.log('2. AhmadBotTest.testUI()');
console.log('3. Click Ξ© button');
console.log('4. Wait for READY status');
console.log('5. Type your question');
}
};
// Auto-run on load
console.log('%cπ Ahmad Bot Test Suite Loaded', 'color: #00d9ff; font-weight: bold;');
console.log('Run: AhmadBotTest.runAll()');
console.log('Or: AhmadBotTest.help()');
|