Elffuss BraidHub

utopia-ia/elffuss-code public

main · 6.4 KiBRawPermalink
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
11import { chromium } from 'playwright';
12import { readFileSync } from 'node:fs';
13import { join, dirname } from 'node:path';
14import { fileURLToPath } from 'node:url';
15const BASE = process.env.BASE || 'http://localhost:8799';
16const SUMAS = readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'web', 'bridge-dl', 'SHA256SUMS'), 'utf8');
17let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
18
19const b = await chromium.launch();
20const ctx = await b.newContext({ locale: 'es-ES', permissions: ['clipboard-read', 'clipboard-write'] });
21await ctx.addInitScript(() => {
22 try { localStorage.setItem('elffusscode.model', 'rules'); } catch {}
23 try { Object.defineProperty(Navigator.prototype, 'gpu', { get() { return undefined; }, configurable: true }); } catch {}
24});
25const errs = [];
26const 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
35let p = await abre();
36const 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»
45await 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});
48await p.locator('#conv-menu [role="menuitem"]', { hasText: 'Copiar enlace' }).click();
49await p.waitForTimeout(200);
50const copiado = await p.evaluate(() => navigator.clipboard.readText()).catch(() => '');
51ok('1 · «Copiar enlace» copia #/conv/<id> de esa conversación', copiado.endsWith('#/conv/' + ids.primera), copiado);
52await p.close();
53p = await abre('#/conv/' + ids.primera);
54await p.waitForTimeout(500);
55const activa = await p.evaluate(() => window.elffussClaw.conv.getActive().id);
56ok('1 · abrir ese enlace reabre esa conversación', activa === ids.primera, JSON.stringify({ activa, esperada: ids.primera }));
57await p.close();
58p = await abre('#/conv/cnoexiste1234');
59await p.waitForTimeout(500);
60ok('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());
61await p.close();
62
63// 2 · Mente, Ajustes y Lab
64p = await abre('#/mind');
65await p.waitForTimeout(800);
66ok('2 · #/mind abre la Mente', await p.evaluate(() => { const o = document.getElementById('mind-overlay'); return !!o && getComputedStyle(o).display !== 'none'; }));
67await p.close();
68p = await abre('#/settings');
69await p.waitForTimeout(500);
70ok('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)
73await p.waitForTimeout(500);
74const 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.
81const hayGPU = await p.evaluate(async () => !!(await navigator.gpu?.requestAdapter?.().catch(() => null)));
82const fichaLigero = enlaces.fichas.some(f => f.href === 'https://huggingface.co/onnx-community/Qwen3.5-0.8B-ONNX' && /Qwen3\.5-0\.8B/.test(f.nombre));
83ok(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));
84ok('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
87await p.waitForSelector('.br-sha', { timeout: 5000 }).catch(() => {});
88const huellas = await p.evaluate(() => [...document.querySelectorAll('.br-sha')].map(d => ({ f: d.dataset.file, h: d.querySelector('code')?.textContent })));
89const esperado = new Map(SUMAS.split('\n').filter(Boolean).map(l => { const [h, f] = l.split(/\s+/); return [f, h]; }));
90ok('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)));
91ok('4 · …y cómo comprobarlo, con el enlace a SHA256SUMS', await p.locator('.br-sha-how a[href="bridge-dl/SHA256SUMS"]').count() === 1);
92await p.close();
93
94p = await ctx.newPage();
95await p.goto(BASE + '/#/lab', { waitUntil: 'domcontentloaded' });
96await p.waitForURL(/lab\.html/, { timeout: 10000 }).catch(() => {});
97ok('2 · #/lab lleva al banco de pruebas', /lab\.html$/.test(new URL(p.url()).pathname), p.url());
98await p.close();
99
100console.log('\n errores JS:', errs[0] || 'ninguno');
101ok('sin errores de página', errs.length === 0, errs.join(' | '));
102console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ ENLACES: conversación, Mente, Ajustes y Lab; fichas, docs y huellas');
103await b.close();
104process.exit(fails ? 1 : 0);