Elffuss BraidHub

utopia-ia/elffuss-code public

e7ee0f72085f · 6.8 KiBRawPermalink
1// Ajustes: lo que ofrecen tiene que ser lo correcto, y usarse sin ratón.
2//
3// 1. Bridge para un Mac ARM: antes se ofrecía la versión Intel (todos los Mac
4// dicen «MacIntel» en navigator.platform). Si no se puede saber la
5// arquitectura, se ofrecen las dos versiones de Mac.
6// 2. Token y carpeta del bridge con su etiqueta asociada; «Olvidar token» y
7// «Desconectar» existen (antes no había forma).
8// 3. El permiso dice lo que controla (ficheros), no «y comandos de terminal».
9// 4. Los interruptores de proveedores externos tienen nombre accesible.
10// 5. El punto del modelo dice con palabras qué modelo y en qué estado, y es
11// un botón que lleva a Ajustes.
12// 6. Al elegir un modelo, su tarjeta dice «cargando…» y, al terminar, queda
13// resaltada (antes el resaltado se quedaba en el anterior).
14// El modelo es de mentira: page.route sirve un providers/onnx.js propio.
15//
16// BASE=http://127.0.0.1:8898 node tests/settings-ux.mjs
17import { chromium } from 'playwright';
18const BASE = process.env.BASE || 'http://localhost:8799';
19let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
20
21const MAC_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36';
22const FALSO = `export const name = 'onnx falso'; export function configure() {}
23export async function load(onProgress = () => {}) { onProgress('cargando falso'); await new Promise(r => setTimeout(r, 900)); }
24export async function chat() { return 'hola'; }`;
25
26const b = await chromium.launch();
27const errs = [];
28const abre = async (arch) => {
29 const ctx = await b.newContext({ locale: 'es-ES', userAgent: MAC_UA });
30 await ctx.addInitScript((arch) => {
31 try { localStorage.setItem('elffusscode.model', 'rules'); localStorage.setItem('elffusscode.bridgeToken', 'tok-de-prueba'); } catch {}
32 const datos = arch === null ? undefined : { getHighEntropyValues: async () => ({ architecture: arch }) };
33 Object.defineProperty(Navigator.prototype, 'userAgentData', { get: () => datos, configurable: true });
34 }, arch);
35 const p = await ctx.newPage({ viewport: { width: 1400, height: 900 } });
36 p.on('pageerror', e => errs.push(e.message.slice(0, 160)));
37 await p.route('**/js/providers/onnx.js*', r => r.fulfill({ status: 200, contentType: 'text/javascript', body: FALSO }));
38 await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' });
39 await p.waitForFunction(() => window.elffussClaw?.conv?.getActive?.(), null, { timeout: 15000 });
40 return { ctx, p };
41};
42const descargas = (p) => p.evaluate(() => [...document.querySelectorAll('#br-dl a')].map(a => a.dataset.file));
43
44// 1 · Mac ARM
45let { ctx, p } = await abre('arm');
46await p.click('#btn-settings');
47await p.waitForTimeout(500);
48ok('1 · en un Mac ARM se ofrece la versión Apple Silicon', JSON.stringify(await descargas(p)) === '["elffuss-bridge-mac-arm64"]', JSON.stringify(await descargas(p)));
49
50// 2 · etiquetas, Olvidar token
51const etiquetas = await p.evaluate(() => ['br-token', 'br-folder'].map(id => document.getElementById(id).labels?.length || 0));
52ok('2 · token y carpeta tienen su etiqueta asociada', etiquetas.every(n => n === 1), JSON.stringify(etiquetas));
53ok('2 · con un token guardado se ofrece «Olvidar token»', await p.locator('#br-forget').isVisible());
54await p.click('#br-forget');
55await p.waitForTimeout(150);
56const olvido = await p.evaluate(() => ({ ls: localStorage.getItem('elffusscode.bridgeToken'), input: document.getElementById('br-token').value, msg: document.querySelector('.bridge-card .br-msg')?.textContent || '' }));
57ok('2 · «Olvidar token» lo borra del navegador y lo dice', olvido.ls === null && olvido.input === '' && /olvidado/.test(olvido.msg), JSON.stringify(olvido));
58const disc = await p.evaluate(() => !!document.getElementById('br-disconnect'));
59ok('2 · existe «Desconectar» (visible cuando el bridge está conectado)', disc);
60
61// 3 · permiso
62const permiso = await p.evaluate(() => document.querySelector('#perm-autoedit').closest('label').textContent);
63ok('3 · el permiso dice que controla escribir y editar ficheros', /Escribir y editar ficheros/.test(permiso) && !/comandos de terminal/.test(permiso), permiso);
64
65// 4 · proveedores
66const nombres = await p.evaluate(() => [...document.querySelectorAll('#settings-panel .prov-head input[type=checkbox]')].map(c => c.getAttribute('aria-label')));
67ok('4 · cada interruptor de proveedor tiene nombre accesible', nombres.length >= 3 && nombres.every(n => /^Activar /.test(n || '')), JSON.stringify(nombres));
68
69// 6 · tarjeta de modelo: cargando… y resaltada al terminar
70const tarjetaQwen = p.locator('#settings-panel .model-card', { hasText: 'Qwen3.5-0.8B' }).first();
71await tarjetaQwen.click();
72await p.waitForTimeout(150);
73const durante = await p.evaluate(() => { const c = [...document.querySelectorAll('#settings-panel .model-card')].find(x => /Qwen3.5-0.8B/.test(x.textContent)); return { busy: c?.getAttribute('aria-busy'), txt: c?.textContent }; });
74ok('6 · al elegir un modelo, su tarjeta dice «cargando…» (aria-busy)', durante.busy === 'true' && /cargando/.test(durante.txt), JSON.stringify(durante));
75await p.waitForTimeout(1500);
76const tras = await p.evaluate(() => { const c = [...document.querySelectorAll('#settings-panel .model-card')].find(x => /Qwen3.5-0.8B/.test(x.textContent)); return { activa: c?.classList.contains('active'), pressed: c?.getAttribute('aria-pressed') }; });
77ok('6 · al terminar, la tarjeta del modelo cargado queda resaltada', tras.activa && tras.pressed === 'true', JSON.stringify(tras));
78
79// 5 · el punto del modelo
80await p.click('#btn-settings'); // cierra
81const punto = await p.evaluate(() => { const d = document.getElementById('model-dot'); return { tag: d.tagName, aria: d.getAttribute('aria-label') }; });
82ok('5 · el punto del modelo es un botón que dice qué modelo y su estado', punto.tag === 'BUTTON' && /Qwen3.5-0.8B/.test(punto.aria) && /listo/.test(punto.aria), JSON.stringify(punto));
83await p.click('#model-dot');
84await p.waitForTimeout(300);
85ok('5 · …y lleva a Ajustes', await p.evaluate(() => !document.getElementById('settings-panel').hidden && !!document.querySelector('#settings-panel .model-grid')));
86await ctx.close();
87
88// 1 · Mac sin datos de arquitectura (Safari): las dos versiones
89({ ctx, p } = await abre(null));
90await p.click('#btn-settings');
91await p.waitForTimeout(500);
92ok('1 · si no se sabe la arquitectura del Mac, se ofrecen las dos versiones', JSON.stringify(await descargas(p)) === '["elffuss-bridge-mac-arm64","elffuss-bridge-mac-intel"]', JSON.stringify(await descargas(p)));
93await ctx.close();
94
95console.log('\n errores JS:', errs[0] || 'ninguno');
96ok('sin errores de página', errs.length === 0, errs.join(' | '));
97console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ AJUSTES: LO QUE OFRECEN ES LO CORRECTO');
98await b.close();
99process.exit(fails ? 1 : 0);