| 1 | // Enlaces que llevan a un sitio concreto, y de dónde sale lo que se usa. |
| 2 | // |
| 3 | // 1. #/conv/<id> reabre esa conversación; su menú tiene «Copiar enlace». |
| 4 | // 2. #/mind abre la Mente, #/settings Ajustes y #/lab el banco de pruebas. |
| 5 | // (Antes solo existía #/file/<ruta>.) |
| 6 | // 3. Ajustes enlaza la ficha de cada modelo local (Hugging Face) y la |
| 7 | // documentación de la API de cada proveedor externo. |
| 8 | // 4. Cada descarga del bridge enseña su SHA-256, el de bridge-dl/SHA256SUMS. |
| 9 | // |
| 10 | // BASE=http://localhost:8799 node tests/links.mjs |
| 11 | import { chromium } from 'playwright'; |
| 12 | import { readFileSync } from 'node:fs'; |
| 13 | import { join, dirname } from 'node:path'; |
| 14 | import { fileURLToPath } from 'node:url'; |
| 15 | const BASE = process.env.BASE || 'http://localhost:8799'; |
| 16 | const SUMAS = readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'web', 'bridge-dl', 'SHA256SUMS'), 'utf8'); |
| 17 | let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; }; |
| 18 | |
| 19 | const b = await chromium.launch(); |
| 20 | const ctx = await b.newContext({ locale: 'es-ES', permissions: ['clipboard-read', 'clipboard-write'] }); |
| 21 | await ctx.addInitScript(() => { |
| 22 | try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} |
| 23 | try { Object.defineProperty(Navigator.prototype, 'gpu', { get() { return undefined; }, configurable: true }); } catch {} |
| 24 | }); |
| 25 | const errs = []; |
| 26 | const abre = async (ruta = '') => { |
| 27 | const p = await ctx.newPage({ viewport: { width: 1400, height: 900 } }); |
| 28 | p.on('pageerror', e => errs.push(e.message.slice(0, 160))); |
| 29 | await p.goto(BASE + '/?test-opfs' + ruta, { waitUntil: 'domcontentloaded' }); |
| 30 | if (ruta !== '#/lab') await p.waitForFunction(() => window.elffussClaw?.conv?.getActive?.(), null, { timeout: 20000 }); |
| 31 | return p; |
| 32 | }; |
| 33 | |
| 34 | // 1 · conversaciones |
| 35 | let p = await abre(); |
| 36 | const ids = await p.evaluate(async () => { |
| 37 | const conv = window.elffussClaw.conv; |
| 38 | const primera = conv.getActive().id; |
| 39 | conv.send(primera, 'hola'); |
| 40 | await new Promise(r => setTimeout(r, 600)); |
| 41 | const segunda = conv.create().id; |
| 42 | return { primera, segunda }; |
| 43 | }); |
| 44 | // el menú de la pestaña de la primera: «Copiar enlace» |
| 45 | await p.locator(`#conv-tabs .tab[data-id="${ids.primera}"]`).click({ button: 'right' }).catch(async () => { |
| 46 | await p.locator('#conv-tabs .tab').first().click({ button: 'right' }); |
| 47 | }); |
| 48 | await p.locator('#conv-menu [role="menuitem"]', { hasText: 'Copiar enlace' }).click(); |
| 49 | await p.waitForTimeout(200); |
| 50 | const copiado = await p.evaluate(() => navigator.clipboard.readText()).catch(() => ''); |
| 51 | ok('1 · «Copiar enlace» copia #/conv/<id> de esa conversación', copiado.endsWith('#/conv/' + ids.primera), copiado); |
| 52 | await p.close(); |
| 53 | p = await abre('#/conv/' + ids.primera); |
| 54 | await p.waitForTimeout(500); |
| 55 | const activa = await p.evaluate(() => window.elffussClaw.conv.getActive().id); |
| 56 | ok('1 · abrir ese enlace reabre esa conversación', activa === ids.primera, JSON.stringify({ activa, esperada: ids.primera })); |
| 57 | await p.close(); |
| 58 | p = await abre('#/conv/cnoexiste1234'); |
| 59 | await p.waitForTimeout(500); |
| 60 | ok('1 · un enlace a una conversación que ya no está lo dice', /ya no está/.test(await p.locator('#statusbar').textContent()), await p.locator('#statusbar').textContent()); |
| 61 | await p.close(); |
| 62 | |
| 63 | // 2 · Mente, Ajustes y Lab |
| 64 | p = await abre('#/mind'); |
| 65 | await p.waitForTimeout(800); |
| 66 | ok('2 · #/mind abre la Mente', await p.evaluate(() => { const o = document.getElementById('mind-overlay'); return !!o && getComputedStyle(o).display !== 'none'; })); |
| 67 | await p.close(); |
| 68 | p = await abre('#/settings'); |
| 69 | await p.waitForTimeout(500); |
| 70 | ok('2 · #/settings abre Ajustes', !(await p.locator('#settings-panel').isHidden()) && /Ajustes/.test(await p.locator('#settings-title').textContent())); |
| 71 | |
| 72 | // 3 · fichas de modelos y documentación de proveedores (con Ajustes abierto) |
| 73 | await p.waitForTimeout(500); |
| 74 | const enlaces = await p.evaluate(() => ({ |
| 75 | fichas: [...document.querySelectorAll('.model-cards-links a')].map(a => ({ t: a.textContent, href: a.href, nombre: a.getAttribute('aria-label') })), |
| 76 | docs: [...document.querySelectorAll('#settings-panel .prov-docs')].map(a => ({ href: a.href, nombre: a.getAttribute('aria-label') })), |
| 77 | })); |
| 78 | // El modelo ligero (ONNX) solo se ofrece con WebGPU: sin ella ningún dtype |
| 79 | // funciona en wasm, y ofrecerlo era bajar ~600 MB para acabar en básico. Así |
| 80 | // que su ficha se enlaza con GPU y NO se enlaza sin ella. |
| 81 | const hayGPU = await p.evaluate(async () => !!(await navigator.gpu?.requestAdapter?.().catch(() => null))); |
| 82 | const fichaLigero = enlaces.fichas.some(f => f.href === 'https://huggingface.co/onnx-community/Qwen3.5-0.8B-ONNX' && /Qwen3\.5-0\.8B/.test(f.nombre)); |
| 83 | ok(hayGPU ? '3 · Ajustes enlaza la ficha del modelo ligero en Hugging Face' : '3 · sin WebGPU no se ofrece el modelo ligero, ni se enlaza su ficha', hayGPU ? fichaLigero : !fichaLigero, JSON.stringify(enlaces.fichas)); |
| 84 | ok('3 · …y la documentación de la API de cada proveedor externo', enlaces.docs.some(d => /platform\.openai\.com/.test(d.href) && /OpenAI/.test(d.nombre)) && enlaces.docs.some(d => /docs\.anthropic\.com/.test(d.href)) && enlaces.docs.some(d => /ollama/.test(d.href)), JSON.stringify(enlaces.docs)); |
| 85 | |
| 86 | // 4 · huella SHA-256 de las descargas del bridge |
| 87 | await p.waitForSelector('.br-sha', { timeout: 5000 }).catch(() => {}); |
| 88 | const huellas = await p.evaluate(() => [...document.querySelectorAll('.br-sha')].map(d => ({ f: d.dataset.file, h: d.querySelector('code')?.textContent }))); |
| 89 | const esperado = new Map(SUMAS.split('\n').filter(Boolean).map(l => { const [h, f] = l.split(/\s+/); return [f, h]; })); |
| 90 | ok('4 · cada descarga del bridge enseña su SHA-256', huellas.length === esperado.size && huellas.every(x => esperado.get(x.f) === x.h), JSON.stringify(huellas.map(x => x.f))); |
| 91 | ok('4 · …y cómo comprobarlo, con el enlace a SHA256SUMS', await p.locator('.br-sha-how a[href="bridge-dl/SHA256SUMS"]').count() === 1); |
| 92 | await p.close(); |
| 93 | |
| 94 | p = await ctx.newPage(); |
| 95 | await p.goto(BASE + '/#/lab', { waitUntil: 'domcontentloaded' }); |
| 96 | await p.waitForURL(/lab\.html/, { timeout: 10000 }).catch(() => {}); |
| 97 | ok('2 · #/lab lleva al banco de pruebas', /lab\.html$/.test(new URL(p.url()).pathname), p.url()); |
| 98 | await p.close(); |
| 99 | |
| 100 | console.log('\n errores JS:', errs[0] || 'ninguno'); |
| 101 | ok('sin errores de página', errs.length === 0, errs.join(' | ')); |
| 102 | console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ ENLACES: conversación, Mente, Ajustes y Lab; fichas, docs y huellas'); |
| 103 | await b.close(); |
| 104 | process.exit(fails ? 1 : 0); |