| 1 | // Los paths entre backticks en el chat deben poder abrirse directamente (sin |
| 2 | // tener que ir a buscarlos a mano), y NO confundirse con código real que |
| 3 | // también use backticks. |
| 4 | import { chromium } from 'playwright'; |
| 5 | const BASE = process.env.BASE || 'http://localhost:8799'; |
| 6 | let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; }; |
| 7 | |
| 8 | const b = await chromium.launch(); |
| 9 | const ctx = await b.newContext(); await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} }); |
| 10 | const p = await ctx.newPage(); |
| 11 | await p.goto(BASE + '/', { waitUntil: 'domcontentloaded' }); |
| 12 | await p.evaluate(async () => { |
| 13 | const o = await navigator.storage.getDirectory(); |
| 14 | const w = async (n, t) => { const f = await o.getFileHandle(n, { create: true }); const s = await f.createWritable(); await s.write(t); await s.close(); }; |
| 15 | await w('README.md', '# el fichero real que se abrirá'); |
| 16 | const dir = await o.getDirectoryHandle('.elffuss', { create: true }).then(d => d.getDirectoryHandle('soul', { create: true })); |
| 17 | const f = await dir.getFileHandle('nota.md', { create: true }); const s = await f.createWritable(); await s.write('# nota real'); await s.close(); |
| 18 | }); |
| 19 | await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); await p.waitForTimeout(1500); |
| 20 | |
| 21 | const addMsg = (cls, text) => p.evaluate(async ({ cls, text }) => { |
| 22 | // addMsg no está exportado (closure de main.js): la disparamos vía el mismo |
| 23 | // camino real que usa la app — reportImprovements, que SÍ está exportado y |
| 24 | // hace addMsg con un path entre backticks, exactamente el caso real. |
| 25 | const m = await import('/js/main.js'); |
| 26 | m.reportImprovements({ proposals: [{ dept: 'Arquitectura', text: 'Propuesta con sustancia suficiente para pasar el filtro de calidad, de verdad.' }, { dept: 'Calidad', text: 'Otra propuesta sólida y con contenido real para el segundo departamento.' }], path: text }); |
| 27 | }, { cls, text }); |
| 28 | |
| 29 | await addMsg('assistant', 'README.md'); |
| 30 | await p.waitForTimeout(300); |
| 31 | const link1 = p.locator('.msg.md code.file-link', { hasText: 'README.md' }); |
| 32 | ok('el path entre backticks se convierte en enlace clicable', await link1.count() > 0); |
| 33 | |
| 34 | // clic → abre el fichero REAL en el editor (Monaco) |
| 35 | await link1.first().click(); |
| 36 | await p.waitForTimeout(600); |
| 37 | const tabText = await p.locator('#tabs-bar').innerText().catch(() => ''); |
| 38 | ok('el clic abre el fichero REAL en una pestaña del editor', /README\.md/.test(tabText), tabText); |
| 39 | const editorContent = await p.evaluate(() => window.monaco?.editor.getModels().map(m => m.getValue()).join('|') || ''); |
| 40 | ok('el contenido mostrado es el REAL del fichero', /el fichero real que se abrirá/.test(editorContent), editorContent.slice(0, 60)); |
| 41 | |
| 42 | // ruta con subcarpetas también debe funcionar |
| 43 | await addMsg('assistant', '.elffuss/soul/nota.md'); |
| 44 | await p.waitForTimeout(300); |
| 45 | const link2 = p.locator('.msg.md code.file-link', { hasText: '.elffuss/soul/nota.md' }); |
| 46 | ok('rutas con subcarpetas también se linkan', await link2.count() > 0); |
| 47 | await link2.first().click(); |
| 48 | await p.waitForTimeout(600); |
| 49 | ok('abre el fichero real dentro de subcarpetas', /nota\.md/.test(await p.locator('#tabs-bar').innerText())); |
| 50 | |
| 51 | // un código que NO es un path (JS de verdad) no debe volverse clicable ni romperse |
| 52 | const codeMsgOk = await p.evaluate(async () => { |
| 53 | const m = await import('/js/main.js'); |
| 54 | m.reportImprovements({ proposals: [{ dept: 'Rendimiento', text: 'usa `const x = 1` en vez de var, y sustancia de sobra para el filtro' }, { dept: 'Producto/DX', text: 'otra propuesta con suficiente sustancia real para el segundo hueco' }], path: null }); |
| 55 | return true; |
| 56 | }); |
| 57 | ok('reportImprovements con snippet de código no-path no rompe nada', codeMsgOk); |
| 58 | const nonFileLink = p.locator('.msg.md code', { hasText: 'const x = 1' }); |
| 59 | ok('un snippet de código real NO se vuelve un file-link', await nonFileLink.evaluate(el => el.classList.contains('file-link')).catch(() => false) === false); |
| 60 | |
| 61 | console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ PATHS CLICABLES EN EL CHAT OK'); |
| 62 | await b.close(); |
| 63 | process.exit(fails ? 1 : 0); |