Elffuss BraidHub

utopia-ia/elffuss-claw public

main · 3.9 KiBRawPermalink
1// 📨 Errores y feedback: opt-in (apagado por defecto), captura de errores no
2// capturados cuando está activo, y envío manual de feedback que funciona
3// SIEMPRE (acción explícita) sin activar el automático de fondo.
4import { chromium } from 'playwright';
5const BASE = process.env.BASE || 'http://localhost:8801';
6let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
7
8const b = await chromium.launch();
9// En español: la prueba busca el botón «Enviar» del feedback. Sin locale el
10// navegador va en inglés, la página también («Send»), y la prueba se caía ahí
11// sin llegar a sus dos últimas comprobaciones. Y en Básico: no necesita modelo.
12const ctx = await b.newContext({ locale: 'es-ES' });
13await ctx.addInitScript(() => { try { localStorage.setItem('elffuss.welcomed', '1'); localStorage.setItem('elffuss.model', 'rules'); } catch {} });
14const p = await ctx.newPage();
15
16const reports = [];
17await p.route('**/proxy/report', async route => {
18 reports.push(JSON.parse(route.request().postData() || '{}'));
19 await route.fulfill({ status: 200, contentType: 'application/json', body: '{"ok":true}' });
20});
21
22await p.goto(BASE + '/', { waitUntil: 'domcontentloaded' });
23await p.waitForTimeout(1500);
24
25ok('telemetría apagada por defecto', await p.evaluate(async () => (await import('/js/telemetry.js')).isEnabled()) === false);
26await p.evaluate(async () => { const t = await import('/js/telemetry.js'); await t.reportError('no debería salir'); });
27await p.waitForTimeout(200);
28ok('con telemetría apagada, reportError() no manda nada', reports.length === 0);
29
30// abre Ajustes (pestaña /modelo)
31await p.evaluate(async () => (await import('/js/ui.js')).selectTab('ajustes'));
32await p.waitForTimeout(300);
33ok('el checkbox de errores/feedback existe y empieza desmarcado', await p.locator('#tel-enabled').isChecked() === false);
34await p.locator('#tel-enabled').check();
35await p.waitForTimeout(100);
36ok('marcarlo activa telemetry.isEnabled()', await p.evaluate(async () => (await import('/js/telemetry.js')).isEnabled()) === true);
37ok('persiste en localStorage', await p.evaluate(() => localStorage.getItem('elffuss.telemetry.elffuss-claw') === '1'));
38
39await p.evaluate(async () => { const t = await import('/js/telemetry.js'); await t.reportError('fallo de prueba', { stack: 'en algún sitio' }); });
40await p.waitForTimeout(200);
41ok('con telemetría activa, reportError() manda el informe', reports.some(r => r.kind === 'error' && r.message === 'fallo de prueba'));
42ok('el informe lleva app=elffuss-claw, url y user-agent', reports.some(r => r.app === 'elffuss-claw' && r.url && r.userAgent));
43
44await p.evaluate(() => { setTimeout(() => { throw new Error('crash-no-capturado-de-prueba'); }, 0); });
45await p.waitForTimeout(300);
46ok('un error global no capturado también se reporta solo', reports.some(r => /crash-no-capturado-de-prueba/.test(r.message)));
47
48await p.locator('#tel-enabled').uncheck();
49await p.waitForTimeout(100);
50const before = reports.length;
51await p.evaluate(async () => { const t = await import('/js/telemetry.js'); await t.reportError('esto no debería salir ya'); });
52await p.waitForTimeout(200);
53ok('al desactivarlo, reportError() vuelve a no mandar nada', reports.length === before);
54
55await p.fill('#tel-feedback', 'esto es un feedback manual de prueba');
56await p.locator('.card', { has: p.locator('#tel-feedback') }).locator('button', { hasText: 'Enviar' }).click();
57await p.waitForTimeout(300);
58ok('el feedback manual SÍ se manda aunque el automático esté apagado', reports.some(r => r.kind === 'feedback' && /feedback manual de prueba/.test(r.message)));
59ok('tras mandar el feedback manual, el automático sigue apagado', await p.evaluate(async () => (await import('/js/telemetry.js')).isEnabled()) === false);
60
61console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ TELEMETRÍA/FEEDBACK (Claw): opt-in real, nunca automático sin permiso, manual siempre disponible');
62await b.close();
63process.exit(fails ? 1 : 0);