utopia-ia/elffuss-code public
Changesets · Branches · Tags · Compare
| Changeset | 86f3b789392d8aed5f737aa17aeb8c187a504c5ddc1f693707ff8fa865e78ba2 |
|---|---|
| Author | KikoCis <kikocisneros@gmail.com> · 2026-10-10 15:09 +02:00 |
| Committer | KikoCis <kikocisneros@gmail.com> · 2026-10-11 14:16 +02:00 |
| Parents | 9d01cb86068a |
3 files changed
modified NOTICE +8 −0
| @@ -9,3 +9,11 @@ | ||
| 9 | 9 | (https://github.com/braedonsaunders/codeflow, MIT) — implementación nativa propia. |
| 10 | 10 | La vista «Ciudad 3D» (web/js/city.js) está inspirada en VibeCodeViewer |
| 11 | 11 | (https://github.com/Sendery/VibeCodeViewer, Apache-2.0) — implementación nativa propia. |
| 12 | + | |
| 13 | +--- Extensiones de VS Code (crédito) --- | |
| 14 | +Las gramáticas TextMate se aplican con vscode-textmate y vscode-oniguruma | |
| 15 | +(Microsoft, MIT), que se cargan del CDN jsDelivr solo cuando hacen falta; no se | |
| 16 | +incluyen en este repositorio. Los colores TextMate de los temas de serie | |
| 17 | +(web/js/ext/themes.js) siguen los temas por defecto de VS Code (Microsoft, MIT). | |
| 18 | +Las extensiones se buscan e instalan desde Open VSX (Eclipse Foundation), con la | |
| 19 | +licencia que declara cada una. |
modified README.md +16 −0
| @@ -47,6 +47,21 @@ | ||
| 47 | 47 | 5. **Optional real terminal.** A tiny local **Bridge** (opt-in) lets the agent run real |
| 48 | 48 | `node` / `npm` / `python` and read the output — still on your machine, nothing hosted. |
| 49 | 49 | |
| 50 | +## VS Code extensions: themes, grammars, snippets | |
| 51 | + | |
| 52 | +The **Extensions** button in the activity bar searches [Open VSX](https://open-vsx.org) | |
| 53 | +and installs the *declarative* part of VS Code extensions: **color themes** (with a | |
| 54 | +Color Theme picker), **TextMate grammars**, **snippets** and **language configurations** | |
| 55 | +(comments, brackets, indentation). You can also install a `.vsix` file. | |
| 56 | + | |
| 57 | +- **No extension code runs.** `main`/`browser` are ignored; the panel says what each | |
| 58 | + extension applies and what would need an extension host (commands, views, debuggers…). | |
| 59 | +- **Your project stays in the browser.** Open VSX only sees what you search for and install. | |
| 60 | +- Packages are checked against the SHA-256 that Open VSX publishes and kept in IndexedDB. | |
| 61 | +- Grammars run on the same engine as VS Code (vscode-textmate + Oniguruma), loaded from | |
| 62 | + the CDN only when a file needs one. Without extensions, nothing extra loads. | |
| 63 | +- `?noext` starts with every extension paused (to rescue a tab from a bad grammar). | |
| 64 | + | |
| 50 | 65 | ## Run locally |
| 51 | 66 | |
| 52 | 67 | ```bash |
| @@ -69,6 +84,7 @@ | ||
| 69 | 84 | js/ide.js Monaco, tabs, file tree, HTML preview |
| 70 | 85 | js/tools/code.js code.tree / read / search / edit / write (the only thing touching your files) |
| 71 | 86 | js/bridge.js optional local Bridge (real node/npm/python) |
| 87 | + js/ext/ VS Code extensions: Open VSX, .vsix reader, themes, grammars, snippets | |
| 72 | 88 | js/providers/ onnx (transformers.js) · api (OpenAI/Anthropic/Ollama) |
| 73 | 89 | server/serve.py static server + CORS proxy (dev) |
| 74 | 90 | ``` |
added tests/extensions.mjs +276 −0
| @@ -0,0 +1,276 @@ | ||
| 1 | +// Extensiones de VS Code en Elffuss Code (nivel 1: temas, gramáticas, | |
| 2 | +// snippets y lenguajes; nada de código de extensión). | |
| 3 | +// | |
| 4 | +// BASE=http://localhost:8999 node tests/extensions.mjs | |
| 5 | +// | |
| 6 | +// Las extensiones de prueba se fabrican aquí (ext_fixtures.mjs): sin red ni | |
| 7 | +// licencias. La parte EN VIVO instala dos extensiones reales de Open VSX | |
| 8 | +// (vscode.theme-monokai y vscode.make, de las «built-in» de VS Code, MIT); si | |
| 9 | +// no hay red, se marca NOT RUN y no cuenta como fallo. | |
| 10 | +import { chromium } from 'playwright'; | |
| 11 | +import { themeVsix, elfscriptVsix, THEME_DARK } from './ext_fixtures.mjs'; | |
| 12 | + | |
| 13 | +const OUT = (process.env.SCRATCH || '/tmp/elffuss-test'); | |
| 14 | +const BASE = process.env.BASE || 'http://localhost:8999'; | |
| 15 | +let fails = 0; | |
| 16 | +const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; }; | |
| 17 | +const notRun = (n, e) => console.log('⏭️ NOT RUN ' + n + (e ? ' — ' + e : '')); | |
| 18 | +const rgb = hex => { const h = hex.replace('#', ''); return `rgb(${parseInt(h.slice(0, 2), 16)}, ${parseInt(h.slice(2, 4), 16)}, ${parseInt(h.slice(4, 6), 16)})`; }; | |
| 19 | +const sleep = ms => new Promise(r => setTimeout(r, ms)); | |
| 20 | +async function hasta(fn, { tiempo = 15000, cada = 150 } = {}) { | |
| 21 | + const fin = Date.now() + tiempo; | |
| 22 | + let v; | |
| 23 | + while (Date.now() < fin) { try { v = await fn(); if (v) return v; } catch { /* reintenta */ } await sleep(cada); } | |
| 24 | + return v; | |
| 25 | +} | |
| 26 | + | |
| 27 | +const b = await chromium.launch(); | |
| 28 | +const ctx = await b.newContext(); | |
| 29 | +await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} }); | |
| 30 | +const p = await ctx.newPage(); | |
| 31 | +const errores = []; | |
| 32 | +// «Canceled»: Monaco deja escapar esa promesa si se cambia de fichero justo | |
| 33 | +// después de aceptar una sugerencia; pasa igual SIN extensiones, no es de aquí. | |
| 34 | +p.on('pageerror', e => { if (e.message !== 'Canceled') errores.push(e.message); }); | |
| 35 | +const pedidas = []; | |
| 36 | +p.on('request', r => pedidas.push(r.url())); | |
| 37 | + | |
| 38 | +// ── helpers dentro de la página ── | |
| 39 | +const fondo = () => p.evaluate(() => getComputedStyle(document.querySelector('#editor .monaco-editor-background') || document.querySelector('#editor .monaco-editor')).backgroundColor); | |
| 40 | +const abre = path => p.evaluate(async path => { await (await import('/js/ide.js')).openFile(path); }, path); | |
| 41 | +const lenguaje = () => p.evaluate(() => window.monaco.editor.getEditors()[0].getModel().getLanguageId()); | |
| 42 | +// estilo del primer span pintado cuyo texto es `txt` | |
| 43 | +const estilo = txt => p.evaluate(txt => { | |
| 44 | + for (const s of document.querySelectorAll('#editor .view-lines span span')) { | |
| 45 | + // Monaco pinta los espacios como U+00A0 | |
| 46 | + if (s.textContent.replace(/ /g, ' ').trim() === txt) { const cs = getComputedStyle(s); return { color: cs.color, italic: cs.fontStyle === 'italic' }; } | |
| 47 | + } | |
| 48 | + return null; | |
| 49 | +}, txt); | |
| 50 | +const colorDe = async (txt, hex) => hasta(async () => (await estilo(txt))?.color === rgb(hex), { tiempo: 8000 }); | |
| 51 | +const ponTexto = (texto) => p.evaluate(texto => { const ed = window.monaco.editor.getEditors()[0]; ed.getModel().setValue(texto); }, texto); | |
| 52 | +const instalaFichero = async (nombre, bytes) => { | |
| 53 | + await p.evaluate(() => { const m = document.getElementById('ext-msg'); if (m) { m.hidden = true; m.textContent = ''; } }); | |
| 54 | + await p.setInputFiles('#ext-file', { name: nombre, mimeType: 'application/octet-stream', buffer: Buffer.from(bytes) }); | |
| 55 | + return hasta(() => p.evaluate(() => { const m = document.getElementById('ext-msg'); return m && !m.hidden && m.textContent; }), { tiempo: 15000 }); | |
| 56 | +}; | |
| 57 | +const abrePanel = async () => { | |
| 58 | + await p.click('#act-ext'); | |
| 59 | + await p.waitForSelector('#ext-panel', { timeout: 10000 }); | |
| 60 | +}; | |
| 61 | +const filaInstalada = id => p.locator(`#ext-installed .ext-row[data-id="${id}"]`); | |
| 62 | + | |
| 63 | +// ── A. primer arranque: sin extensiones no se carga NADA nuevo ── | |
| 64 | +await p.goto(BASE + '/', { waitUntil: 'domcontentloaded' }); | |
| 65 | +await p.evaluate(async () => { | |
| 66 | + const o = await navigator.storage.getDirectory(); | |
| 67 | + 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(); }; | |
| 68 | + await w('app.js', '// nota\nconst a = 1;\n'); | |
| 69 | + await w('notes.elfs', '# hola\nspell fire with 42\n cast "llama"\nend\nᚱune\n'); | |
| 70 | + await w('Makefile', '# build\nall: build\n\tgcc -o app main.c\n'); | |
| 71 | +}); | |
| 72 | +pedidas.length = 0; | |
| 73 | +await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); | |
| 74 | +await hasta(() => p.evaluate(() => !!window.monaco?.editor?.getEditors?.().length)); | |
| 75 | +await sleep(800); | |
| 76 | +const extras = pedidas.filter(u => /\/js\/ext\/|\/css\/ext\.css|vscode-textmate|vscode-oniguruma|open-vsx|eclipsecontent/.test(u)); | |
| 77 | +ok('primer arranque sin extensiones: ni host, ni panel, ni motor TextMate, ni Open VSX', extras.length === 0, extras.join(' ')); | |
| 78 | +ok('tema de serie (vs-dark)', (await fondo()) === 'rgb(30, 30, 30)', await fondo()); | |
| 79 | + | |
| 80 | +// ── B. panel + tema desde un .vsix ── | |
| 81 | +await abrePanel(); | |
| 82 | +ok('el panel abre sin pedir nada a Open VSX (solo al buscar)', !pedidas.some(u => /open-vsx/.test(u))); | |
| 83 | +await instalaFichero('elf-theme.vsix', themeVsix()); | |
| 84 | +ok('tema instalado desde .vsix', await hasta(async () => (await filaInstalada('elffuss-test.elf-theme').count()) === 1), await p.locator('#ext-msg').textContent()); | |
| 85 | +const textoFila = await filaInstalada('elffuss-test.elf-theme').innerText(); | |
| 86 | +ok('la fila dice qué aplica y qué no (commands necesita código, main no se ejecuta)', /2 (temas|themes)/.test(textoFila) && /commands/.test(textoFila) && /(main\/browser)/.test(textoFila), textoFila.replace(/\s+/g, ' ').slice(0, 220)); | |
| 87 | +const chipOscuro = filaInstalada('elffuss-test.elf-theme').locator('.ext-theme-chips .ext-chip').first(); | |
| 88 | +await chipOscuro.click(); | |
| 89 | +ok('tema aplicado: fondo del editor', await hasta(async () => (await fondo()) === rgb(THEME_DARK.bg)), await fondo()); | |
| 90 | +ok('pestañas con los colores del tema (sin el url() malicioso)', await hasta(() => p.evaluate(() => (document.getElementById('ext-theme-chrome')?.textContent || '').includes('#203040') && !document.getElementById('ext-theme-chrome').textContent.includes('url(')))); | |
| 91 | +await p.click('#settings-close'); | |
| 92 | +await abre('app.js'); | |
| 93 | +ok('JS (Monarch): keyword con el color del tema', await colorDe('const', THEME_DARK.keyword), JSON.stringify(await estilo('const'))); | |
| 94 | +ok('JS (Monarch): comentario con color y cursiva del tema', (await colorDe('// nota', THEME_DARK.comment)) && (await estilo('// nota'))?.italic, JSON.stringify(await estilo('// nota'))); | |
| 95 | + | |
| 96 | +// ── C. lenguaje nuevo + gramática TextMate + snippets ── | |
| 97 | +await abrePanel(); | |
| 98 | +await instalaFichero('elfscript.vsix', elfscriptVsix()); | |
| 99 | +ok('extensión de lenguaje instalada', await hasta(async () => (await filaInstalada('elffuss-test.elfscript').count()) === 1)); | |
| 100 | +await p.click('#settings-close'); | |
| 101 | +await abre('notes.elfs'); | |
| 102 | +ok('.elfs → lenguaje elfscript (de la extensión)', await hasta(async () => (await lenguaje()) === 'elfscript'), await lenguaje()); | |
| 103 | +ok('motor TextMate bajado solo ahora (al abrir un fichero con gramática)', await hasta(() => pedidas.some(u => /vscode-textmate@9\.3\.2/.test(u)) && pedidas.some(u => /onig\.wasm/.test(u)))); | |
| 104 | +ok('gramática: keyword.control con el color exacto del tema', await colorDe('spell', THEME_DARK.control), JSON.stringify(await estilo('spell'))); | |
| 105 | +ok('gramática: comentario (color + cursiva) y cadena', (await colorDe('# hola', THEME_DARK.comment)) && (await estilo('# hola'))?.italic && await colorDe('"llama"', THEME_DARK.string), JSON.stringify([await estilo('# hola'), await estilo('"llama"')])); | |
| 106 | +ok('gramática: número y gramática incluida (plist .tmLanguage)', (await colorDe('42', THEME_DARK.number)) && await colorDe('ᚱune', THEME_DARK.keyword), JSON.stringify([await estilo('42'), await estilo('ᚱune')])); | |
| 107 | +ok('gramática: selector con contexto («source.elfs keyword») que Monarch no sabría aplicar', await colorDe('with', '#123456'), JSON.stringify(await estilo('with'))); | |
| 108 | +const ambitos = await p.evaluate(() => window.monaco.editor.tokenize('spell x\n# c', 'elfscript').flat().map(t => t.type)); | |
| 109 | +ok('tokens con los ámbitos de la gramática', ambitos.includes('keyword.control.elfs') && ambitos.includes('comment.line.number-sign.elfs'), ambitos.join(' ')); | |
| 110 | +await p.evaluate(() => { const ed = window.monaco.editor.getEditors()[0]; ed.setPosition({ lineNumber: 2, column: 1 }); ed.focus(); ed.trigger('t', 'editor.action.commentLine', {}); }); | |
| 111 | +ok('configuración del lenguaje: comentar línea usa «#»', (await p.evaluate(() => window.monaco.editor.getEditors()[0].getModel().getLineContent(2))).startsWith('# spell')); | |
| 112 | +// snippet en el lenguaje nuevo | |
| 113 | +await ponTexto(''); | |
| 114 | +await p.evaluate(() => { const ed = window.monaco.editor.getEditors()[0]; ed.setPosition({ lineNumber: 1, column: 1 }); ed.focus(); }); | |
| 115 | +await p.keyboard.type('elfsp'); | |
| 116 | +await p.evaluate(() => window.monaco.editor.getEditors()[0].trigger('t', 'editor.action.triggerSuggest', {})); | |
| 117 | +const visto = await hasta(() => p.evaluate(() => [...document.querySelectorAll('.suggest-widget.visible .monaco-list-row')].some(r => r.textContent.includes('elfspell')))); | |
| 118 | +ok('snippet sugerido al escribir el prefijo', visto); | |
| 119 | +await p.keyboard.press('Enter'); | |
| 120 | +// el \t del snippet sale con la sangría del fichero, como en VS Code | |
| 121 | +ok('snippet expandido (cuerpo en varias líneas con sus valores)', await hasta(async () => /^spell name\n(\t| +)cast fire\nend$/.test(await p.evaluate(() => window.monaco.editor.getEditors()[0].getModel().getValue()))), JSON.stringify(await p.evaluate(() => window.monaco.editor.getEditors()[0].getModel().getValue()))); | |
| 122 | +await p.keyboard.press('Escape'); | |
| 123 | +// snippet de la misma extensión para JavaScript | |
| 124 | +await abre('app.js'); | |
| 125 | +await ponTexto(''); | |
| 126 | +await p.evaluate(() => { const ed = window.monaco.editor.getEditors()[0]; ed.setPosition({ lineNumber: 1, column: 1 }); ed.focus(); }); | |
| 127 | +await p.keyboard.type('elflo'); | |
| 128 | +await p.evaluate(() => window.monaco.editor.getEditors()[0].trigger('t', 'editor.action.triggerSuggest', {})); | |
| 129 | +await hasta(() => p.evaluate(() => [...document.querySelectorAll('.suggest-widget.visible .monaco-list-row')].some(r => r.textContent.includes('elflog')))); | |
| 130 | +await p.keyboard.press('Enter'); | |
| 131 | +ok('snippet en JavaScript (otro lenguaje de la misma extensión)', await hasta(async () => (await p.evaluate(() => window.monaco.editor.getEditors()[0].getModel().getValue())) === "console.log('elf', );"), await p.evaluate(() => window.monaco.editor.getEditors()[0].getModel().getValue())); | |
| 132 | +await p.keyboard.press('Escape'); | |
| 133 | + | |
| 134 | +// ── D. las herramientas code.* del agente siguen trabajando sobre los modelos ── | |
| 135 | +await abre('notes.elfs'); | |
| 136 | +await p.evaluate(async () => { const code = await import('/js/tools/code.js'); await code.write({ path: 'notes.elfs', content: 'spell agent\n cast 7\nend\n' }); }); | |
| 137 | +ok('code.write refresca el modelo abierto', await hasta(async () => (await p.evaluate(() => window.monaco.editor.getEditors()[0].getModel().getValue())) === 'spell agent\n cast 7\nend\n')); | |
| 138 | +ok('…y la gramática sigue pintándolo', await colorDe('cast', THEME_DARK.control)); | |
| 139 | +const editado = await p.evaluate(async () => { const code = await import('/js/tools/code.js'); return code.edit({ path: 'notes.elfs', search: 'cast 7', replace: 'cast 8' }); }); | |
| 140 | +ok('code.edit sobre un fichero de la extensión', await hasta(async () => (await p.evaluate(() => window.monaco.editor.getEditors()[0].getModel().getValue())).includes('cast 8')), String(editado).slice(0, 80)); | |
| 141 | +ok('code.read devuelve el contenido', /cast 8/.test(await p.evaluate(async () => (await import('/js/tools/code.js')).read({ path: 'notes.elfs' })))); | |
| 142 | +await p.screenshot({ path: OUT + '/ext-grammar.png' }); | |
| 143 | + | |
| 144 | +// ── E. recargar conserva el estado ── | |
| 145 | +pedidas.length = 0; | |
| 146 | +await p.reload({ waitUntil: 'domcontentloaded' }); | |
| 147 | +await hasta(() => p.evaluate(() => !!window.monaco?.editor?.getEditors?.().length)); | |
| 148 | +ok('tras recargar: el host se carga al arrancar (hay extensiones)', await hasta(() => pedidas.some(u => /\/js\/ext\/host\.js/.test(u)))); | |
| 149 | +ok('tras recargar: el tema sigue', await hasta(async () => (await fondo()) === rgb(THEME_DARK.bg)), await fondo()); | |
| 150 | +await abre('notes.elfs'); | |
| 151 | +ok('tras recargar: la gramática sigue', await colorDe('spell', THEME_DARK.control), JSON.stringify(await estilo('spell'))); | |
| 152 | +await abrePanel(); | |
| 153 | +ok('tras recargar: las dos extensiones siguen instaladas', (await p.locator('#ext-installed .ext-row').count()) === 2); | |
| 154 | +const espejo = await p.evaluate(async () => (await import('/js/db.js')).get('kv', 'extensions')); | |
| 155 | +ok('la lista va al inventario del espacio de trabajo (kv «extensions»)', Array.isArray(espejo) && espejo.length === 2 && espejo.every(e => e.enabled), JSON.stringify(espejo)); | |
| 156 | + | |
| 157 | +// ── F. selector de tema: previsualiza, Escape deshace, Enter elige ── | |
| 158 | +await p.click('#ext-theme-btn'); | |
| 159 | +await p.waitForSelector('#ext-themepick'); | |
| 160 | +await p.keyboard.press('ArrowUp'); | |
| 161 | +const previa = await hasta(async () => (await fondo()) !== rgb(THEME_DARK.bg) && fondo()); | |
| 162 | +ok('selector: las flechas previsualizan', !!previa, String(previa)); | |
| 163 | +await p.keyboard.press('Escape'); | |
| 164 | +ok('selector: Escape deja el tema que había', await hasta(async () => (await fondo()) === rgb(THEME_DARK.bg))); | |
| 165 | +await p.click('#ext-theme-btn'); | |
| 166 | +await p.waitForSelector('#ext-themepick'); | |
| 167 | +await p.click('#ext-themepick .tp-item[data-theme="vs"]'); | |
| 168 | +ok('selector: tema claro de serie elegido', await hasta(async () => (await fondo()) === 'rgb(255, 255, 254)'), await fondo()); | |
| 169 | +ok('…y la gramática se repinta con colores de Light+', await colorDe('spell', '#AF00DB'), JSON.stringify(await estilo('spell'))); | |
| 170 | +await p.reload({ waitUntil: 'domcontentloaded' }); | |
| 171 | +await hasta(() => p.evaluate(() => !!window.monaco?.editor?.getEditors?.().length)); | |
| 172 | +ok('el tema elegido sobrevive a la recarga', await hasta(async () => (await fondo()) === 'rgb(255, 255, 254)'), await fondo()); | |
| 173 | +// por la paleta de comandos | |
| 174 | +await p.keyboard.press(process.platform === 'darwin' ? 'Meta+Shift+P' : 'Control+Shift+P'); | |
| 175 | +await p.fill('#pal-input', '>tema de color'); | |
| 176 | +let filas = await p.locator('#pal-list .pal-item').count(); | |
| 177 | +if (!filas) { await p.fill('#pal-input', '>color theme'); filas = await p.locator('#pal-list .pal-item').count(); } | |
| 178 | +ok('comando «Tema de color…» en la paleta', filas === 1); | |
| 179 | +await p.keyboard.press('Enter'); | |
| 180 | +await p.waitForSelector('#ext-themepick'); | |
| 181 | +await p.click(`#ext-themepick .tp-item[data-theme^="x-elffuss-test-elf-theme-elf-dark"]`); | |
| 182 | +ok('tema de la extensión elegido desde la paleta', await hasta(async () => (await fondo()) === rgb(THEME_DARK.bg))); | |
| 183 | + | |
| 184 | +// ── G. ?noext: todo en pausa ── | |
| 185 | +await p.goto(BASE + '/?test-opfs&noext', { waitUntil: 'domcontentloaded' }); | |
| 186 | +await hasta(() => p.evaluate(() => !!window.monaco?.editor?.getEditors?.().length)); | |
| 187 | +await sleep(600); | |
| 188 | +ok('?noext: se arranca sin aplicar extensiones', (await fondo()) === 'rgb(30, 30, 30)', await fondo()); | |
| 189 | +await abre('notes.elfs'); | |
| 190 | +ok('?noext: el .elfs queda en texto plano', (await lenguaje()) === 'plaintext'); | |
| 191 | +await abrePanel(); | |
| 192 | +ok('?noext: el panel lo avisa', await p.locator('.ext-paused').count() === 1); | |
| 193 | +await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); | |
| 194 | +await hasta(() => p.evaluate(() => !!window.monaco?.editor?.getEditors?.().length)); | |
| 195 | + | |
| 196 | +// ── H. desactivar y desinstalar lo deshacen todo ── | |
| 197 | +await abre('notes.elfs'); | |
| 198 | +await colorDe('spell', THEME_DARK.control); | |
| 199 | +await abrePanel(); | |
| 200 | +await filaInstalada('elffuss-test.elf-theme').locator('.ext-toggle').click(); | |
| 201 | +ok('desactivar el tema → vuelve el oscuro de serie y las pestañas de siempre', await hasta(async () => (await fondo()) === 'rgb(30, 30, 30)' && !(await p.evaluate(() => document.getElementById('ext-theme-chrome')?.textContent))), await fondo()); | |
| 202 | +ok('…y la gramática se repinta con Dark+', await colorDe('spell', '#C586C0'), JSON.stringify(await estilo('spell'))); | |
| 203 | +await filaInstalada('elffuss-test.elfscript').locator('.ext-toggle').click(); | |
| 204 | +ok('desactivar el lenguaje → el .elfs vuelve a texto plano', await hasta(async () => (await lenguaje()) === 'plaintext'), await lenguaje()); | |
| 205 | +await p.click('#settings-close'); | |
| 206 | +await abre('app.js'); | |
| 207 | +await ponTexto(''); | |
| 208 | +await p.evaluate(() => { const ed = window.monaco.editor.getEditors()[0]; ed.setPosition({ lineNumber: 1, column: 1 }); ed.focus(); }); | |
| 209 | +await p.keyboard.type('elflo'); | |
| 210 | +await p.evaluate(() => window.monaco.editor.getEditors()[0].trigger('t', 'editor.action.triggerSuggest', {})); | |
| 211 | +await sleep(1200); | |
| 212 | +ok('…y sus snippets ya no se ofrecen', !(await p.evaluate(() => [...document.querySelectorAll('.suggest-widget.visible .monaco-list-row')].some(r => r.textContent.includes('elflog'))))); | |
| 213 | +await p.keyboard.press('Escape'); | |
| 214 | +await abrePanel(); | |
| 215 | +await filaInstalada('elffuss-test.elfscript').locator('.ext-toggle').click(); | |
| 216 | +await abre('notes.elfs'); | |
| 217 | +ok('reactivar el lenguaje lo devuelve', await hasta(async () => (await lenguaje()) === 'elfscript') && await colorDe('spell', '#C586C0')); | |
| 218 | +p.once('dialog', d => d.accept()); | |
| 219 | +await filaInstalada('elffuss-test.elfscript').locator('.ext-uninstall').click(); | |
| 220 | +ok('desinstalar el lenguaje', await hasta(async () => (await filaInstalada('elffuss-test.elfscript').count()) === 0 && (await lenguaje()) === 'plaintext')); | |
| 221 | +p.once('dialog', d => d.accept()); | |
| 222 | +await filaInstalada('elffuss-test.elf-theme').locator('.ext-uninstall').click(); | |
| 223 | +ok('desinstalar el tema', await hasta(async () => (await p.locator('#ext-installed .ext-row').count()) === 0)); | |
| 224 | +const restos = await p.evaluate(() => new Promise(res => { | |
| 225 | + const r = indexedDB.open('elffuss-code-ext'); | |
| 226 | + r.onsuccess = () => { const q = r.result.transaction('files').objectStore('files').getAllKeys(); q.onsuccess = () => { res(q.result.length); r.result.close(); }; }; | |
| 227 | + r.onerror = () => res(-1); | |
| 228 | +})); | |
| 229 | +ok('sin restos en IndexedDB tras desinstalar', restos === 0, String(restos)); | |
| 230 | +ok('kv «extensions» vacía', JSON.stringify(await p.evaluate(async () => (await import('/js/db.js')).get('kv', 'extensions'))) === '[]'); | |
| 231 | + | |
| 232 | +// ── I. EN VIVO contra Open VSX ── | |
| 233 | +const red = await p.evaluate(async () => { try { return (await fetch('https://open-vsx.org/api/vscode/theme-monokai', { credentials: 'omit' })).ok; } catch { return false; } }); | |
| 234 | +if (!red) { | |
| 235 | + notRun('instalación en vivo desde Open VSX', 'sin acceso a open-vsx.org'); | |
| 236 | +} else { | |
| 237 | + await p.fill('#ext-q', 'monokai'); | |
| 238 | + const fila = p.locator('#ext-results .ext-row[data-id="vscode.theme-monokai"]'); | |
| 239 | + ok('Open VSX: búsqueda con resultados', await hasta(async () => (await fila.count()) === 1, { tiempo: 20000 })); | |
| 240 | + await fila.locator('.ext-main').click(); | |
| 241 | + ok('Open VSX: el detalle dice qué aplicaría (sin bajar el .vsix)', await hasta(async () => /1 (tema|theme)/.test(await fila.locator('.ext-detail').innerText()), { tiempo: 20000 }), await fila.locator('.ext-detail').innerText()); | |
| 242 | + await fila.locator('.ext-install').click(); | |
| 243 | + ok('Open VSX: vscode.theme-monokai instalada (SHA-256 comprobada)', await hasta(async () => (await filaInstalada('vscode.theme-monokai').count()) === 1, { tiempo: 30000 }) && /SHA-256/.test(await filaInstalada('vscode.theme-monokai').innerText())); | |
| 244 | + await filaInstalada('vscode.theme-monokai').locator('.ext-theme-chips .ext-chip').first().click(); | |
| 245 | + ok('Monokai aplicado', await hasta(async () => (await fondo()) === 'rgb(39, 40, 34)'), await fondo()); | |
| 246 | + const r = await p.evaluate(async () => { | |
| 247 | + const host = await (await import('/js/ide.js')).loadExt(); | |
| 248 | + try { const rec = await host.install({ namespace: 'vscode', name: 'make', version: '1.95.3' }); return rec.id; } catch (e) { return 'ERR ' + e.message; } | |
| 249 | + }); | |
| 250 | + ok('Open VSX: vscode.make instalada', r === 'vscode.make', r); | |
| 251 | + await p.click('#settings-close').catch(() => {}); | |
| 252 | + await abre('Makefile'); | |
| 253 | + ok('Makefile → lenguaje makefile', await hasta(async () => (await lenguaje()) === 'makefile'), await lenguaje()); | |
| 254 | + const tipos = await p.evaluate(() => window.monaco.editor.tokenize('all: build\n# c', 'makefile').flat().map(t => t.type)); | |
| 255 | + ok('Makefile: ámbitos de la gramática real', tipos.some(t => /entity\.name\.function\.target\.makefile/.test(t)) && tipos.some(t => /comment/.test(t)), tipos.join(' ')); | |
| 256 | + ok('Makefile: el objetivo con el color de función de Monokai', await colorDe('all', '#A6E22E'), JSON.stringify(await estilo('all'))); | |
| 257 | + await p.screenshot({ path: OUT + '/ext-monokai-make.png' }); | |
| 258 | + // una gramática para un lenguaje que Monaco YA tiene (JavaScript): la | |
| 259 | + // sustituye, y al desactivarla vuelve el coloreado de serie (Monarch) | |
| 260 | + const js = await p.evaluate(async () => { | |
| 261 | + const host = await (await import('/js/ide.js')).loadExt(); | |
| 262 | + try { await host.install({ namespace: 'vscode', name: 'javascript', version: '1.95.3' }); return 'ok'; } catch (e) { return 'ERR ' + e.message; } | |
| 263 | + }); | |
| 264 | + ok('Open VSX: vscode.javascript instalada', js === 'ok', js); | |
| 265 | + await abre('app.js'); | |
| 266 | + await ponTexto('const a = 1; // x\n'); | |
| 267 | + ok('JS con la gramática TextMate de VS Code (storage.type.js)', await hasta(async () => (await p.evaluate(() => window.monaco.editor.tokenize('const a = 1;', 'javascript')[0].map(t => t.type))).includes('storage.type.js'))); | |
| 268 | + await p.evaluate(async () => { const host = await (await import('/js/ide.js')).loadExt(); await host.setEnabled('vscode.javascript', false); }); | |
| 269 | + ok('desactivarla devuelve el Monarch de serie de Monaco (keyword.js)', await hasta(async () => (await p.evaluate(() => window.monaco.editor.tokenize('const a = 1;', 'javascript')[0].map(t => t.type))).includes('keyword.js'))); | |
| 270 | + ok('…y el fichero abierto se repinta con Monokai vía Monarch', await colorDe('const', '#F92672'), JSON.stringify(await estilo('const'))); | |
| 271 | +} | |
| 272 | + | |
| 273 | +ok('sin errores de página', !errores.length, errores.slice(0, 3).join(' | ')); | |
| 274 | +console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ EXTENSIONES DE VS CODE (nivel 1) OK'); | |
| 275 | +await b.close(); | |
| 276 | +process.exit(fails ? 1 : 0); |