Elffuss BraidHub

utopia-ia/elffuss-copilot public

main · 12.0 KiBRawPermalink
1// Teclado, foco y lector de pantalla en el Copiloto (lo que encontró la revisión tras la auditoría).
2// 1. El contador de la grabación no es una región viva (el lector lo leía cada segundo): se anuncia
3// una vez al empezar y otra al guardar.
4// 2. Con el foco en «Enviar» de la ficha, una frase nueva no lo tira al <body> (la ficha se rehacía
5// entera con cada frase).
6// 3. Borrar los modelos, con el botón del inicio o con el chip 💾, no tira el foco al <body>.
7// 4. «Enviar» (arriba y en la ficha) con el teclado: el foco se queda en el botón mientras envía y
8// después, y un segundo Intro no manda otra vez (antes se desactivaba y el foco caía al <body>).
9// 5. «Reintentar la IA avanzada» con el teclado: el foco pasa al chip de la IA y cómo acaba se anuncia.
10// 6. Parar con el teclado deja el foco en CSV, no en «Nueva llamada»; y «Nueva llamada» con una ficha
11// sin enviar ni descargar pregunta antes de borrarla.
12// Navegador sin cabeza, micro falso y modelos de mentira (tests/browser). Uso: node copilot/tests/a11y.mjs
13import { launch, newContext, startStatic, startWebhook, checker, until } from '../../tests/browser/harness.mjs';
14
15const { srv, base } = await startStatic();
16const browser = await launch();
17const C = checker('Copiloto · teclado y lector de pantalla');
18const PAGE = base + '/copilot/?ui=es&lang=es&skill=ficha';
19const LAURA = [
20 { spk: 1, lang: 'es', text: 'Hola, me llamo Laura Pérez y trabajo en Construcciones Norte.' },
21 { spk: 0, lang: 'es', text: 'Encantado, ¿me da un teléfono?' },
22 { spk: 1, lang: 'es', text: 'Sí, el seis uno dos tres cuatro cinco seis siete ocho.' },
23];
24
25async function open(fake = { lines: LAURA }, { gpu = 0, hfStatus = 200 } = {}) {
26 const ctx = await newContext(browser, { base, init: { fake, gpu }, hfStatus });
27 const page = await ctx.newPage();
28 const errors = []; page.on('pageerror', e => errors.push(e.message));
29 // Los diálogos se aceptan, salvo mientras la prueba ponga page.__dismiss.
30 const dialogs = []; page.on('dialog', d => { dialogs.push(d.message()); if (page.__dismiss) d.dismiss(); else d.accept(); });
31 await page.goto(PAGE);
32 return { ctx, page, errors, dialogs };
33}
34const focused = page => page.evaluate(() => document.activeElement?.id || document.activeElement?.tagName);
35
36// 1 ── La grabación se anuncia al empezar y al guardar; el contador no
37{
38 const { ctx, page, errors } = await open();
39 await page.evaluate(() => {
40 window.__live = [];
41 for (const el of document.querySelectorAll('[aria-live],[role=status],[role=alert],[role=log]')) {
42 if (el.id === 'status') continue; // el estado de cada frase sí debe leerse
43 new MutationObserver(() => { if (el.textContent.trim()) window.__live.push(el.id + ': ' + el.textContent); }).observe(el, { childList: true, characterData: true, subtree: true });
44 }
45 });
46 await page.check('#recOpt');
47 await page.click('#start');
48 await page.waitForTimeout(4500); // unos cuantos segundos del contador
49 const during = await page.evaluate(() => ({ live: window.__live.slice(), chipLive: !!document.getElementById('recChip').closest('[aria-live],[role=status],[role=alert],[role=log]'), chip: document.getElementById('recChip').textContent }));
50 await page.click('#stop');
51 await until(page, () => /guardada/.test(document.getElementById('recChip').textContent), null, { timeout: 6000, what: 'la grabación guardada' });
52 await page.waitForTimeout(200);
53 const after = await page.evaluate(() => window.__live.slice());
54 C.ok('el contador de la grabación no está en una región que se lee sola', !during.chipLive && /grabando 00:0\d/.test(during.chip), during);
55 C.ok('al empezar se anuncia una vez que graba, sin el contador', during.live.filter(x => /Grabando la llamada/.test(x)).length === 1 && !during.live.some(x => /\d\d:\d\d/.test(x)), during.live);
56 C.ok('al parar se anuncia que se guardó', after.some(x => /grabación guardada/.test(x)), after);
57 C.ok('sin errores en la página', !errors.length, errors);
58 await ctx.close();
59}
60
61// 2 ── «Enviar» de la ficha conserva el foco cuando llega otra frase
62{
63 const { ctx, page, errors } = await open();
64 await page.click('#start');
65 await until(page, () => document.querySelectorAll('#log .tline').length >= 1, null, { timeout: 15000, what: 'una frase' });
66 await page.focus('#send2');
67 const n = await page.evaluate(() => document.querySelectorAll('#log .tline').length);
68 const more = await until(page, k => document.querySelectorAll('#log .tline').length > k, n, { timeout: 12000, what: 'otra frase' });
69 await page.waitForTimeout(200);
70 const f = await focused(page);
71 C.ok('con el foco en «Enviar» de la ficha, una frase nueva no lo mueve', more && f === 'send2', f);
72 C.ok('sin errores en la página', !errors.length, errors);
73 await ctx.close();
74}
75
76// 3 ── Borrar los modelos no tira el foco al <body>
77{
78 const { ctx, page, errors } = await open();
79 const fill = () => page.evaluate(async () => { const c = await caches.open('transformers-cache'); await c.put('https://huggingface.co/x', new Response('x'.repeat(8e6))); });
80 await fill();
81 await page.reload();
82 await until(page, () => !document.getElementById('clearCache').hidden, null, { what: 'el botón de borrar' });
83 await page.focus('#clearCache');
84 await page.keyboard.press('Enter');
85 await until(page, () => /Borrando|borrados/.test(document.getElementById('clearCache').textContent), null, { what: 'borrando' });
86 const during = await focused(page);
87 await page.waitForFunction(() => document.getElementById('clearCache').hidden, null, { timeout: 8000 }).catch(() => {});
88 const after = { hidden: await page.evaluate(() => document.getElementById('clearCache').hidden), focus: await focused(page) };
89 C.ok('botón del inicio: mientras borra, el foco sigue en él', during === 'clearCache', during);
90 C.ok('…y al esconderse pasa a Empezar', after.hidden && after.focus === 'start', after);
91 await fill();
92 await page.reload();
93 await until(page, () => { const c = document.getElementById('diskChip'); return c && !c.hidden; }, null, { what: 'el chip de disco' });
94 await page.focus('#diskChip');
95 await page.keyboard.press('Enter');
96 await until(page, () => /…|Borrado/.test(document.getElementById('diskChip').textContent), null, { what: 'borrando' });
97 const chipDuring = await focused(page);
98 await page.waitForFunction(() => document.getElementById('diskChip').hidden, null, { timeout: 8000 }).catch(() => {});
99 const chipAfter = { hidden: await page.evaluate(() => document.getElementById('diskChip').hidden), focus: await focused(page) };
100 C.ok('chip 💾: mientras borra, el foco sigue en él', chipDuring === 'diskChip', chipDuring);
101 C.ok('…y al esconderse pasa a Empezar', chipAfter.hidden && chipAfter.focus === 'start', chipAfter);
102 C.ok('sin errores en la página', !errors.length, errors);
103 await ctx.close();
104}
105
106// 4 ── «Enviar» con el teclado, con un webhook que tarda en contestar
107{
108 const hook = await startWebhook({ status: 200, delay: 1500 });
109 for (const id of ['send', 'send2']) {
110 const { ctx, page, errors } = await open();
111 await page.evaluate(u => { document.getElementById('dest').open = true; const w = document.getElementById('webhook'); w.value = u; w.dispatchEvent(new Event('input')); }, hook.url);
112 await page.click('#start');
113 await until(page, () => document.querySelectorAll('#log .tline').length >= 1, null, { timeout: 15000, what: 'una frase' });
114 const posts = () => hook.hits.filter(h => h.method === 'POST').length;
115 const n0 = posts();
116 await page.focus('#' + id);
117 await page.keyboard.press('Enter');
118 await page.waitForTimeout(200);
119 const during = { focus: await focused(page), res: await page.textContent('#sendRes'), aria: await page.getAttribute('#' + id, 'aria-disabled') };
120 await page.keyboard.press('Enter'); // otra vez mientras envía: no manda nada
121 await until(page, () => /✓/.test(document.getElementById('sendRes').textContent), null, { timeout: 8000, what: 'el resultado del envío' });
122 const after = { focus: await focused(page), aria: await page.getAttribute('#' + id, 'aria-disabled'), posts: posts() - n0 };
123 C.ok(`«Enviar» (${id}) con el teclado: mientras envía, el foco sigue en él y dice que no está disponible`, during.focus === id && /Enviando/.test(during.res) && during.aria === 'true', during);
124 C.ok(`…al acabar sigue ahí, vuelve a estar disponible y el segundo Intro no mandó otra vez`, after.focus === id && after.aria === null && after.posts === 1, after);
125 C.ok('sin errores en la página', !errors.length, errors);
126 await ctx.close();
127 }
128 hook.srv.close();
129}
130
131// 5 ── «Reintentar la IA avanzada» con el teclado (la IA no carga: el Hub contesta 404)
132{
133 const GiB = 1024 ** 3;
134 const { ctx, page, errors } = await open({ lines: LAURA }, { gpu: 4 * GiB, hfStatus: 404 });
135 await until(page, () => !document.getElementById('iaOpt').disabled, null, { what: 'IA disponible' });
136 await page.check('#iaOpt');
137 await page.click('#start');
138 await until(page, () => !document.getElementById('iaRetry').hidden, null, { timeout: 15000, what: 'Reintentar' });
139 await page.evaluate(() => { window.__ann = []; const n = document.getElementById('srNote'); new MutationObserver(() => { if (n.textContent) window.__ann.push(n.textContent); }).observe(n, { childList: true, characterData: true, subtree: true }); });
140 const name = await page.evaluate(() => { const b = document.getElementById('iaRetry'); return { text: b.textContent, label: b.getAttribute('aria-label') }; });
141 await page.focus('#iaRetry');
142 await page.keyboard.press('Enter');
143 const right = await focused(page);
144 await until(page, () => !document.getElementById('iaRetry').hidden, null, { timeout: 15000, what: 'Reintentar otra vez (vuelve a fallar)' });
145 await page.waitForTimeout(300);
146 const after = { focus: await focused(page), ann: await page.evaluate(() => window.__ann.slice()) };
147 C.ok('el botón dice qué reintenta («Reintentar la IA avanzada»)', name.text === 'Reintentar' && name.label === 'Reintentar la IA avanzada', name);
148 C.ok('al pulsarlo con el teclado, el foco pasa al chip de la IA (no al <body>) y ahí sigue', right === 'iaChip' && after.focus === 'iaChip', { right, after: after.focus });
149 C.ok('…y cómo acaba se anuncia (otra vez no carga, y por qué)', after.ann.some(t => /No se pudo cargar la IA \(descarga 404\)/.test(t)), after.ann);
150 C.ok('sin errores en la página', !errors.length, errors);
151 await ctx.close();
152}
153
154// 6 ── Parar con el teclado, y «Nueva llamada» con una ficha sin guardar
155{
156 const { ctx, page, errors, dialogs } = await open();
157 await page.click('#start');
158 await until(page, () => /Laura/.test(document.getElementById('board').textContent), null, { timeout: 15000, what: 'la ficha con datos' });
159 await page.focus('#stop');
160 await page.keyboard.press('Enter');
161 const afterStop = await focused(page);
162 await page.focus('#newCall');
163 page.__dismiss = true;
164 await page.keyboard.press('Enter'); // pregunta, y se dice que no
165 await page.waitForTimeout(300);
166 const kept = { ...await page.evaluate(() => ({ live: !document.getElementById('live').hidden, board: /Laura/.test(document.getElementById('board').textContent) })), asked: dialogs.length };
167 page.__dismiss = false;
168 await page.keyboard.press('Enter'); // pregunta, y se dice que sí
169 await page.waitForTimeout(300);
170 const gone = await page.evaluate(() => ({ setup: !document.getElementById('setup').hidden, board: document.getElementById('board').textContent.trim() }));
171 C.ok('Parar con el teclado deja el foco en CSV, no en «Nueva llamada»', afterStop === 'exp', afterStop);
172 C.ok('«Nueva llamada» con la ficha sin guardar pregunta; si se dice que no, la llamada y la ficha siguen', kept.asked === 1 && /no se ha enviado ni descargado/.test(dialogs[0]) && kept.live && kept.board, { dialogs, kept });
173 C.ok('…y si se dice que sí, vuelve al inicio con la ficha borrada', dialogs.length === 2 && gone.setup && gone.board === '', { dialogs, gone });
174 C.ok('sin errores en la página', !errors.length, errors);
175 await ctx.close();
176}
177
178await browser.close(); srv.close();
179process.exit(C.done() ? 1 : 0);