Elffuss BraidHub

utopia-ia/elffuss-code public

main · 9.4 KiBRawPermalink
1// Panel de Skills: claro de usar, con teclado y en el teléfono. GitHub se
2// stubea aquí (nada sale a la red).
3//
4// 1. Dos partes que no se mezclan: «Instaladas» y «Explorar catálogos», cada
5// una con su encabezado, y una sola acción por fila.
6// 2. «Explorar» abre la lista DENTRO de la tarjeta del catálogo (antes se
7// añadía al final del panel, debajo de «Añadir repo») y otra vez la cierra
8// (aria-expanded).
9// 3. «Instalar» NO cierra el panel: el botón pasa a «Instalada ✓», conserva
10// el foco, la skill aparece arriba y el chat recibe el «cómo usarla».
11// 4. «Quitar» la quita al momento, el foco no cae a <body> y la lista
12// abierta vuelve a ofrecer «Instalar».
13// 5. Un catálogo añadido por ti se quita desde dentro de su lista.
14// 6. En el teléfono los nombres no se cortan («Co…») ni hay desplazamiento
15// lateral, y los botones caben.
16// 7. En inglés, todo en inglés (también los nombres de los catálogos y los
17// errores).
18//
19// BASE=http://127.0.0.1:8898 node tests/skills-panel-ux.mjs
20import { chromium } from 'playwright';
21const BASE = process.env.BASE || 'http://localhost:8799';
22let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
23
24const REPO = 'anthropics/skills';
25const ARBOL = { tree: [{ path: 'skills/pdf/SKILL.md' }, { path: 'skills/docx/SKILL.md' }] };
26const md = n => `---\nname: ${n}\ndescription: Hace cosas de ${n}.\n---\nInstrucciones de ${n}.`;
27const b = await chromium.launch();
28async function abre(locale, viewport, movil = false) {
29 const ctx = await b.newContext({ locale, viewport, isMobile: movil, hasTouch: movil });
30 await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
31 await ctx.route('**/*', r => {
32 const u = r.request().url();
33 if (u.startsWith('https://api.github.com/repos/')) return u.includes('/no/existe/') ? r.fulfill({ status: 404, body: '{}' }) : r.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(ARBOL) });
34 if (u.startsWith('https://raw.githubusercontent.com/')) return r.fulfill({ status: 200, contentType: 'text/plain', body: md(u.match(/skills\/([^/]+)\/SKILL/)?.[1] || 'x') });
35 if (/soundcloud|huggingface|hf\.co/.test(u)) return r.abort();
36 return r.continue();
37 });
38 const p = await ctx.newPage();
39 p.errs = []; p.on('pageerror', e => p.errs.push(e.message.slice(0, 160)));
40 await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' });
41 await p.waitForFunction(() => window.elffussClaw?.conv?.getActive?.(), null, { timeout: 30000 });
42 return { ctx, p };
43}
44const foco = p => p.evaluate(() => { const a = document.activeElement; return !a || a === document.body ? 'BODY' : (a.getAttribute('aria-label') || a.textContent || a.id).trim().slice(0, 60); });
45const enter = async (p, loc) => { await loc.focus(); await p.keyboard.press('Enter'); };
46
47// ── escritorio, en español y con teclado ──
48{
49 const { ctx, p } = await abre('es-ES', { width: 1280, height: 800 });
50 await p.click('#act-skills');
51 await p.waitForSelector('#settings-panel .sk-catalogos .sk-cat');
52 const heads = await p.$$eval('#settings-panel .skills-panel h4', hs => hs.map(h => h.textContent));
53 ok('1 · dos partes con encabezado: Instaladas y Explorar catálogos', heads.length === 2 && /^Instaladas \(0\)$/.test(heads[0]) && /^Explorar catálogos$/.test(heads[1]), JSON.stringify(heads));
54 const acciones = await p.$$eval('#settings-panel .sk-catalogos .sk-cat', fs => fs.map(f => f.querySelectorAll(':scope > button').length));
55 ok('1 · cada catálogo tiene UNA acción', acciones.length >= 3 && acciones.every(n => n === 1), JSON.stringify(acciones));
56
57 const tarjeta = p.locator(`#settings-panel .sk-cat[data-repo="${REPO}"]`);
58 const explorar = tarjeta.locator(':scope > button');
59 await enter(p, explorar);
60 await p.waitForFunction(r => document.querySelector(`.sk-cat[data-repo="${r}"] .sk-browse .sk-install`), REPO);
61 ok('2 · «Explorar» abre la lista DENTRO de la tarjeta del catálogo', await tarjeta.locator('.sk-browse .sk-row').count() === 2
62 && await explorar.getAttribute('aria-expanded') === 'true' && await explorar.innerText() === 'Ocultar');
63 ok('2 · …y el foco sigue en el botón', (await foco(p)) === 'Explorar anthropics/skills', await foco(p));
64
65 const nombre = (await tarjeta.locator('.sk-install', { hasText: 'Instalar' }).first().getAttribute('aria-label')).replace(/^Instalar: /, '');
66 const instalar = tarjeta.locator(`.sk-install[data-nombre="${nombre}"]`);
67 await enter(p, instalar);
68 await p.waitForFunction(() => document.querySelectorAll('#settings-panel .sk-instaladas .sk-row').length === 1);
69 ok('3 · instalar NO cierra el panel', await p.isVisible('#settings-panel'));
70 ok('3 · el botón pasa a «Instalada ✓» (inerte) y conserva el foco', await instalar.getAttribute('aria-disabled') === 'true'
71 && (await foco(p)) === `Instalada ✓: ${nombre}`, await foco(p));
72 ok('3 · la skill aparece arriba y el contador sube', /^Instaladas \(1\)$/.test(await p.textContent('#sk-inst-h'))
73 && (await p.innerText('#settings-panel .sk-instaladas .sk-row b')) === nombre);
74 ok('3 · el aviso lo dice y el chat tiene el «cómo usarla»', /instalada/.test(await p.innerText('.skills-panel > .sk-msg'))
75 && await p.evaluate(n => [...document.querySelectorAll('#chat-log .msg')].some(m => m.textContent.includes(`Skill «${n}» instalada`)), nombre));
76
77 await enter(p, p.locator('#settings-panel .sk-instaladas .sk-remove').first());
78 await p.waitForTimeout(200);
79 ok('4 · «Quitar» la quita al momento', /^Instaladas \(0\)$/.test(await p.textContent('#sk-inst-h')));
80 ok('4 · …el foco no cae a <body> (va al encabezado)', (await foco(p)) === 'Instaladas (0)', await foco(p));
81 ok('4 · …y la lista abierta vuelve a ofrecer «Instalar»', await p.locator(`#settings-panel .sk-install[aria-label="Instalar: ${nombre}"]`).getAttribute('aria-disabled') === null);
82
83 await explorar.click();
84 ok('2 · otra vez «Ocultar» la cierra', await tarjeta.locator('.sk-browse').isHidden() && await explorar.getAttribute('aria-expanded') === 'false');
85
86 // un catálogo propio
87 await p.fill('#settings-panel .sk-add input', 'https://github.com/alguien/mis-skills');
88 await p.keyboard.press('Enter');
89 const propia = p.locator('#settings-panel .sk-cat[data-repo="alguien/mis-skills"]');
90 await propia.waitFor();
91 ok('5 · añadir un repo lo enseña con una sola acción y el foco en «Explorar»', await propia.locator(':scope > button').count() === 1
92 && (await foco(p)) === 'Explorar alguien/mis-skills', await foco(p));
93 await propia.locator(':scope > button').click();
94 const quitarRepo = propia.locator('.sk-remove-repo');
95 await quitarRepo.waitFor();
96 await enter(p, quitarRepo);
97 await p.waitForTimeout(250);
98 ok('5 · …y se quita desde dentro de su lista (el foco va al encabezado)', await p.locator('#settings-panel .sk-cat[data-repo="alguien/mis-skills"]').count() === 0
99 && (await foco(p)) === 'Explorar catálogos', await foco(p));
100 ok('sin errores de página', !p.errs.length, p.errs.join(' | '));
101 await ctx.close();
102}
103
104// ── teléfono ──
105{
106 const { ctx, p } = await abre('es-ES', { width: 390, height: 844 }, true);
107 await p.tap('#btn-drawer');
108 await p.waitForTimeout(200);
109 await p.tap('#act-skills');
110 await p.waitForSelector('#settings-panel .sk-cat');
111 await p.locator(`#settings-panel .sk-cat[data-repo="${REPO}"] > button`).tap();
112 await p.waitForSelector('#settings-panel .sk-browse .sk-install');
113 const m = await p.evaluate(() => {
114 const cortados = [...document.querySelectorAll('#settings-panel .sk-info b')].filter(b => b.scrollWidth > b.clientWidth + 1).map(b => b.textContent);
115 const fuera = [...document.querySelectorAll('#settings-panel button')].filter(b => { const r = b.getBoundingClientRect(); return r.width && (r.right > innerWidth || r.left < 0); }).map(b => b.textContent);
116 return { cortados, fuera, scrollX: document.documentElement.scrollWidth - innerWidth };
117 });
118 ok('6 · en el teléfono ningún nombre se corta', !m.cortados.length, JSON.stringify(m.cortados));
119 ok('6 · …ningún botón se sale de la pantalla y no hay desplazamiento lateral', !m.fuera.length && m.scrollX <= 0, JSON.stringify(m));
120 ok('6 · sin errores de página', !p.errs.length, p.errs.join(' | '));
121 await ctx.close();
122}
123
124// ── en inglés ──
125{
126 const { ctx, p } = await abre('en-US', { width: 1280, height: 800 });
127 await p.click('#act-skills');
128 await p.waitForSelector('#settings-panel .sk-cat');
129 const txt = await p.textContent('#settings-panel');
130 ok('7 · en inglés: título, partes y catálogos en inglés', /Skills for Elffuss/.test(txt) && /Installed \(0\)/.test(txt) && /Browse catalogs/i.test(txt)
131 && /Community · Mega collection/.test(txt) && !/Comunidad|Catálogos|Instaladas|Explorar/.test(txt), txt.slice(0, 400));
132 await p.fill('#settings-panel .sk-add input', 'esto no vale');
133 await p.keyboard.press('Enter');
134 await p.waitForTimeout(200);
135 ok('7 · …y el error de un repo que no vale, también', /Type owner\/repo/.test(await p.innerText('#settings-panel .sk-add + .sk-msg')), await p.innerText('#settings-panel .sk-add + .sk-msg'));
136 ok('7 · sin errores de página', !p.errs.length, p.errs.join(' | '));
137 await ctx.close();
138}
139await b.close();
140console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ panel de Skills: claro, con teclado, en el teléfono y en inglés');
141process.exit(fails ? 1 : 0);