| 1 | // What the user sees of level 2: the panel's "what will work" lines, the |
| 2 | // "Works in Code" filter, sizes, a phone, the new overlays' roles and keys, and |
| 3 | // that Code looks the same with code extensions running. |
| 4 | // |
| 5 | // node tests/x2_ux.mjs (own server; Open VSX mocked with context.route) |
| 6 | // |
| 7 | // X1 every kind of extension says, before installing, what will work: |
| 8 | // declarative parts, browser code that runs in the sandbox (with what it |
| 9 | // brings), "Needs Node", workbench parts that won't appear, why its code |
| 10 | // can't run (engine, proposed APIs, never activated, failed in the |
| 11 | // census), and "Tested in Code" or "Not tested in Code yet"; the run |
| 12 | // button is there, or inert with its reason |
| 13 | // X2 the "Works in Code" chip: a toggle (aria-pressed), hides what cannot |
| 14 | // work, says how many it checked, and says Open VSX sees those lookups |
| 15 | // X3 sizes: the consent dialog shows the runtime's size from the vendor |
| 16 | // manifest and the extension's own size |
| 17 | // X4 at 390×844: the panel, the consent dialog and an extension's dialogs |
| 18 | // fit with no horizontal scroll, and a command runs from the panel |
| 19 | // X5 roles and keys: the consent and modal dialogs trap Tab, start on |
| 20 | // Cancel, close on Escape and give the focus back; the quick pick is a |
| 21 | // combobox with a listbox, arrows move aria-activedescendant, Enter picks |
| 22 | // X6 the computed styles of 25 of Code's own elements are identical with |
| 23 | // and without code extensions running (no global CSS clash) |
| 24 | // X1b "Install" on a result that only brings code, with its details closed: |
| 25 | // its manifest is read first (no .vsix), the row shows "Install and run |
| 26 | // its code…" with the focus on it, and the message points at it |
| 27 | // X2b the filter turned on before any details are opened: rows still say |
| 28 | // what will work and offer the code button |
| 29 | // X3 also: "Install without its code" in the consent of a mixed extension, |
| 30 | // and the dialogs' primary button at 4.5:1 or more |
| 31 | // X7 where level 2 cannot start (Code served on a host config.js gives no |
| 32 | // sandbox): the lines say so, the run button is inert with the reason, |
| 33 | // and the filter hides what only brings code |
| 34 | // X8 keyboard: F6 and Code's palette reach a notification and come back, |
| 35 | // focus never falls to the page, a notification without buttons waits |
| 36 | // while hovered or focused, the quick pick and input box keep Tab inside |
| 37 | // and close on Escape from their buttons, Space checks with a filter |
| 38 | // X9 "Block requests for this session": the next request is dropped and |
| 39 | // the status bar says so, the user's own editor links still ask, the |
| 40 | // panel shows the block with Unblock |
| 41 | // X10 "Turn off all extension code" keeps the focus and announces it; the |
| 42 | // run button names its action, without aria-pressed |
| 43 | // X4b at 360×640 a long address: title and site in view, the address |
| 44 | // scrolls in its own box, the site repeated by the buttons; a |
| 45 | // notification does not cover the chat prompt |
| 46 | // X11 a tab opened before the sandbox ran is seen by extensions (onLanguage) |
| 47 | // X12 in Spanish, level 2's texts are Spanish (the keybindings not bound) |
| 48 | import fs from 'node:fs'; |
| 49 | import path from 'node:path'; |
| 50 | import { fileURLToPath } from 'node:url'; |
| 51 | import { chromium } from 'playwright'; |
| 52 | import { startServer } from './lib/x2-server.mjs'; |
| 53 | import { mockOpenVsx } from './lib/openvsx-mock.mjs'; |
| 54 | import { seed, UI, NOOP, SORT, FMT } from './lib/x2-fixtures.mjs'; |
| 55 | |
| 56 | const HERE = path.dirname(fileURLToPath(import.meta.url)); |
| 57 | let fails = 0; |
| 58 | const ok = (name, c, extra = '') => { console.log((c ? '✅' : '❌') + ' ' + name + (extra ? ' — ' + extra : '')); if (!c) fails++; }; |
| 59 | const sleep = ms => new Promise(r => setTimeout(r, ms)); |
| 60 | async function until(fn, { timeout = 20000, every = 150 } = {}) { |
| 61 | const end = Date.now() + timeout; |
| 62 | let v; |
| 63 | while (Date.now() < end) { try { v = await fn(); if (v) return v; } catch { /* reintenta */ } await sleep(every); } |
| 64 | return v; |
| 65 | } |
| 66 | |
| 67 | // ── manifiestos de prueba: uno por cada caso de «qué funcionará» ── |
| 68 | const base = (name, extra = {}, { namespace = 'elffuss-ux', version = '1.0.0' } = {}) => ({ |
| 69 | namespace, name, version, keywords: ['elffuss-ux'], published: null, |
| 70 | manifest: { name, publisher: namespace, version, displayName: 'UX ' + name, license: 'MIT', engines: { vscode: '^1.80.0' }, ...extra }, |
| 71 | }); |
| 72 | const theme = { themes: [{ label: 'T', uiTheme: 'vs-dark', path: './t.json' }] }; |
| 73 | const fixtures = [ |
| 74 | base('decl', { contributes: theme }), |
| 75 | base('webok', { browser: './web.js', contributes: { commands: [{ command: 'w.a', title: 'A' }, { command: 'w.b', title: 'B' }], keybindings: [{ command: 'w.a', key: 'alt+k' }], configuration: { properties: { 'w.one': { type: 'string' }, 'w.two': { type: 'boolean' }, 'w.three': { type: 'number' } } } } }), |
| 76 | base('nodetheme', { main: './out.js', contributes: theme }), |
| 77 | base('webviews', { browser: './web.js', contributes: { views: { explorer: [{ id: 'v', name: 'V' }] }, viewsContainers: { activitybar: [{ id: 'c', title: 'C', icon: 'i.svg' }] }, commands: [{ command: 'v.a', title: 'A' }] } }), |
| 78 | base('webengine', { browser: './web.js', engines: { vscode: '^1.200.0' } }), |
| 79 | base('webproposals', { browser: './web.js', enabledApiProposals: ['fileSearchProvider'] }), |
| 80 | base('webnever', { browser: './web.js', activationEvents: ['workspaceContains:**/never.txt'] }), |
| 81 | // solo Node y un lenguaje que Monaco ya trae (como Pyrefly): nada se aplica |
| 82 | base('pyreflike', { main: './out.js', contributes: { languages: [{ id: 'python', aliases: ['Python'], extensions: ['.py'] }] } }), |
| 83 | // tema Y código para el navegador: el consentimiento ofrece instalarla sin su código |
| 84 | base('mixedcode', { browser: './web.js', contributes: { ...theme, commands: [{ command: 'm.a', title: 'A' }] } }), |
| 85 | // del censo (web/js/ext2/tested.json): una que arranca y una que falla |
| 86 | base('prettier-vscode', { browser: './dist/web-extension.cjs', displayName: 'Prettier - Code formatter' }, { namespace: 'esbenp', version: '12.4.0' }), |
| 87 | base('gitlens', { browser: './dist/browser/gitlens.js', displayName: 'GitLens' }, { namespace: 'eamodio', version: '2026.10.90519' }), |
| 88 | ]; |
| 89 | for (const f of fixtures) f.keywords = ['elffuss-ux']; |
| 90 | |
| 91 | const srv = await startServer(); |
| 92 | const browser = await chromium.launch(); |
| 93 | const errors = []; |
| 94 | async function profile({ width = 1280, height = 860, mock = true } = {}) { |
| 95 | const ctx = await browser.newContext({ viewport: { width, height } }); |
| 96 | await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); localStorage.setItem('elffusscode.ext.onlyWorks', '0'); } catch { /* — */ } }); |
| 97 | if (mock) await mockOpenVsx(ctx, fixtures); |
| 98 | const page = await ctx.newPage(); |
| 99 | page.on('pageerror', e => { if (e.message !== 'Canceled') errors.push(e.message); }); |
| 100 | await page.goto(srv.codeOrigin + '/', { waitUntil: 'domcontentloaded' }); |
| 101 | await page.evaluate(async () => { |
| 102 | const o = await navigator.storage.getDirectory(); |
| 103 | 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(); }; |
| 104 | await w('fruits.txt', 'pear\napple\nfig\n'); |
| 105 | await w('app.js', 'function zeta() {}\n'); |
| 106 | }); |
| 107 | return { ctx, page }; |
| 108 | } |
| 109 | const openIde = async page => { |
| 110 | await page.goto(srv.codeOrigin + '/?test-opfs', { waitUntil: 'domcontentloaded' }); |
| 111 | await page.waitForFunction(() => !!window.monaco?.editor?.getEditors?.().length, null, { timeout: 30000 }); |
| 112 | }; |
| 113 | const panel = async page => { await page.evaluate(() => { if (!(document.getElementById('ext-panel')?.isConnected && !document.getElementById('settings-panel').hidden)) document.getElementById('act-ext').click(); }); await until(() => page.evaluate(() => !document.getElementById('settings-panel').hidden && !!document.getElementById('ext-panel'))); }; |
| 114 | const search = async (page, q) => { await page.fill('#ext-q', q); await page.press('#ext-q', 'Enter'); }; |
| 115 | const row = (page, id) => page.locator(`#ext-results .ext-row[data-id="${id}"]`); |
| 116 | |
| 117 | // ── X1: qué funcionará ── |
| 118 | const { ctx, page } = await profile(); |
| 119 | await openIde(page); |
| 120 | await panel(page); |
| 121 | await search(page, 'elffuss-ux'); |
| 122 | await until(async () => (await page.locator('#ext-results .ext-row').count()) === fixtures.length); |
| 123 | async function detail(id) { |
| 124 | await row(page, id).locator('.ext-name').click(); |
| 125 | const text = await until(async () => { const t = await row(page, id).locator('.ext-detail').innerText(); return /Licence|License/.test(t) ? t : null; }); |
| 126 | const run = await row(page, id).evaluate(r => { const b = r.querySelector('.ext-install-code'); return b ? { inert: b.getAttribute('aria-disabled') === 'true', title: b.title } : null; }); |
| 127 | const install = await row(page, id).evaluate(r => { const b = r.querySelector('.ext-install'); return b ? { inert: b.getAttribute('aria-disabled') === 'true', title: b.title } : null; }); |
| 128 | return { text: text || '', run, install }; |
| 129 | } |
| 130 | const d = {}; |
| 131 | for (const f of fixtures) d[f.name] = await detail(`${f.namespace}.${f.name}`); |
| 132 | ok('X1 declarative only: "Works now (no code)", once, and no run button', /Works now \(no code\): 1 theme/.test(d.decl.text) && !/Applies:/.test(d.decl.text) && !d.decl.run, JSON.stringify(d.decl)); |
| 133 | ok('X1 browser code: runs in the sandbox, with what it brings, and "Not tested in Code yet"', /Runs in Code’s sandbox: 2 commands, 1 keybinding, 3 settings\. No internet; sees only the files you open\./.test(d.webok.text) |
| 134 | && /Not tested in Code yet/.test(d.webok.text) && d.webok.run && !d.webok.run.inert, JSON.stringify(d.webok)); |
| 135 | ok('X1 …and nothing contradicts it ("Nothing … can be applied", "needs its code")', !/Nothing in this extension|needs its code/.test(d.webok.text + d.webviews.text + d['prettier-vscode'].text), JSON.stringify(d.webok.text)); |
| 136 | ok('X1 Node only: "Needs Node: not available in the browser", and its theme still applies', /Needs Node: not available in the browser\. Only its themes, grammars and snippets apply\./.test(d.nodetheme.text) |
| 137 | && /Works now \(no code\): 1 theme/.test(d.nodetheme.text) && !d.nodetheme.run, JSON.stringify(d.nodetheme)); |
| 138 | ok('X1 workbench parts: "Won’t appear here: views"', /Won’t appear here: views/.test(d.webviews.text) && d.webviews.run && !d.webviews.run.inert, JSON.stringify(d.webviews)); |
| 139 | ok('X1 proposed APIs: it runs, with a warning, and the run button works', /Runs in Code’s sandbox/.test(d.webproposals.text) && /Uses proposed VS Code APIs, which Code doesn’t turn on: some of its features may fail\./.test(d.webproposals.text) |
| 140 | && !/can’t run here/.test(d.webproposals.text) && d.webproposals.run && !d.webproposals.run.inert, JSON.stringify(d.webproposals)); |
| 141 | ok('X1 Node with only a language Monaco already has (like Pyrefly): "Needs Node", no "Works now", one line saying nothing applies, Install inert', |
| 142 | /Needs Node: not available in the browser\./.test(d.pyreflike.text) && !/Works now|Only its themes/.test(d.pyreflike.text) && !d.pyreflike.run |
| 143 | && d.pyreflike.install?.inert && /Nothing in this extension can be applied here/.test(d.pyreflike.install.title), JSON.stringify(d.pyreflike)); |
| 144 | for (const [k, why] of [['webengine', /needs a newer VS Code than 1\.138\.0/], ['webnever', /nothing in Code starts it/]]) { |
| 145 | ok(`X1 ${k}: why its code can’t run, and the run button inert with that reason`, why.test(d[k].text) && d[k].run?.inert && why.test(d[k].run.title), JSON.stringify(d[k])); |
| 146 | } |
| 147 | ok('X1 from the census: "Tested in Code: starts, … formatter"', /Tested in Code: starts.*formatter/.test(d['prettier-vscode'].text) && !d['prettier-vscode'].run.inert, JSON.stringify(d['prettier-vscode'])); |
| 148 | ok('X1 failed in the census: "doesn’t start here", run button inert', /Tested in Code: doesn’t start here/.test(d.gitlens.text) && d.gitlens.run?.inert && /failed when tested in Code/.test(d.gitlens.run.title), JSON.stringify(d.gitlens).slice(0, 300)); |
| 149 | |
| 150 | // ── X2: el filtro ── |
| 151 | const chip = page.locator('#ext-works'); |
| 152 | ok('X2 the chip is a toggle, off by default', (await chip.getAttribute('aria-pressed')) === 'false' && (await chip.evaluate(b => b.tagName)) === 'BUTTON'); |
| 153 | await chip.click(); |
| 154 | const filtered = await until(async () => { |
| 155 | const ids = await page.locator('#ext-results .ext-row').evaluateAll(rs => rs.filter(r => !r.hidden).map(r => r.dataset.id)); |
| 156 | const head = await page.textContent('#ext-results .sk-h').catch(() => ''); |
| 157 | return new RegExp(`checked ${fixtures.length} of ${fixtures.length}`).test(head) ? { ids, head } : null; |
| 158 | }); |
| 159 | const shouldHide = ['elffuss-ux.webengine', 'elffuss-ux.webnever', 'eamodio.gitlens', 'elffuss-ux.pyreflike']; |
| 160 | ok('X2 with the filter on, what cannot work is hidden and it says how many it checked', !!filtered && shouldHide.every(id => !filtered.ids.includes(id)) |
| 161 | && ['elffuss-ux.decl', 'elffuss-ux.webok', 'elffuss-ux.nodetheme', 'esbenp.prettier-vscode', 'elffuss-ux.webproposals', 'elffuss-ux.mixedcode'].every(id => filtered.ids.includes(id)), JSON.stringify(filtered)); |
| 162 | const rowLines = await page.evaluate(() => [...document.querySelectorAll('#ext-results .ext-row[data-id="elffuss-ux.decl"] .ext-x2-lines div')].map(x => x.textContent)); |
| 163 | ok('X2 each row says what will work (here, "Works now (no code): 1 theme")', rowLines.includes('Works now (no code): 1 theme'), JSON.stringify(rowLines)); |
| 164 | ok('X2 pressed, and it says Open VSX sees those lookups', (await chip.getAttribute('aria-pressed')) === 'true' && await page.isVisible('#ext-works-note') |
| 165 | && /Open VSX also sees the manifest lookups/.test(await page.textContent('#ext-works-note'))); |
| 166 | await chip.click(); |
| 167 | ok('X2 off again: all results back', !!(await until(async () => (await page.locator('#ext-results .ext-row').count()) === fixtures.length)) && !(await page.isVisible('#ext-works-note'))); |
| 168 | |
| 169 | // ── X3: tamaños ── |
| 170 | const manifest = JSON.parse(fs.readFileSync(path.join(HERE, '../web/js/ext2/vendor-manifest.json'), 'utf8')); |
| 171 | const runtimeMb = (manifest.files.reduce((n, f) => n + f.gz, 0) / 1e6).toFixed(1); |
| 172 | await row(page, 'esbenp.prettier-vscode').locator('.ext-install-code').click(); |
| 173 | const consent = await until(() => page.evaluate(() => document.querySelector('#x2-consent [role="dialog"]')?.textContent || null)); |
| 174 | const censusMb = (JSON.parse(fs.readFileSync(path.join(HERE, '../web/js/ext2/tested.json'), 'utf8')).results['esbenp.prettier-vscode@12.4.0'].bytes / 1e6).toFixed(1); |
| 175 | ok('X3 the consent shows the runtime’s size from the vendor manifest and the extension’s own', !!consent && consent.includes(`Code’s extension runtime: ${runtimeMb} MB`) && consent.includes(`This extension: ${censusMb} MB`), String(consent).slice(0, 400)); |
| 176 | |
| 177 | // ── X5 (consentimiento): roles, Tab atrapado, foco en Cancelar, Escape devuelve el foco ── |
| 178 | const dlg = await page.evaluate(() => { |
| 179 | const d = document.querySelector('#x2-consent [role="dialog"]'); |
| 180 | return { modal: d.getAttribute('aria-modal'), labelled: !!document.getElementById(d.getAttribute('aria-labelledby') || '-'), focus: document.activeElement?.textContent }; |
| 181 | }); |
| 182 | const inside = []; |
| 183 | for (let i = 0; i < 6; i++) { await page.keyboard.press('Tab'); inside.push(await page.evaluate(() => !!document.activeElement?.closest('#x2-consent'))); } |
| 184 | await page.keyboard.press('Escape'); |
| 185 | const back = await until(() => page.evaluate(() => !document.querySelector('#x2-consent') && document.activeElement?.classList.contains('ext-install-code'))); |
| 186 | ok('X5 consent: a labelled modal dialog, focus on Cancel, Tab stays inside, Escape closes and the focus goes back', dlg.modal === 'true' && dlg.labelled && dlg.focus === 'Cancel' && inside.every(Boolean) && !!back, JSON.stringify({ dlg, inside, back })); |
| 187 | // una con tema y código: el consentimiento ofrece instalarla sin su código (no «solo temas y snippets») |
| 188 | await row(page, 'elffuss-ux.mixedcode').locator('.ext-install-code').click(); |
| 189 | const mixedButtons = await until(() => page.evaluate(() => { const d = document.querySelector('#x2-consent [role="dialog"]'); return d ? [...d.querySelectorAll('button')].map(b => b.textContent) : null; })); |
| 190 | ok('X3 consent of an extension with a theme and code: "Install without its code", "Install and run code"', JSON.stringify(mixedButtons) === JSON.stringify(['Cancel', 'Install without its code', 'Install and run code']), JSON.stringify(mixedButtons)); |
| 191 | await page.keyboard.press('Escape'); |
| 192 | // el botón primario de los diálogos: texto oscuro sobre el degradado (WCAG 1.4.3, 4,5:1) |
| 193 | await row(page, 'elffuss-ux.mixedcode').locator('.ext-install-code').click(); |
| 194 | const contrast = await until(() => page.evaluate(() => { |
| 195 | const b = document.querySelector('#x2-consent .x2-btn.x2-primary'); |
| 196 | if (!b) return null; |
| 197 | const cs = getComputedStyle(b); |
| 198 | const rgb = s => (s.match(/\d+(\.\d+)?/g) || []).slice(0, 3).map(Number); |
| 199 | const lum = ([r, g, bl]) => { const f = v => { v /= 255; return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4; }; return 0.2126 * f(r) + 0.7152 * f(g) + 0.0722 * f(bl); }; |
| 200 | const ends = (cs.backgroundImage.match(/rgba?\([^)]*\)/g) || []).map(rgb); |
| 201 | const fg = lum(rgb(cs.color)); |
| 202 | const ratio = c => { const l = lum(c); return (Math.max(l, fg) + 0.05) / (Math.min(l, fg) + 0.05); }; |
| 203 | return { color: cs.color, ends: ends.length, ratios: ends.map(c => +ratio(c).toFixed(2)) }; |
| 204 | })); |
| 205 | ok('X3 the dialogs’ primary button: at least 4.5:1 against both ends of the gradient', !!contrast && contrast.ends >= 2 && contrast.ratios.every(r => r >= 4.5), JSON.stringify(contrast)); |
| 206 | await page.keyboard.press('Escape'); |
| 207 | await ctx.close(); |
| 208 | |
| 209 | // ── X2b: el filtro encendido ANTES de abrir ningún detalle: las filas dicen igual qué funcionará ── |
| 210 | { |
| 211 | const { ctx, page } = await profile(); |
| 212 | await openIde(page); |
| 213 | await panel(page); |
| 214 | await page.click('#ext-works'); |
| 215 | await search(page, 'elffuss-ux'); |
| 216 | const rows2 = await until(async () => { |
| 217 | const head = await page.textContent('#ext-results .sk-h').catch(() => ''); |
| 218 | if (!new RegExp(`checked ${fixtures.length} of ${fixtures.length}`).test(head)) return null; |
| 219 | await sleep(300); |
| 220 | return page.evaluate(() => Object.fromEntries([...document.querySelectorAll('#ext-results .ext-row')].map(r => [r.dataset.id, { |
| 221 | lines: [...r.querySelectorAll('.ext-x2-lines div')].map(x => x.textContent), code: !!r.querySelector('.ext-install-code'), opened: !r.querySelector('.ext-detail').hidden, |
| 222 | }]))); |
| 223 | }); |
| 224 | ok('X2b filter first: each row says what will work and offers "Install and run its code…" without opening its details', !!rows2 && !rows2['elffuss-ux.webok']?.opened |
| 225 | && rows2['elffuss-ux.webok']?.lines.some(l => /^Runs in Code’s sandbox/.test(l)) && rows2['elffuss-ux.webok'].code && rows2['esbenp.prettier-vscode']?.code |
| 226 | && rows2['elffuss-ux.decl']?.lines.includes('Works now (no code): 1 theme') && !rows2['elffuss-ux.decl'].code, JSON.stringify(rows2)); |
| 227 | await ctx.close(); |
| 228 | } |
| 229 | |
| 230 | // ── X1b: «Instalar» en una que solo trae código, sin abrir su detalle ── |
| 231 | { |
| 232 | const { ctx, page } = await profile(); |
| 233 | const log = []; |
| 234 | ctx.on('request', r => { if (/open-vsx\.org/.test(r.url())) log.push(r.method() + ' ' + new URL(r.url()).pathname); }); |
| 235 | const l2 = []; |
| 236 | page.on('request', r => { if (/\/js\/ext2\//.test(r.url())) l2.push(new URL(r.url()).pathname); }); |
| 237 | await openIde(page); |
| 238 | await panel(page); |
| 239 | await search(page, 'elffuss-ux'); |
| 240 | await until(async () => (await page.locator('#ext-results .ext-row').count()) === fixtures.length); |
| 241 | // un tema: su manifiesto dice que algo se aplica y se instala sin cargar nada del nivel 2 |
| 242 | await row(page, 'elffuss-ux.decl').locator('.ext-install').click(); |
| 243 | const declMsg = await until(() => page.evaluate(() => document.getElementById('ext-msg')?.textContent || null)); |
| 244 | ok('X1b Install on a theme reads its manifest and goes on to install it, without loading anything of level 2', l2.length === 0 && log.some(l => /elffuss-ux\/decl\/1\.0\.0\/file\/package\.json$/.test(l)) && !!declMsg, |
| 245 | JSON.stringify({ l2, declMsg })); |
| 246 | await row(page, 'elffuss-ux.webok').locator('.ext-install').click(); |
| 247 | const after = await until(() => page.evaluate(() => { |
| 248 | const r = [...document.querySelectorAll('#ext-results .ext-row')].find(x => x.dataset.id === 'elffuss-ux.webok'); |
| 249 | const code = r?.querySelector('.ext-install-code'); |
| 250 | return code ? { focused: document.activeElement === code, msg: document.getElementById('ext-msg')?.textContent, role: document.getElementById('ext-msg')?.getAttribute('role'), buttons: [...r.querySelectorAll('.ext-actions button')].map(b => b.textContent) } : null; |
| 251 | })); |
| 252 | ok('X1b Install on a code-only result: the row now offers "Install and run its code…", with the focus on it, and the message points at it', |
| 253 | !!after && after.focused && /It only brings code: use “Install and run its code…”/.test(after.msg) && after.buttons.includes('Install and run its code…'), JSON.stringify(after)); |
| 254 | ok('X1b …and nothing was downloaded to find that out (only its manifest)', !log.some(l => /\.vsix$/.test(l)) && log.some(l => /package\.json$/.test(l)), JSON.stringify(log)); |
| 255 | await ctx.close(); |
| 256 | } |
| 257 | |
| 258 | // ── X5 (diálogos de una extensión) y X4 (teléfono) ── |
| 259 | { |
| 260 | const { ctx, page } = await profile({ width: 390, height: 844, mock: false }); |
| 261 | await seed(page, [UI, SORT]); |
| 262 | await openIde(page); |
| 263 | const up = await until(() => page.evaluate(async () => { const s = (await import('/js/ext2/bridge.js')).state(); return s.state === 'running' && s.extensions.find(e => e.id === 'elffuss-test.ui')?.state === 'active'; }), { timeout: 90000 }); |
| 264 | ok('X4 premise: at 390 px the sandbox runs the two fixtures', !!up); |
| 265 | await page.evaluate(() => { window.__ask = import('/js/ext2/bridge.js').then(b => b.runCommand('x2ui.ask')); }); |
| 266 | const toast = await until(() => page.evaluate(() => { |
| 267 | const t = [...document.querySelectorAll('#x2-toasts .x2-toast')].find(x => x.textContent.includes('x2 asks')); |
| 268 | if (!t) return null; |
| 269 | const r = t.getBoundingClientRect(); |
| 270 | return { role: t.getAttribute('role'), left: r.left, right: r.right, w: innerWidth, sw: document.documentElement.scrollWidth }; |
| 271 | })); |
| 272 | ok('X4 at 390 px a toast fits, with no horizontal scroll; X5 it is a status', !!toast && toast.role === 'status' && toast.left >= 0 && toast.right <= toast.w && toast.sw <= toast.w, JSON.stringify(toast)); |
| 273 | await page.click('#x2-toasts .x2-toast:has-text("x2 asks") .x2-toast-buttons button:has-text("Yes")'); |
| 274 | await until(() => page.evaluate(() => !!document.querySelector('#x2-dialog [role="dialog"]'))); |
| 275 | const modal = await page.evaluate(() => { const d = document.querySelector('#x2-dialog [role="dialog"]'); const r = d.getBoundingClientRect(); return { modal: d.getAttribute('aria-modal'), focus: document.activeElement?.textContent, left: r.left, right: r.right, w: innerWidth, sw: document.documentElement.scrollWidth }; }); |
| 276 | const trapped = []; |
| 277 | for (let i = 0; i < 4; i++) { await page.keyboard.press('Shift+Tab'); trapped.push(await page.evaluate(() => !!document.activeElement?.closest('#x2-dialog'))); } |
| 278 | ok('X5 an extension’s modal: aria-modal, focus on Cancel, Shift+Tab stays inside; X4 it fits', modal.modal === 'true' && modal.focus === 'Cancel' && trapped.every(Boolean) && modal.left >= 0 && modal.right <= modal.w && modal.sw <= modal.w, JSON.stringify({ modal, trapped })); |
| 279 | await page.keyboard.press('Escape'); |
| 280 | const pick = await until(() => page.evaluate(() => { |
| 281 | const p = document.getElementById('x2-pick'); |
| 282 | if (!p || p.classList.contains('x2-inputbox')) return null; |
| 283 | const inp = p.querySelector('input'), list = p.querySelector('[role="listbox"]'); |
| 284 | return { combobox: inp.getAttribute('role'), expanded: inp.getAttribute('aria-expanded'), controls: inp.getAttribute('aria-controls') === list?.id, options: list ? list.querySelectorAll('[role="option"]').length : 0, active: inp.getAttribute('aria-activedescendant') }; |
| 285 | })); |
| 286 | await page.keyboard.press('ArrowDown'); |
| 287 | await page.keyboard.press('ArrowDown'); |
| 288 | const moved = await page.evaluate(() => { const inp = document.querySelector('#x2-pick input'); const a = document.getElementById(inp.getAttribute('aria-activedescendant')); return { label: a?.querySelector('.x2-pick-label')?.textContent, selected: a?.getAttribute('aria-selected') }; }); |
| 289 | await page.keyboard.press('Enter'); |
| 290 | ok('X5 quick pick: a combobox that controls a listbox; the arrows move aria-activedescendant; Enter picks', !!pick && pick.combobox === 'combobox' && pick.expanded === 'true' && pick.controls && pick.options === 3 |
| 291 | && moved.label === 'c' && moved.selected === 'true', JSON.stringify({ pick, moved })); |
| 292 | await until(() => page.evaluate(() => document.querySelectorAll('#x2-pick .x2-pick-item').length === 3)); |
| 293 | await page.keyboard.press('Escape'); |
| 294 | await until(() => page.evaluate(() => !!document.querySelector('#x2-input input'))); |
| 295 | await page.keyboard.press('Escape'); |
| 296 | const res = JSON.parse(await page.evaluate(() => window.__ask) || '{}'); |
| 297 | ok('X5 the extension got what was chosen: Yes, nothing (Escape), c, nothing, nothing', res.info === 'Yes' && res.modal === undefined && res.pick === 'c' && res.many === undefined && res.input === undefined, JSON.stringify(res)); |
| 298 | // un comando desde el panel, en el teléfono |
| 299 | await page.evaluate(async () => { await (await import('/js/ide.js')).openFile('fruits.txt'); const ed = window.monaco.editor.getEditors()[0]; ed.setSelection(ed.getModel().getFullModelRange()); }); |
| 300 | // en un teléfono no hay barra de actividad: el panel se abre con «/extensions» |
| 301 | await page.click('#btn-slash'); |
| 302 | await page.locator('#menu .menu-item', { hasText: '/extensions' }).click(); |
| 303 | await until(() => page.evaluate(() => !!document.getElementById('ext-panel')?.isConnected && !document.getElementById('settings-panel').hidden)); |
| 304 | const runBtn = page.locator('#ext-installed .ext-row[data-id="elffuss-test.sort"] [data-k="cmd:x2sort.sortLines"]'); |
| 305 | await until(async () => (await runBtn.count()) === 1); |
| 306 | const layout = await page.evaluate(() => ({ sw: document.documentElement.scrollWidth, w: innerWidth })); |
| 307 | await runBtn.click(); |
| 308 | ok('X4 at 390 px the panel fits and a command runs from it', layout.sw <= layout.w && !!(await until(() => page.evaluate(() => window.monaco.editor.getEditors()[0].getModel().getValue() === 'apple\nfig\npear\n'))), JSON.stringify(layout)); |
| 309 | await ctx.close(); |
| 310 | } |
| 311 | |
| 312 | // ── X7: donde el nivel 2 no puede arrancar: Code en un host sin recinto en |
| 313 | // config.js (aquí «code.localhost», que el navegador trata como contexto |
| 314 | // seguro y resuelve a sí mismo; code.elffuss.com sí tiene el suyo, |
| 315 | // x2.utopiaia.com) ── |
| 316 | { |
| 317 | const alias = 'code.localhost'; |
| 318 | const srv2 = await startServer({ codeAliases: [alias] }); |
| 319 | const origin2 = `http://${alias}:${srv2.port}`; |
| 320 | const b2 = browser; |
| 321 | const ctx2 = await b2.newContext({ viewport: { width: 1280, height: 860 } }); |
| 322 | await ctx2.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); localStorage.setItem('elffusscode.ext.onlyWorks', '0'); } catch { /* — */ } }); |
| 323 | await mockOpenVsx(ctx2, fixtures); |
| 324 | const p2 = await ctx2.newPage(); |
| 325 | p2.on('pageerror', e => { if (e.message !== 'Canceled') errors.push('X7: ' + e.message); }); |
| 326 | await p2.goto(origin2 + '/?test-opfs', { waitUntil: 'domcontentloaded' }); |
| 327 | await p2.waitForFunction(() => !!window.monaco?.editor?.getEditors?.().length, null, { timeout: 30000 }); |
| 328 | const rt = await p2.evaluate(async () => (await import('/js/ext2/vendor.js')).runtimeInfo()); |
| 329 | const premise = await p2.evaluate(async () => { const c = await import('/js/ext2/config.js'); return c.sandboxOrigin(location) === null && c.sandboxOrigin({ hostname: 'code.elffuss.com', origin: 'https://code.elffuss.com', port: '' }) === 'https://x2.utopiaia.com'; }); |
| 330 | ok('X7 premise: Code on a host config.js gives no sandbox (code.elffuss.com has x2.utopiaia.com): level 2 is not available on this site', rt.available === false && rt.reason === 'site' && premise, JSON.stringify(rt)); |
| 331 | await panel(p2); |
| 332 | await search(p2, 'elffuss-ux'); |
| 333 | await until(async () => (await p2.locator('#ext-results .ext-row').count()) === fixtures.length); |
| 334 | const r7 = id => p2.locator(`#ext-results .ext-row[data-id="${id}"]`); |
| 335 | await r7('elffuss-ux.webok').locator('.ext-name').click(); |
| 336 | const t7 = await until(async () => { const t = await r7('elffuss-ux.webok').locator('.ext-detail').innerText(); return /Licence|License/.test(t) ? t : null; }); |
| 337 | const run7 = await r7('elffuss-ux.webok').evaluate(r => { const b = r.querySelector('.ext-install-code'); return b ? { inert: b.getAttribute('aria-disabled') === 'true', title: b.title } : null; }); |
| 338 | ok('X7 there, a code-only extension says its code can’t run on this site (not "Runs in Code’s sandbox"), and its run button is inert with that reason', |
| 339 | /Its code can’t run here\. Not available on this site yet: the sandbox needs its own domain\./.test(t7 || '') && !/Runs in Code’s sandbox/.test(t7 || '') |
| 340 | && run7?.inert && /Not available on this site yet/.test(run7.title), JSON.stringify({ t7, run7 })); |
| 341 | await p2.click('#ext-works'); |
| 342 | const f7 = await until(async () => { |
| 343 | const head = await p2.textContent('#ext-results .sk-h').catch(() => ''); |
| 344 | return new RegExp(`checked ${fixtures.length} of ${fixtures.length}`).test(head) ? p2.locator('#ext-results .ext-row').evaluateAll(rs => rs.filter(r => !r.hidden).map(r => r.dataset.id)) : null; |
| 345 | }); |
| 346 | ok('X7 …and the Works in Code filter hides what only brings code, keeping what applies without it', !!f7 && !f7.includes('elffuss-ux.webok') && !f7.includes('esbenp.prettier-vscode') |
| 347 | && f7.includes('elffuss-ux.decl') && f7.includes('elffuss-ux.mixedcode'), JSON.stringify(f7)); |
| 348 | await ctx2.close(); |
| 349 | await srv2.close(); |
| 350 | } |
| 351 | |
| 352 | // ── X8: los avisos y el selector, con el teclado ── |
| 353 | const MOD = process.platform === 'darwin' ? 'Meta' : 'Control'; |
| 354 | const bridgeRun = (page, cmd, arg, slot) => page.evaluate(([cmd, arg, slot]) => { window[slot] = import('/js/ext2/bridge.js').then(b => b.runCommand(cmd, arg === null ? undefined : [arg])); }, [cmd, arg ?? null, slot]); |
| 355 | const runningWith = (page, id) => until(() => page.evaluate(async id => { const s = (await import('/js/ext2/bridge.js')).state(); return s.state === 'running' && s.extensions.find(e => e.id === id)?.state === 'active'; }, id), { timeout: 90000 }); |
| 356 | { |
| 357 | const { ctx, page } = await profile({ mock: false }); |
| 358 | await seed(page, [UI, SORT]); |
| 359 | await openIde(page); |
| 360 | ok('X8 premise: the sandbox runs the UI fixture', !!(await runningWith(page, 'elffuss-test.ui'))); |
| 361 | await page.evaluate(async () => { await (await import('/js/ide.js')).openFile('fruits.txt'); window.monaco.editor.getEditors()[0].focus(); }); |
| 362 | const inEditor = () => page.evaluate(() => !!document.activeElement?.closest('#editor')); |
| 363 | const toastWith = text => until(() => page.evaluate(text => [...document.querySelectorAll('#x2-toasts .x2-toast')].some(x => x.textContent.includes(text)), text)); |
| 364 | // F6: del editor al aviso y de vuelta |
| 365 | await bridgeRun(page, 'x2ui.question', null, '__q'); |
| 366 | await toastWith('x2 question'); |
| 367 | const hint = await page.evaluate(() => [...document.querySelectorAll('#x2-toasts .x2-toast')].find(x => x.textContent.includes('x2 question'))?.querySelector('.x2-sr')?.textContent || ''); |
| 368 | ok('X8 a notification that waits for an answer tells screen readers how to reach it (F6)', /Press F6 to reach its buttons/.test(hint), hint); |
| 369 | const start = await inEditor(); |
| 370 | await page.keyboard.press('F6'); |
| 371 | const f1 = await page.evaluate(() => (document.activeElement?.closest('#x2-toasts') ? document.activeElement.textContent : null)); |
| 372 | await page.keyboard.press('F6'); |
| 373 | const back1 = await inEditor(); |
| 374 | await page.keyboard.press('F6'); |
| 375 | await page.keyboard.press('Tab'); |
| 376 | const f2 = await page.evaluate(() => document.activeElement?.textContent); |
| 377 | await page.keyboard.press('Enter'); |
| 378 | const ans1 = await page.evaluate(() => window.__q); |
| 379 | const back2 = await until(inEditor); |
| 380 | ok('X8 F6 from the editor reaches the notification’s buttons, F6 again goes back; answering returns the focus to the editor', start && f1 === 'Keep' && back1 && f2 === 'Drop' && ans1 === 'Drop' && !!back2, |
| 381 | JSON.stringify({ start, f1, back1, f2, ans1, back2 })); |
| 382 | // la paleta de Code: «Extensiones: ir al aviso», solo mientras hay uno |
| 383 | await bridgeRun(page, 'x2ui.question', null, '__q2'); |
| 384 | await toastWith('x2 question'); |
| 385 | await page.keyboard.press(`${MOD}+Shift+KeyP`); |
| 386 | await page.waitForSelector('#palette:not([hidden])'); |
| 387 | await page.fill('#pal-input', '>go to the notification'); |
| 388 | const palRow = await until(() => page.evaluate(() => { const r = document.querySelector('#palette .pal-item'); return r ? r.querySelector('.pi-name').textContent + ' | ' + r.querySelector('.pi-hint').textContent : null; })); |
| 389 | await page.keyboard.press('Enter'); |
| 390 | const f3 = await until(() => page.evaluate(() => (document.activeElement?.closest('#x2-toasts') ? document.activeElement.textContent : null))); |
| 391 | await page.keyboard.press('Escape'); |
| 392 | const ans2 = await page.evaluate(() => window.__q2); |
| 393 | const notBody = await until(() => page.evaluate(() => document.activeElement && document.activeElement !== document.body)); |
| 394 | ok('X8 Code’s palette offers "Extensions: Go to the notification" (F6) while one is shown; Escape closes the notification and the focus does not fall to the page', |
| 395 | palRow === 'Extensions: Go to the notification | F6' && f3 === 'Keep' && ans2 === 'undefined' && !!notBody, JSON.stringify({ palRow, f3, ans2, notBody })); |
| 396 | await page.keyboard.press(`${MOD}+Shift+KeyP`); |
| 397 | await page.waitForSelector('#palette:not([hidden])'); |
| 398 | await page.fill('#pal-input', '>go to the notification'); |
| 399 | await sleep(300); |
| 400 | const gone = await page.evaluate(() => [...document.querySelectorAll('#palette .pal-item .pi-name')].some(x => x.textContent === 'Extensions: Go to the notification')); |
| 401 | await page.keyboard.press('Escape'); |
| 402 | ok('X8 …and the entry goes away with the last notification', !gone); |
| 403 | // un aviso sin botones: no se va mientras el ratón o el foco están en él |
| 404 | await page.evaluate(() => window.monaco.editor.getEditors()[0].focus()); |
| 405 | await bridgeRun(page, 'x2ui.note', null, '__n'); |
| 406 | await toastWith('x2 note'); |
| 407 | const note = page.locator('#x2-toasts .x2-toast', { hasText: 'x2 note' }); |
| 408 | await note.hover(); |
| 409 | await sleep(10500); |
| 410 | const whileHovered = await note.count(); |
| 411 | await page.keyboard.press('F6'); |
| 412 | await page.mouse.move(5, 5); |
| 413 | await sleep(10500); |
| 414 | const whileFocused = await note.count(); |
| 415 | const onClose = await page.evaluate(() => document.activeElement?.classList.contains('x2-toast-close')); |
| 416 | await page.keyboard.press('Enter'); |
| 417 | const noteRes = await page.evaluate(() => window.__n); |
| 418 | const back3 = await until(inEditor); |
| 419 | ok('X8 a notification without buttons stays while hovered or focused (its 9 s pause), and closing it gives the focus back to the editor', |
| 420 | whileHovered === 1 && whileFocused === 1 && onClose && noteRes === 'closed' && !!back3, JSON.stringify({ whileHovered, whileFocused, onClose, noteRes, back3 })); |
| 421 | // el selector y el cuadro de texto: Tab no sale, Escape desde sus botones, Espacio con filtro |
| 422 | await bridgeRun(page, 'x2ui.ask', null, '__ask'); |
| 423 | await page.click('#x2-toasts .x2-toast:has-text("x2 asks") .x2-toast-buttons button:has-text("Yes")'); |
| 424 | await until(() => page.evaluate(() => !!document.querySelector('#x2-dialog [role="dialog"]'))); |
| 425 | await page.keyboard.press('Escape'); |
| 426 | await until(() => page.evaluate(() => { const p = document.getElementById('x2-pick'); return p && !p.classList.contains('x2-inputbox') && !p.querySelector('[aria-multiselectable]'); })); |
| 427 | const where = () => page.evaluate(() => { const a = document.activeElement; return a?.closest('#x2-pick, #x2-input') ? (a.tagName === 'INPUT' ? 'input' : a.textContent) : 'OUT ' + (a?.id || a?.tagName); }); |
| 428 | const tabs1 = []; |
| 429 | for (let i = 0; i < 3; i++) { await page.keyboard.press('Tab'); tabs1.push(await where()); } |
| 430 | await page.keyboard.press('Escape'); |
| 431 | await until(() => page.evaluate(() => !!document.querySelector('#x2-pick [aria-multiselectable]'))); |
| 432 | await page.keyboard.type('t'); |
| 433 | await page.keyboard.press('Space'); |
| 434 | await page.keyboard.press('ArrowDown'); |
| 435 | await page.keyboard.press('Space'); |
| 436 | const multi = await page.evaluate(() => { const p = document.getElementById('x2-pick'); return { value: p.querySelector('input').value, checked: [...p.querySelectorAll('.x2-pick-item')].map(r => r.querySelector('.x2-pick-label').textContent + ':' + r.getAttribute('aria-checked')), ph: p.querySelector('input').placeholder }; }); |
| 437 | await page.keyboard.press('Enter'); |
| 438 | await until(() => page.evaluate(() => !!document.querySelector('#x2-input input'))); |
| 439 | const tabs2 = []; |
| 440 | for (let i = 0; i < 3; i++) { await page.keyboard.press('Tab'); tabs2.push(await where()); } |
| 441 | await page.keyboard.press('Tab'); |
| 442 | await page.keyboard.press('Escape'); |
| 443 | const res = JSON.parse(await page.evaluate(() => window.__ask) || '{}'); |
| 444 | ok('X8 quick pick: Tab stays inside it, and Escape from its Cancel button closes it', JSON.stringify(tabs1) === JSON.stringify(['Cancel', 'input', 'Cancel']) && res.pick === undefined, JSON.stringify({ tabs1, pick: res.pick })); |
| 445 | ok('X8 several to pick: Space checks the highlighted one even with a filter typed (and says so)', multi.value === 't' && JSON.stringify(multi.checked) === JSON.stringify(['two:false', 'three:true']) |
| 446 | && JSON.stringify(res.many) === '["three"]' && /Space checks the highlighted one/.test(multi.ph), JSON.stringify({ multi, many: res.many })); |
| 447 | ok('X8 input box: Tab stays inside it, and Escape from a button closes it', JSON.stringify(tabs2) === JSON.stringify(['Cancel', 'OK', 'input']) && res.input === undefined, JSON.stringify({ tabs2, input: res.input })); |
| 448 | await ctx.close(); |
| 449 | } |
| 450 | |
| 451 | // ── X9: «Bloquear peticiones» y desbloquear; X10: apagar todo y el botón de cada una ── |
| 452 | { |
| 453 | const { ctx, page } = await profile({ mock: false }); |
| 454 | await seed(page, [UI]); |
| 455 | await openIde(page); |
| 456 | ok('X9 premise: the sandbox runs the UI fixture', !!(await runningWith(page, 'elffuss-test.ui'))); |
| 457 | const dialog = () => until(() => page.evaluate(() => { const d = document.querySelector('#x2-open [role="dialog"]'); return d ? { code: d.querySelector('.x2-code').textContent, buttons: [...d.querySelectorAll('button')].map(b => b.textContent) } : null; })); |
| 458 | await bridgeRun(page, 'x2ui.open', 'https://blocked.example/a', '__o1'); |
| 459 | await dialog(); |
| 460 | await page.click('#x2-open button:has-text("Block requests for this session")'); |
| 461 | const r1 = await page.evaluate(() => window.__o1); |
| 462 | await bridgeRun(page, 'x2ui.open', 'https://blocked.example/b', '__o2'); |
| 463 | const r2 = await page.evaluate(() => window.__o2); |
| 464 | const sb = await page.textContent('#statusbar'); |
| 465 | const noDialog = await page.evaluate(() => !document.querySelector('#x2-open')); |
| 466 | ok('X9 after "Block requests for this session" an extension’s next address is not opened, and the status bar says why', r1 === 'false' && r2 === 'false' && noDialog && /blocked for this session/.test(sb || ''), JSON.stringify({ r1, r2, noDialog, sb })); |
| 467 | await page.evaluate(async () => { await (await import('/js/ide.js')).openFile('fruits.txt'); const ed = window.monaco.editor.getEditors()[0]; ed.getModel().setValue('see https://docs.example/page now\n'); ed.setPosition({ lineNumber: 1, column: 8 }); ed.focus(); }); |
| 468 | // (los enlaces los calcula el worker del editor: se reintenta hasta que el enlace existe) |
| 469 | let link = null; |
| 470 | for (let i = 0; i < 10 && !link; i++) { |
| 471 | await sleep(500); |
| 472 | await page.evaluate(() => window.monaco.editor.getEditors()[0].getAction('editor.action.openLink').run()); |
| 473 | link = await until(() => page.evaluate(() => { const d = document.querySelector('#x2-open [role="dialog"]'); return d ? { code: d.querySelector('.x2-code').textContent, buttons: [...d.querySelectorAll('button')].map(b => b.textContent) } : null; }), { timeout: 1500 }); |
| 474 | } |
| 475 | ok('X9 …but the user’s own link in the editor still asks, with no Block button (that one is for extensions)', !!link && link.code === 'https://docs.example/page' && !link.buttons.includes('Block requests for this session'), JSON.stringify(link)); |
| 476 | await page.keyboard.press('Escape'); |
| 477 | await page.evaluate(() => window.monaco.editor.getEditors()[0].getModel().setValue('pear\napple\nfig\n')); |
| 478 | await panel(page); |
| 479 | const line = await until(() => page.evaluate(() => { const p = document.querySelector('#ext-installed .ext-x2-runtime'); return p && !p.hidden && /blocked/.test(p.textContent) && p.querySelector('.ext-x2-unblock') ? p.textContent : null; })); |
| 480 | await page.focus('#ext-installed .ext-x2-unblock'); |
| 481 | await page.keyboard.press('Enter'); |
| 482 | const unblocked = await until(() => page.evaluate(() => { const m = document.getElementById('ext-msg')?.textContent || ''; return /ask to open an address again/.test(m) ? { focus: document.activeElement?.id, line: document.querySelector('#ext-installed .ext-x2-runtime')?.textContent } : null; })); |
| 483 | await page.click('#settings-close'); |
| 484 | await bridgeRun(page, 'x2ui.open', 'https://blocked.example/c', '__o3'); |
| 485 | const again = await dialog(); |
| 486 | await page.keyboard.press('Escape'); |
| 487 | ok('X9 the Extensions panel says requests are blocked, with Unblock; after it the focus is on the Installed heading, it is announced, and the next request asks again', |
| 488 | !!line && /1 not opened/.test(line) && unblocked?.focus === 'ext-installed-h' && !/blocked/.test(unblocked.line || '') && again?.code === 'https://blocked.example/c', JSON.stringify({ line, unblocked, again })); |
| 489 | // X10 |
| 490 | await panel(page); |
| 491 | const btnOf = () => page.locator('#ext-installed .ext-row[data-id="elffuss-test.ui"] [data-k="x2run"]').evaluate(b => ({ label: b.getAttribute('aria-label'), pressed: b.getAttribute('aria-pressed'), text: b.textContent })); |
| 492 | const t1 = await btnOf(); |
| 493 | await page.focus('#ext-installed .ext-x2-alloff'); |
| 494 | await page.keyboard.press('Enter'); |
| 495 | const off = await until(() => page.evaluate(() => { const m = document.getElementById('ext-msg')?.textContent || ''; return /Extension code turned off/.test(m) && !document.querySelector('#ext-installed .ext-x2-alloff') ? { focus: document.activeElement?.id, role: document.getElementById('ext-msg').getAttribute('role') } : null; })); |
| 496 | const t2 = await btnOf(); |
| 497 | ok('X10 "Turn off all extension code": the focus goes to the Installed heading and the result is announced', off?.focus === 'ext-installed-h' && off.role === 'status', JSON.stringify(off)); |
| 498 | ok('X10 the run button names its action and has no aria-pressed: "Turn off the code of X2 ui" running, "Run the code of X2 ui" off', t1.pressed === null && t1.label === 'Turn off the code of X2 ui' && t1.text === 'Turn off code' |
| 499 | && t2.pressed === null && t2.label === 'Run the code of X2 ui' && t2.text === 'Run code', JSON.stringify({ t1, t2 })); |
| 500 | await ctx.close(); |
| 501 | } |
| 502 | |
| 503 | // ── X4b: en un teléfono (360×640), una dirección larga ── |
| 504 | { |
| 505 | const { ctx, page } = await profile({ width: 360, height: 640, mock: false }); |
| 506 | await seed(page, [UI]); |
| 507 | await openIde(page); |
| 508 | ok('X4b premise: at 360 px the sandbox runs the UI fixture', !!(await runningWith(page, 'elffuss-test.ui'))); |
| 509 | const LONG = 'https://github.com/search?q=' + Array.from({ length: 300 }, (_, i) => 'word' + i).join('+') + '&type=code'; |
| 510 | await bridgeRun(page, 'x2ui.open', LONG, '__long'); |
| 511 | const g = await until(() => page.evaluate(() => { |
| 512 | const d = document.querySelector('#x2-open [role="dialog"]'); |
| 513 | if (!d) return null; |
| 514 | const inView = e => { if (!e) return false; const r = e.getBoundingClientRect(), b = d.getBoundingClientRect(); return r.top >= b.top - 1 && r.bottom <= b.bottom + 1 && r.top >= 0 && r.bottom <= innerHeight; }; |
| 515 | const box = d.querySelector('.x2-code'), sites = d.querySelectorAll('.x2-site'); |
| 516 | return { scrollTop: d.scrollTop, title: inView(d.querySelector('.x2-modal-title')), site: inView(sites[0]), siteAgain: inView(sites[1]), again: sites[1]?.textContent || '', |
| 517 | focus: document.activeElement?.textContent, focusInView: inView(document.activeElement), boxScrolls: box.scrollHeight > box.clientHeight, code: box.textContent, sw: document.documentElement.scrollWidth, w: innerWidth }; |
| 518 | })); |
| 519 | ok('X4b at 360×640 a long address: the dialog opens at its top with the title and the site in view, the address scrolls in its own box, the site is repeated by the buttons, and Cancel has the focus in view', |
| 520 | !!g && g.scrollTop === 0 && g.title && g.site && g.siteAgain && /Site: github\.com/.test(g.again) && g.boxScrolls && g.focus === 'Cancel' && g.focusInView && g.sw <= g.w, JSON.stringify({ ...g, code: g?.code.length })); |
| 521 | ok('X4b the address is the one the extension asked for, with its query readable (= & +, not %3D %26 %2B)', g?.code === LONG, String(g?.code).slice(0, 120)); |
| 522 | await page.keyboard.press('Escape'); |
| 523 | // y el aviso de una extensión no tapa el prompt del chat en un teléfono |
| 524 | await bridgeRun(page, 'x2ui.question', null, '__q'); |
| 525 | const cover = await until(() => page.evaluate(() => { |
| 526 | const t = [...document.querySelectorAll('#x2-toasts .x2-toast')].find(x => x.textContent.includes('x2 question')); |
| 527 | const pr = document.getElementById('prompt'); |
| 528 | if (!t || !pr) return null; |
| 529 | const a = t.getBoundingClientRect(), b = pr.getBoundingClientRect(); |
| 530 | const visible = b.width > 0 && b.height > 0; |
| 531 | return { overlaps: visible && a.left < b.right && a.right > b.left && a.top < b.bottom && a.bottom > b.top, visible }; |
| 532 | })); |
| 533 | ok('X4b at 360 px a notification does not cover the chat prompt', !!cover && !cover.overlaps, JSON.stringify(cover)); |
| 534 | await page.keyboard.press('F6'); |
| 535 | await page.keyboard.press('Escape'); |
| 536 | await ctx.close(); |
| 537 | } |
| 538 | |
| 539 | // ── X11: las pestañas que ya estaban abiertas al arrancar el recinto también las ve ── |
| 540 | { |
| 541 | const { ctx, page } = await profile({ mock: false }); |
| 542 | await seed(page, [FMT]); |
| 543 | await openIde(page); |
| 544 | const before = await page.evaluate(async () => { |
| 545 | const ide = await import('/js/ide.js'); |
| 546 | await ide.openFile('app.js'); |
| 547 | await ide.openFile('fruits.txt'); |
| 548 | const b = performance.getEntriesByType('resource').some(e => e.name.includes('/js/ext2/bridge.js')) ? (await import('/js/ext2/bridge.js')).state().state : 'not loaded'; |
| 549 | return b; |
| 550 | }); |
| 551 | const fmt = await until(() => page.evaluate(async () => { const s = (await import('/js/ext2/bridge.js')).state(); return s.state === 'running' ? s.extensions.find(e => e.id === 'elffuss-test.fmt')?.state || null : null; }).then(x => (x === 'active' ? x : null)), { timeout: 90000 }); |
| 552 | const active = await page.evaluate(() => window.monaco.editor.getEditors()[0].getModel().getLanguageId()); |
| 553 | ok('X11 a JavaScript tab opened before the sandbox ran starts the extension that waits for JavaScript, without visiting it again', before !== 'running' && fmt === 'active' && active === 'plaintext', JSON.stringify({ before, fmt, active })); |
| 554 | await ctx.close(); |
| 555 | } |
| 556 | |
| 557 | // ── X12: en español, lo que dice el nivel 2 está en español ── |
| 558 | { |
| 559 | const ctx = await browser.newContext({ locale: 'es-ES', viewport: { width: 1280, height: 860 } }); |
| 560 | await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); localStorage.setItem('elffusscode.ext.onlyWorks', '0'); } catch { /* — */ } }); |
| 561 | const page = await ctx.newPage(); |
| 562 | page.on('pageerror', e => { if (e.message !== 'Canceled') errors.push(e.message); }); |
| 563 | await page.goto(srv.codeOrigin + '/', { waitUntil: 'domcontentloaded' }); |
| 564 | await seed(page, [SORT]); |
| 565 | await openIde(page); |
| 566 | ok('X12 premise: the sandbox runs sort', !!(await until(() => page.evaluate(async () => (await import('/js/ext2/bridge.js')).state().state === 'running'), { timeout: 90000 }))); |
| 567 | await page.evaluate(() => { if (!(document.getElementById('ext-panel')?.isConnected && !document.getElementById('settings-panel').hidden)) document.getElementById('act-ext').click(); }); |
| 568 | const keys = await until(() => page.evaluate(() => { const d = document.querySelector('#ext-installed .ext-row[data-id="elffuss-test.sort"] .ext-x2-keys'); return d ? d.textContent : null; })); |
| 569 | ok('X12 the keybindings that were not bound say why in Spanish', !!keys && /reservado por Elffuss Code o el navegador/.test(keys) && !/reserved by/.test(keys), String(keys)); |
| 570 | await ctx.close(); |
| 571 | } |
| 572 | |
| 573 | // ── X6: el aspecto de Code, igual con y sin extensiones de código ── |
| 574 | const SELECTORS = ['body', '#ide', '#activity', '#tree', '#tabs-bar', '#tabs-bar .tab', '#tabs-bar .tab.active', '#editor', '#statusbar', '#chat-log', |
| 575 | '#prompt', '#btn-send', '#conv-tabs .tab', '#palette', '#pal-input', '#palette .pal-item', '#settings-panel', '#ext-panel', '#ext-q', '#ext-results .ext-row', |
| 576 | '#ext-results .ext-install', '.ext-chip', '.monaco-editor', '.monaco-editor .view-lines', '#act-ext']; |
| 577 | const PROPS = ['color', 'background-color', 'font-family', 'font-size', 'font-weight', 'line-height', 'padding-top', 'padding-right', 'padding-bottom', 'padding-left', |
| 578 | 'margin-top', 'margin-bottom', 'border-top-width', 'border-top-style', 'border-top-color', 'border-radius', 'display', 'position', 'z-index', 'box-shadow', 'opacity', 'cursor', 'letter-spacing', 'text-transform']; |
| 579 | async function looks(withCode) { |
| 580 | const { ctx, page } = await profile(); |
| 581 | if (withCode) await seed(page, [NOOP]); |
| 582 | await openIde(page); |
| 583 | await page.evaluate(async () => { await (await import('/js/ide.js')).openFile('app.js'); }); |
| 584 | if (withCode) await until(() => page.evaluate(async () => (await import('/js/ext2/bridge.js')).state().state === 'running'), { timeout: 90000 }); |
| 585 | await panel(page); |
| 586 | await search(page, 'elffuss-ux'); |
| 587 | await until(async () => (await page.locator('#ext-results .ext-row').count()) === fixtures.length); |
| 588 | const css = await page.evaluate(() => [...document.styleSheets].map(s => s.href || 'inline').filter(h => /ext2\.css/.test(h)).length); |
| 589 | const panelStyles = await page.evaluate(({ SELECTORS, PROPS }) => Object.fromEntries(SELECTORS.filter(s => !s.includes('pal')).map(s => { |
| 590 | const e = document.querySelector(s); |
| 591 | return [s, e ? Object.fromEntries(PROPS.map(p => [p, getComputedStyle(e).getPropertyValue(p)])) : null]; |
| 592 | })), { SELECTORS, PROPS }); |
| 593 | await page.click('#settings-close').catch(() => page.keyboard.press('Escape')); |
| 594 | await page.evaluate(() => window.monaco.editor.getEditors()[0].focus()); |
| 595 | await page.keyboard.press(`${process.platform === 'darwin' ? 'Meta' : 'Control'}+KeyP`); |
| 596 | await page.waitForSelector('#palette:not([hidden])'); |
| 597 | await page.fill('#pal-input', 'a'); |
| 598 | await sleep(300); |
| 599 | const palStyles = await page.evaluate(({ SELECTORS, PROPS }) => Object.fromEntries(SELECTORS.filter(s => s.includes('pal')).map(s => { |
| 600 | const e = document.querySelector(s); |
| 601 | return [s, e ? Object.fromEntries(PROPS.map(p => [p, getComputedStyle(e).getPropertyValue(p)])) : null]; |
| 602 | })), { SELECTORS, PROPS }); |
| 603 | await ctx.close(); |
| 604 | return { styles: { ...panelStyles, ...palStyles }, css }; |
| 605 | } |
| 606 | const plain = await looks(false); |
| 607 | const withCode = await looks(true); |
| 608 | const missing = SELECTORS.filter(s => !plain.styles[s]); |
| 609 | const differ = SELECTORS.filter(s => JSON.stringify(plain.styles[s]) !== JSON.stringify(withCode.styles[s])) |
| 610 | .map(s => s + ': ' + PROPS.filter(p => plain.styles[s]?.[p] !== withCode.styles[s]?.[p]).map(p => `${p} ${plain.styles[s]?.[p]} → ${withCode.styles[s]?.[p]}`).join(', ')); |
| 611 | ok('X6 premise: all 25 elements exist, and ext2.css is loaded only with code running', !missing.length && plain.css === 0 && withCode.css > 0, JSON.stringify({ missing, css: [plain.css, withCode.css] })); |
| 612 | ok(`X6 the computed styles of Code’s 25 elements are identical with and without code extensions (${PROPS.length} properties each)`, !differ.length, differ.slice(0, 4).join(' | ')); |
| 613 | |
| 614 | ok('no page errors', errors.length === 0, errors.slice(0, 3).join(' | ')); |
| 615 | await browser.close(); |
| 616 | await srv.close(); |
| 617 | console.log(fails ? `\n❌ ${fails} failed` : '\n✅ all passed'); |
| 618 | process.exit(fails ? 1 : 0); |