Elffuss BraidHub

utopia-ia/elffuss-code public

main · 5.0 KiBRawPermalink
1// Con la interfaz en inglés, nada en español colado:
2// 1. La ayuda del modo Básico (era siempre en español y mandaba a «Ajustes →
3// Cerebro» mientras la interfaz decía «Settings → Brain»), y las órdenes
4// en inglés que esa ayuda promete («tree», «read <file>»…) funcionan.
5// 2. Lo que se para dice «(Stopped.)», no «(Parado.)».
6// 3. La carpeta del almacenamiento del navegador es «OPFS (browser)».
7// Y en español sigue todo igual.
8//
9// BASE=http://localhost:8799 node tests/english-ui.mjs
10import { chromium } from 'playwright';
11const BASE = process.env.BASE || 'http://localhost:8799';
12let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
13const b = await chromium.launch();
14const errs = [];
15
16async function abre(locale) {
17 const ctx = await b.newContext({ locale });
18 await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
19 const p = await ctx.newPage({ viewport: { width: 1400, height: 900 } });
20 p.on('pageerror', e => errs.push(e.message.slice(0, 160)));
21 await p.goto(BASE + '/manifest.json');
22 await p.evaluate(async () => {
23 const root = await navigator.storage.getDirectory();
24 const w = await (await root.getFileHandle('notes.md', { create: true })).createWritable(); await w.write('# notes\nhello\n'); await w.close();
25 });
26 await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' });
27 await p.waitForFunction(() => window.elffussClaw?.conv?.getActive?.(), null, { timeout: 20000 });
28 return { ctx, p };
29}
30const di = async (p, texto) => {
31 const antes = await p.locator('#chat-log .msg.assistant').count();
32 await p.fill('#prompt', texto);
33 await p.press('#prompt', 'Enter');
34 await p.waitForFunction(n => document.querySelectorAll('#chat-log .msg.assistant').length > n && !window.elffussClaw.conv.isBusy(), antes, { timeout: 10000 }).catch(() => {});
35 return p.evaluate(() => ({ ultima: [...document.querySelectorAll('#chat-log .msg.assistant')].at(-1)?.textContent || '',
36 herramientas: [...document.querySelectorAll('#chat-log .msg.tool b')].map(b => b.textContent) }));
37};
38
39// 1 · inglés
40{
41 const { ctx, p } = await abre('en-US');
42 const hola = await di(p, 'hello');
43 ok('1 · en inglés, la ayuda del modo Básico sale en inglés', /basic mode/.test(hola.ultima) && /Settings → Brain/.test(hola.ultima) && !/Ajustes|Cerebro|Entiendo/.test(hola.ultima), hola.ultima.slice(0, 160));
44 const arbol = await di(p, 'tree');
45 ok('1 · …y entiende las órdenes en inglés que promete («tree»)', arbol.herramientas.includes('code.tree'), JSON.stringify(arbol.herramientas));
46 const lee = await di(p, 'read notes.md');
47 ok('1 · …(«read <file>»)', lee.herramientas.includes('code.read'), JSON.stringify(lee.herramientas));
48
49 // 2 · parar
50 await p.evaluate(() => {
51 window.elffussClaw.conv.setProvider({ chat: async (h, s, cb, signal) => {
52 for (let i = 0; i < 200; i++) { if (signal?.aborted) throw new DOMException('Stopped', 'AbortError'); cb('·'); await new Promise(r => setTimeout(r, 25)); }
53 return 'done';
54 } });
55 });
56 await p.fill('#prompt', 'a long job');
57 await p.press('#prompt', 'Enter');
58 await p.waitForFunction(() => document.getElementById('btn-send').classList.contains('is-stop'), null, { timeout: 5000 }).catch(() => {});
59 await p.click('#btn-send');
60 await p.waitForFunction(() => !window.elffussClaw.conv.isBusy(), null, { timeout: 8000 }).catch(() => {});
61 const nota = await p.evaluate(() => [...document.querySelectorAll('#chat-log .msg.muted')].map(n => n.textContent).at(-1) || '');
62 ok('2 · lo que se para dice «(Stopped.)»', nota === '(Stopped.)', JSON.stringify(nota));
63
64 // 3 · carpeta OPFS: el proyecto de prueba vive en la OPFS, y su carpeta es la
65 // que se adopta como espacio de trabajo («Use the project's»)
66 await p.click('#btn-settings');
67 await p.waitForTimeout(400);
68 await p.locator('#settings-panel button', { hasText: "Use the project's" }).click();
69 await p.waitForTimeout(400);
70 const ajustes = await p.evaluate(() => document.getElementById('settings-panel').textContent);
71 ok('3 · la carpeta del navegador se llama «OPFS (browser)»', /OPFS \(browser\)/.test(ajustes) && !/navegador/.test(ajustes), (ajustes.match(/[^.]{0,40}OPFS[^.]{0,30}/) || [''])[0]);
72 await ctx.close();
73}
74
75// 4 · español: igual que antes
76{
77 const { ctx, p } = await abre('es-ES');
78 const hola = await di(p, 'hola');
79 ok('4 · en español, la ayuda sigue en español', /modo básico/.test(hola.ultima) && /Ajustes → Cerebro/.test(hola.ultima), hola.ultima.slice(0, 120));
80 const arbol = await di(p, 'árbol');
81 ok('4 · …y «árbol» sigue funcionando', arbol.herramientas.includes('code.tree'), JSON.stringify(arbol.herramientas));
82 await ctx.close();
83}
84
85console.log('\n errores JS:', errs[0] || 'ninguno');
86ok('sin errores de página', errs.length === 0, errs.join(' | '));
87console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ INTERFAZ EN INGLÉS SIN ESPAÑOL COLADO');
88await b.close();
89process.exit(fails ? 1 : 0);