| 1 | // Bug real reportado: un enlace del chat con solo el NOMBRE del fichero |
| 2 | // («config.py») fallaba con «no existe» aunque el fichero real vivía en una |
| 3 | // subcarpeta (drone_hacker/config.py) — el mensaje de error ya lo SUGERÍA |
| 4 | // («¿Quizá: drone_hacker/config.py?») pero no se abría solo. openFile ahora |
| 5 | // resuelve por nombre cuando hay una única coincidencia en el proyecto. |
| 6 | import { chromium } from 'playwright'; |
| 7 | const BASE = process.env.BASE || 'http://localhost:8799'; |
| 8 | let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; }; |
| 9 | |
| 10 | const b = await chromium.launch(); |
| 11 | const ctx = await b.newContext({ locale: 'es-ES' }); await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} }); |
| 12 | const p = await ctx.newPage(); |
| 13 | await p.goto(BASE + '/', { waitUntil: 'domcontentloaded' }); |
| 14 | await p.evaluate(async () => { |
| 15 | const o = await navigator.storage.getDirectory(); |
| 16 | const dir = await o.getDirectoryHandle('drone_hacker', { create: true }); |
| 17 | const f = await dir.getFileHandle('config.py', { create: true }); |
| 18 | const s = await f.createWritable(); await s.write('# el config real de drone_hacker'); await s.close(); |
| 19 | // un homónimo AMBIGUO en otra carpeta, para el caso de "varias coincidencias" |
| 20 | const dir2 = await o.getDirectoryHandle('otro', { create: true }); |
| 21 | const f2 = await dir2.getFileHandle('ambiguo.py', { create: true }); const s2 = await f2.createWritable(); await s2.write('a'); await s2.close(); |
| 22 | const dir3 = await o.getDirectoryHandle('mas', { create: true }); |
| 23 | const f3 = await dir3.getFileHandle('ambiguo.py', { create: true }); const s3 = await f3.createWritable(); await s3.write('b'); await s3.close(); |
| 24 | }); |
| 25 | await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); await p.waitForTimeout(1500); |
| 26 | |
| 27 | // caso EXACTO del bug: el chat menciona solo "config.py" (sin ruta) |
| 28 | await p.evaluate(async () => { |
| 29 | const m = await import('/js/main.js'); |
| 30 | m.reportImprovements({ proposals: [{ dept: 'Arquitectura', text: 'Revisa el fichero de configuración con sustancia suficiente para el filtro de calidad.' }, { dept: 'Calidad', text: 'Otra propuesta sólida y con contenido real para el segundo departamento.' }], path: 'config.py' }); |
| 31 | }); |
| 32 | await p.waitForTimeout(300); |
| 33 | await p.locator('.msg.md code.file-link', { hasText: 'config.py' }).first().click(); |
| 34 | await p.waitForTimeout(600); |
| 35 | ok('el enlace con SOLO el nombre abre el fichero REAL (resuelto por nombre)', /drone_hacker\/config\.py|config\.py/.test(await p.locator('#tabs-bar').innerText())); |
| 36 | ok('sin barra de error (no falló)', await p.locator('#statusbar').innerText().then(t => !/No pude abrir/.test(t))); |
| 37 | const content = await p.evaluate(() => window.monaco?.editor.getModels().map(m => m.getValue()).join('|') || ''); |
| 38 | ok('el contenido es el REAL del fichero resuelto', /el config real de drone_hacker/.test(content), content.slice(0, 50)); |
| 39 | |
| 40 | // homónimos AMBIGUOS (2 ficheros con el mismo nombre) → error claro, no adivina |
| 41 | const openRes = await p.evaluate(async () => { |
| 42 | const ide = await import('/js/ide.js'); |
| 43 | try { await ide.openFile('ambiguo.py'); return 'ok'; } catch (e) { return 'err:' + e.message; } |
| 44 | }); |
| 45 | const ambiguousTab = await p.locator('#tabs-bar').innerText(); |
| 46 | ok('con homónimos ambiguos NO abre ninguno al azar (sin pestaña ambiguo.py suelta sin contexto)', !/^ambiguo\.py$/m.test(ambiguousTab.split('\n').find(l => l === 'ambiguo.py') || '')); |
| 47 | |
| 48 | // contador de streaming: dice "car." (caracteres), no ambigüo con tokens |
| 49 | await p.evaluate(async () => { |
| 50 | const m = await import('/js/main.js'); |
| 51 | const th = m.thinkingBubble(); |
| 52 | th.tick('hola'); |
| 53 | window.__label = document.querySelector('.msg.thinking span').textContent; |
| 54 | th.remove(); |
| 55 | }); |
| 56 | const labelText = await p.evaluate(() => window.__label); |
| 57 | ok('el contador de streaming se etiqueta como caracteres, no tokens', /car\./.test(labelText), labelText); |
| 58 | |
| 59 | console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ ENLACES DEL CHAT (resolución por nombre) OK'); |
| 60 | await b.close(); |
| 61 | process.exit(fails ? 1 : 0); |