Elffuss BraidHub

utopia-ia/elffuss-code public

fc9a8dba96f6 · 49.6 KiBRawPermalink
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 as code.elffuss.com): the
32// lines say so, the run button is inert with the reason, and the filter
33// 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)
48import fs from 'node:fs';
49import path from 'node:path';
50import { fileURLToPath } from 'node:url';
51import { chromium } from 'playwright';
52import { startServer } from './lib/x2-server.mjs';
53import { mockOpenVsx } from './lib/openvsx-mock.mjs';
54import { seed, UI, NOOP, SORT, FMT } from './lib/x2-fixtures.mjs';
55
56const HERE = path.dirname(fileURLToPath(import.meta.url));
57let fails = 0;
58const ok = (name, c, extra = '') => { console.log((c ? '✅' : '❌') + ' ' + name + (extra ? ' — ' + extra : '')); if (!c) fails++; };
59const sleep = ms => new Promise(r => setTimeout(r, ms));
60async 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á» ──
68const 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});
72const theme = { themes: [{ label: 'T', uiTheme: 'vs-dark', path: './t.json' }] };
73const 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];
89for (const f of fixtures) f.keywords = ['elffuss-ux'];
90
91const srv = await startServer();
92const browser = await chromium.launch();
93const errors = [];
94async 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'); } 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}
109const 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};
113const panel = async page => { await page.click('#act-ext'); await until(() => page.evaluate(() => !document.getElementById('settings-panel').hidden && !!document.getElementById('ext-panel'))); };
114const search = async (page, q) => { await page.fill('#ext-q', q); await page.press('#ext-q', 'Enter'); };
115const row = (page, id) => page.locator(`#ext-results .ext-row[data-id="${id}"]`);
116
117// ── X1: qué funcionará ──
118const { ctx, page } = await profile();
119await openIde(page);
120await panel(page);
121await search(page, 'elffuss-ux');
122await until(async () => (await page.locator('#ext-results .ext-row').count()) === fixtures.length);
123async 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}
130const d = {};
131for (const f of fixtures) d[f.name] = await detail(`${f.namespace}.${f.name}`);
132ok('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));
133ok('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));
135ok('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));
136ok('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));
138ok('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));
139ok('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));
141ok('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));
144for (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}
147ok('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']));
148ok('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 ──
151const chip = page.locator('#ext-works');
152ok('X2 the chip is a toggle, off by default', (await chip.getAttribute('aria-pressed')) === 'false' && (await chip.evaluate(b => b.tagName)) === 'BUTTON');
153await chip.click();
154const filtered = await until(async () => {
155 const ids = await page.locator('#ext-results .ext-row').evaluateAll(rs => rs.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});
159const shouldHide = ['elffuss-ux.webengine', 'elffuss-ux.webnever', 'eamodio.gitlens', 'elffuss-ux.pyreflike'];
160ok('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));
162const rowLines = await page.evaluate(() => [...document.querySelectorAll('#ext-results .ext-row[data-id="elffuss-ux.decl"] .ext-x2-lines div')].map(x => x.textContent));
163ok('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));
164ok('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')));
166await chip.click();
167ok('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 ──
170const manifest = JSON.parse(fs.readFileSync(path.join(HERE, '../web/js/ext2/vendor-manifest.json'), 'utf8'));
171const runtimeMb = (manifest.files.reduce((n, f) => n + f.gz, 0) / 1e6).toFixed(1);
172await row(page, 'esbenp.prettier-vscode').locator('.ext-install-code').click();
173const consent = await until(() => page.evaluate(() => document.querySelector('#x2-consent [role="dialog"]')?.textContent || null));
174const 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);
175ok('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 ──
178const 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});
182const inside = [];
183for (let i = 0; i < 6; i++) { await page.keyboard.press('Tab'); inside.push(await page.evaluate(() => !!document.activeElement?.closest('#x2-consent'))); }
184await page.keyboard.press('Escape');
185const back = await until(() => page.evaluate(() => !document.querySelector('#x2-consent') && document.activeElement?.classList.contains('ext-install-code')));
186ok('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»)
188await row(page, 'elffuss-ux.mixedcode').locator('.ext-install-code').click();
189const mixedButtons = await until(() => page.evaluate(() => { const d = document.querySelector('#x2-consent [role="dialog"]'); return d ? [...d.querySelectorAll('button')].map(b => b.textContent) : null; }));
190ok('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));
191await 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)
193await row(page, 'elffuss-ux.mixedcode').locator('.ext-install-code').click();
194const 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}));
205ok('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));
206await page.keyboard.press('Escape');
207await 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 await openIde(page);
236 await panel(page);
237 await search(page, 'elffuss-ux');
238 await until(async () => (await page.locator('#ext-results .ext-row').count()) === fixtures.length);
239 await row(page, 'elffuss-ux.webok').locator('.ext-install').click();
240 const after = await until(() => page.evaluate(() => {
241 const r = [...document.querySelectorAll('#ext-results .ext-row')].find(x => x.dataset.id === 'elffuss-ux.webok');
242 const code = r?.querySelector('.ext-install-code');
243 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;
244 }));
245 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',
246 !!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));
247 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));
248 await ctx.close();
249}
250
251// ── X5 (diálogos de una extensión) y X4 (teléfono) ──
252{
253 const { ctx, page } = await profile({ width: 390, height: 844, mock: false });
254 await seed(page, [UI, SORT]);
255 await openIde(page);
256 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 });
257 ok('X4 premise: at 390 px the sandbox runs the two fixtures', !!up);
258 await page.evaluate(() => { window.__ask = import('/js/ext2/bridge.js').then(b => b.runCommand('x2ui.ask')); });
259 const toast = await until(() => page.evaluate(() => {
260 const t = [...document.querySelectorAll('#x2-toasts .x2-toast')].find(x => x.textContent.includes('x2 asks'));
261 if (!t) return null;
262 const r = t.getBoundingClientRect();
263 return { role: t.getAttribute('role'), left: r.left, right: r.right, w: innerWidth, sw: document.documentElement.scrollWidth };
264 }));
265 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));
266 await page.click('#x2-toasts .x2-toast:has-text("x2 asks") .x2-toast-buttons button:has-text("Yes")');
267 await until(() => page.evaluate(() => !!document.querySelector('#x2-dialog [role="dialog"]')));
268 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 }; });
269 const trapped = [];
270 for (let i = 0; i < 4; i++) { await page.keyboard.press('Shift+Tab'); trapped.push(await page.evaluate(() => !!document.activeElement?.closest('#x2-dialog'))); }
271 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 }));
272 await page.keyboard.press('Escape');
273 const pick = await until(() => page.evaluate(() => {
274 const p = document.getElementById('x2-pick');
275 if (!p || p.classList.contains('x2-inputbox')) return null;
276 const inp = p.querySelector('input'), list = p.querySelector('[role="listbox"]');
277 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') };
278 }));
279 await page.keyboard.press('ArrowDown');
280 await page.keyboard.press('ArrowDown');
281 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') }; });
282 await page.keyboard.press('Enter');
283 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
284 && moved.label === 'c' && moved.selected === 'true', JSON.stringify({ pick, moved }));
285 await until(() => page.evaluate(() => document.querySelectorAll('#x2-pick .x2-pick-item').length === 3));
286 await page.keyboard.press('Escape');
287 await until(() => page.evaluate(() => !!document.querySelector('#x2-input input')));
288 await page.keyboard.press('Escape');
289 const res = JSON.parse(await page.evaluate(() => window.__ask) || '{}');
290 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));
291 // un comando desde el panel, en el teléfono
292 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()); });
293 // en un teléfono no hay barra de actividad: el panel se abre con «/extensions»
294 await page.click('#btn-slash');
295 await page.locator('#menu .menu-item', { hasText: '/extensions' }).click();
296 await until(() => page.evaluate(() => !!document.getElementById('ext-panel')?.isConnected && !document.getElementById('settings-panel').hidden));
297 const runBtn = page.locator('#ext-installed .ext-row[data-id="elffuss-test.sort"] [data-k="cmd:x2sort.sortLines"]');
298 await until(async () => (await runBtn.count()) === 1);
299 const layout = await page.evaluate(() => ({ sw: document.documentElement.scrollWidth, w: innerWidth }));
300 await runBtn.click();
301 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));
302 await ctx.close();
303}
304
305// ── X7: donde el nivel 2 no puede arrancar: Code en un host sin recinto en
306// config.js, como code.elffuss.com hoy (aquí «code.localhost», que el navegador
307// trata como contexto seguro y resuelve a sí mismo; config.js da a los dos lo
308// mismo: ningún recinto) ──
309{
310 const alias = 'code.localhost';
311 const srv2 = await startServer({ codeAliases: [alias] });
312 const origin2 = `http://${alias}:${srv2.port}`;
313 const b2 = browser;
314 const ctx2 = await b2.newContext({ viewport: { width: 1280, height: 860 } });
315 await ctx2.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch { /* — */ } });
316 await mockOpenVsx(ctx2, fixtures);
317 const p2 = await ctx2.newPage();
318 p2.on('pageerror', e => { if (e.message !== 'Canceled') errors.push('X7: ' + e.message); });
319 await p2.goto(origin2 + '/?test-opfs', { waitUntil: 'domcontentloaded' });
320 await p2.waitForFunction(() => !!window.monaco?.editor?.getEditors?.().length, null, { timeout: 30000 });
321 const rt = await p2.evaluate(async () => (await import('/js/ext2/vendor.js')).runtimeInfo());
322 const sameAsProd = await p2.evaluate(async () => { const c = await import('/js/ext2/config.js'); return c.sandboxOrigin({ hostname: 'code.elffuss.com', origin: 'https://code.elffuss.com', port: '' }) === null && c.sandboxOrigin(location) === null; });
323 ok('X7 premise: Code on a host with no sandbox (as code.elffuss.com today): level 2 is not available on this site', rt.available === false && rt.reason === 'site' && sameAsProd, JSON.stringify(rt));
324 await panel(p2);
325 await search(p2, 'elffuss-ux');
326 await until(async () => (await p2.locator('#ext-results .ext-row').count()) === fixtures.length);
327 const r7 = id => p2.locator(`#ext-results .ext-row[data-id="${id}"]`);
328 await r7('elffuss-ux.webok').locator('.ext-name').click();
329 const t7 = await until(async () => { const t = await r7('elffuss-ux.webok').locator('.ext-detail').innerText(); return /Licence|License/.test(t) ? t : null; });
330 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; });
331 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',
332 /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 || '')
333 && run7?.inert && /Not available on this site yet/.test(run7.title), JSON.stringify({ t7, run7 }));
334 await p2.click('#ext-works');
335 const f7 = await until(async () => {
336 const head = await p2.textContent('#ext-results .sk-h').catch(() => '');
337 return new RegExp(`checked ${fixtures.length} of ${fixtures.length}`).test(head) ? p2.locator('#ext-results .ext-row').evaluateAll(rs => rs.map(r => r.dataset.id)) : null;
338 });
339 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')
340 && f7.includes('elffuss-ux.decl') && f7.includes('elffuss-ux.mixedcode'), JSON.stringify(f7));
341 await ctx2.close();
342 await srv2.close();
343}
344
345// ── X8: los avisos y el selector, con el teclado ──
346const MOD = process.platform === 'darwin' ? 'Meta' : 'Control';
347const 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]);
348const 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 });
349{
350 const { ctx, page } = await profile({ mock: false });
351 await seed(page, [UI, SORT]);
352 await openIde(page);
353 ok('X8 premise: the sandbox runs the UI fixture', !!(await runningWith(page, 'elffuss-test.ui')));
354 await page.evaluate(async () => { await (await import('/js/ide.js')).openFile('fruits.txt'); window.monaco.editor.getEditors()[0].focus(); });
355 const inEditor = () => page.evaluate(() => !!document.activeElement?.closest('#editor'));
356 const toastWith = text => until(() => page.evaluate(text => [...document.querySelectorAll('#x2-toasts .x2-toast')].some(x => x.textContent.includes(text)), text));
357 // F6: del editor al aviso y de vuelta
358 await bridgeRun(page, 'x2ui.question', null, '__q');
359 await toastWith('x2 question');
360 const hint = await page.evaluate(() => [...document.querySelectorAll('#x2-toasts .x2-toast')].find(x => x.textContent.includes('x2 question'))?.querySelector('.x2-sr')?.textContent || '');
361 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);
362 const start = await inEditor();
363 await page.keyboard.press('F6');
364 const f1 = await page.evaluate(() => (document.activeElement?.closest('#x2-toasts') ? document.activeElement.textContent : null));
365 await page.keyboard.press('F6');
366 const back1 = await inEditor();
367 await page.keyboard.press('F6');
368 await page.keyboard.press('Tab');
369 const f2 = await page.evaluate(() => document.activeElement?.textContent);
370 await page.keyboard.press('Enter');
371 const ans1 = await page.evaluate(() => window.__q);
372 const back2 = await until(inEditor);
373 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,
374 JSON.stringify({ start, f1, back1, f2, ans1, back2 }));
375 // la paleta de Code: «Extensiones: ir al aviso», solo mientras hay uno
376 await bridgeRun(page, 'x2ui.question', null, '__q2');
377 await toastWith('x2 question');
378 await page.keyboard.press(`${MOD}+Shift+KeyP`);
379 await page.waitForSelector('#palette:not([hidden])');
380 await page.fill('#pal-input', '>go to the notification');
381 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; }));
382 await page.keyboard.press('Enter');
383 const f3 = await until(() => page.evaluate(() => (document.activeElement?.closest('#x2-toasts') ? document.activeElement.textContent : null)));
384 await page.keyboard.press('Escape');
385 const ans2 = await page.evaluate(() => window.__q2);
386 const notBody = await until(() => page.evaluate(() => document.activeElement && document.activeElement !== document.body));
387 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',
388 palRow === 'Extensions: Go to the notification | F6' && f3 === 'Keep' && ans2 === 'undefined' && !!notBody, JSON.stringify({ palRow, f3, ans2, notBody }));
389 await page.keyboard.press(`${MOD}+Shift+KeyP`);
390 await page.waitForSelector('#palette:not([hidden])');
391 await page.fill('#pal-input', '>go to the notification');
392 await sleep(300);
393 const gone = await page.evaluate(() => [...document.querySelectorAll('#palette .pal-item .pi-name')].some(x => x.textContent === 'Extensions: Go to the notification'));
394 await page.keyboard.press('Escape');
395 ok('X8 …and the entry goes away with the last notification', !gone);
396 // un aviso sin botones: no se va mientras el ratón o el foco están en él
397 await page.evaluate(() => window.monaco.editor.getEditors()[0].focus());
398 await bridgeRun(page, 'x2ui.note', null, '__n');
399 await toastWith('x2 note');
400 const note = page.locator('#x2-toasts .x2-toast', { hasText: 'x2 note' });
401 await note.hover();
402 await sleep(10500);
403 const whileHovered = await note.count();
404 await page.keyboard.press('F6');
405 await page.mouse.move(5, 5);
406 await sleep(10500);
407 const whileFocused = await note.count();
408 const onClose = await page.evaluate(() => document.activeElement?.classList.contains('x2-toast-close'));
409 await page.keyboard.press('Enter');
410 const noteRes = await page.evaluate(() => window.__n);
411 const back3 = await until(inEditor);
412 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',
413 whileHovered === 1 && whileFocused === 1 && onClose && noteRes === 'closed' && !!back3, JSON.stringify({ whileHovered, whileFocused, onClose, noteRes, back3 }));
414 // el selector y el cuadro de texto: Tab no sale, Escape desde sus botones, Espacio con filtro
415 await bridgeRun(page, 'x2ui.ask', null, '__ask');
416 await page.click('#x2-toasts .x2-toast:has-text("x2 asks") .x2-toast-buttons button:has-text("Yes")');
417 await until(() => page.evaluate(() => !!document.querySelector('#x2-dialog [role="dialog"]')));
418 await page.keyboard.press('Escape');
419 await until(() => page.evaluate(() => { const p = document.getElementById('x2-pick'); return p && !p.classList.contains('x2-inputbox') && !p.querySelector('[aria-multiselectable]'); }));
420 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); });
421 const tabs1 = [];
422 for (let i = 0; i < 3; i++) { await page.keyboard.press('Tab'); tabs1.push(await where()); }
423 await page.keyboard.press('Escape');
424 await until(() => page.evaluate(() => !!document.querySelector('#x2-pick [aria-multiselectable]')));
425 await page.keyboard.type('t');
426 await page.keyboard.press('Space');
427 await page.keyboard.press('ArrowDown');
428 await page.keyboard.press('Space');
429 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 }; });
430 await page.keyboard.press('Enter');
431 await until(() => page.evaluate(() => !!document.querySelector('#x2-input input')));
432 const tabs2 = [];
433 for (let i = 0; i < 3; i++) { await page.keyboard.press('Tab'); tabs2.push(await where()); }
434 await page.keyboard.press('Tab');
435 await page.keyboard.press('Escape');
436 const res = JSON.parse(await page.evaluate(() => window.__ask) || '{}');
437 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 }));
438 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'])
439 && JSON.stringify(res.many) === '["three"]' && /Space checks the highlighted one/.test(multi.ph), JSON.stringify({ multi, many: res.many }));
440 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 }));
441 await ctx.close();
442}
443
444// ── X9: «Bloquear peticiones» y desbloquear; X10: apagar todo y el botón de cada una ──
445{
446 const { ctx, page } = await profile({ mock: false });
447 await seed(page, [UI]);
448 await openIde(page);
449 ok('X9 premise: the sandbox runs the UI fixture', !!(await runningWith(page, 'elffuss-test.ui')));
450 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; }));
451 await bridgeRun(page, 'x2ui.open', 'https://blocked.example/a', '__o1');
452 await dialog();
453 await page.click('#x2-open button:has-text("Block requests for this session")');
454 const r1 = await page.evaluate(() => window.__o1);
455 await bridgeRun(page, 'x2ui.open', 'https://blocked.example/b', '__o2');
456 const r2 = await page.evaluate(() => window.__o2);
457 const sb = await page.textContent('#statusbar');
458 const noDialog = await page.evaluate(() => !document.querySelector('#x2-open'));
459 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 }));
460 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(); });
461 // (los enlaces los calcula el worker del editor: se reintenta hasta que el enlace existe)
462 let link = null;
463 for (let i = 0; i < 10 && !link; i++) {
464 await sleep(500);
465 await page.evaluate(() => window.monaco.editor.getEditors()[0].getAction('editor.action.openLink').run());
466 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 });
467 }
468 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));
469 await page.keyboard.press('Escape');
470 await page.evaluate(() => window.monaco.editor.getEditors()[0].getModel().setValue('pear\napple\nfig\n'));
471 await panel(page);
472 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; }));
473 await page.focus('#ext-installed .ext-x2-unblock');
474 await page.keyboard.press('Enter');
475 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; }));
476 await page.click('#settings-close');
477 await bridgeRun(page, 'x2ui.open', 'https://blocked.example/c', '__o3');
478 const again = await dialog();
479 await page.keyboard.press('Escape');
480 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',
481 !!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 }));
482 // X10
483 await panel(page);
484 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 }));
485 const t1 = await btnOf();
486 await page.focus('#ext-installed .ext-x2-alloff');
487 await page.keyboard.press('Enter');
488 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; }));
489 const t2 = await btnOf();
490 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));
491 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'
492 && t2.pressed === null && t2.label === 'Run the code of X2 ui' && t2.text === 'Run code', JSON.stringify({ t1, t2 }));
493 await ctx.close();
494}
495
496// ── X4b: en un teléfono (360×640), una dirección larga ──
497{
498 const { ctx, page } = await profile({ width: 360, height: 640, mock: false });
499 await seed(page, [UI]);
500 await openIde(page);
501 ok('X4b premise: at 360 px the sandbox runs the UI fixture', !!(await runningWith(page, 'elffuss-test.ui')));
502 const LONG = 'https://github.com/search?q=' + Array.from({ length: 300 }, (_, i) => 'word' + i).join('+') + '&type=code';
503 await bridgeRun(page, 'x2ui.open', LONG, '__long');
504 const g = await until(() => page.evaluate(() => {
505 const d = document.querySelector('#x2-open [role="dialog"]');
506 if (!d) return null;
507 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; };
508 const box = d.querySelector('.x2-code'), sites = d.querySelectorAll('.x2-site');
509 return { scrollTop: d.scrollTop, title: inView(d.querySelector('.x2-modal-title')), site: inView(sites[0]), siteAgain: inView(sites[1]), again: sites[1]?.textContent || '',
510 focus: document.activeElement?.textContent, focusInView: inView(document.activeElement), boxScrolls: box.scrollHeight > box.clientHeight, code: box.textContent, sw: document.documentElement.scrollWidth, w: innerWidth };
511 }));
512 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',
513 !!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 }));
514 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));
515 await page.keyboard.press('Escape');
516 // y el aviso de una extensión no tapa el prompt del chat en un teléfono
517 await bridgeRun(page, 'x2ui.question', null, '__q');
518 const cover = await until(() => page.evaluate(() => {
519 const t = [...document.querySelectorAll('#x2-toasts .x2-toast')].find(x => x.textContent.includes('x2 question'));
520 const pr = document.getElementById('prompt');
521 if (!t || !pr) return null;
522 const a = t.getBoundingClientRect(), b = pr.getBoundingClientRect();
523 const visible = b.width > 0 && b.height > 0;
524 return { overlaps: visible && a.left < b.right && a.right > b.left && a.top < b.bottom && a.bottom > b.top, visible };
525 }));
526 ok('X4b at 360 px a notification does not cover the chat prompt', !!cover && !cover.overlaps, JSON.stringify(cover));
527 await page.keyboard.press('F6');
528 await page.keyboard.press('Escape');
529 await ctx.close();
530}
531
532// ── X11: las pestañas que ya estaban abiertas al arrancar el recinto también las ve ──
533{
534 const { ctx, page } = await profile({ mock: false });
535 await seed(page, [FMT]);
536 await openIde(page);
537 const before = await page.evaluate(async () => {
538 const ide = await import('/js/ide.js');
539 await ide.openFile('app.js');
540 await ide.openFile('fruits.txt');
541 const b = performance.getEntriesByType('resource').some(e => e.name.includes('/js/ext2/bridge.js')) ? (await import('/js/ext2/bridge.js')).state().state : 'not loaded';
542 return b;
543 });
544 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 });
545 const active = await page.evaluate(() => window.monaco.editor.getEditors()[0].getModel().getLanguageId());
546 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 }));
547 await ctx.close();
548}
549
550// ── X12: en español, lo que dice el nivel 2 está en español ──
551{
552 const ctx = await browser.newContext({ locale: 'es-ES', viewport: { width: 1280, height: 860 } });
553 await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch { /* — */ } });
554 const page = await ctx.newPage();
555 page.on('pageerror', e => { if (e.message !== 'Canceled') errors.push(e.message); });
556 await page.goto(srv.codeOrigin + '/', { waitUntil: 'domcontentloaded' });
557 await seed(page, [SORT]);
558 await openIde(page);
559 ok('X12 premise: the sandbox runs sort', !!(await until(() => page.evaluate(async () => (await import('/js/ext2/bridge.js')).state().state === 'running'), { timeout: 90000 })));
560 await page.click('#act-ext');
561 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; }));
562 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));
563 await ctx.close();
564}
565
566// ── X6: el aspecto de Code, igual con y sin extensiones de código ──
567const SELECTORS = ['body', '#ide', '#activity', '#tree', '#tabs-bar', '#tabs-bar .tab', '#tabs-bar .tab.active', '#editor', '#statusbar', '#chat-log',
568 '#prompt', '#btn-send', '#conv-tabs .tab', '#palette', '#pal-input', '#palette .pal-item', '#settings-panel', '#ext-panel', '#ext-q', '#ext-results .ext-row',
569 '#ext-results .ext-install', '.ext-chip', '.monaco-editor', '.monaco-editor .view-lines', '#act-ext'];
570const PROPS = ['color', 'background-color', 'font-family', 'font-size', 'font-weight', 'line-height', 'padding-top', 'padding-right', 'padding-bottom', 'padding-left',
571 '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'];
572async function looks(withCode) {
573 const { ctx, page } = await profile();
574 if (withCode) await seed(page, [NOOP]);
575 await openIde(page);
576 await page.evaluate(async () => { await (await import('/js/ide.js')).openFile('app.js'); });
577 if (withCode) await until(() => page.evaluate(async () => (await import('/js/ext2/bridge.js')).state().state === 'running'), { timeout: 90000 });
578 await panel(page);
579 await search(page, 'elffuss-ux');
580 await until(async () => (await page.locator('#ext-results .ext-row').count()) === fixtures.length);
581 const css = await page.evaluate(() => [...document.styleSheets].map(s => s.href || 'inline').filter(h => /ext2\.css/.test(h)).length);
582 const panelStyles = await page.evaluate(({ SELECTORS, PROPS }) => Object.fromEntries(SELECTORS.filter(s => !s.includes('pal')).map(s => {
583 const e = document.querySelector(s);
584 return [s, e ? Object.fromEntries(PROPS.map(p => [p, getComputedStyle(e).getPropertyValue(p)])) : null];
585 })), { SELECTORS, PROPS });
586 await page.click('#settings-close').catch(() => page.keyboard.press('Escape'));
587 await page.evaluate(() => window.monaco.editor.getEditors()[0].focus());
588 await page.keyboard.press(`${process.platform === 'darwin' ? 'Meta' : 'Control'}+KeyP`);
589 await page.waitForSelector('#palette:not([hidden])');
590 await page.fill('#pal-input', 'a');
591 await sleep(300);
592 const palStyles = await page.evaluate(({ SELECTORS, PROPS }) => Object.fromEntries(SELECTORS.filter(s => s.includes('pal')).map(s => {
593 const e = document.querySelector(s);
594 return [s, e ? Object.fromEntries(PROPS.map(p => [p, getComputedStyle(e).getPropertyValue(p)])) : null];
595 })), { SELECTORS, PROPS });
596 await ctx.close();
597 return { styles: { ...panelStyles, ...palStyles }, css };
598}
599const plain = await looks(false);
600const withCode = await looks(true);
601const missing = SELECTORS.filter(s => !plain.styles[s]);
602const differ = SELECTORS.filter(s => JSON.stringify(plain.styles[s]) !== JSON.stringify(withCode.styles[s]))
603 .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(', '));
604ok('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] }));
605ok(`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(' | '));
606
607ok('no page errors', errors.length === 0, errors.slice(0, 3).join(' | '));
608await browser.close();
609await srv.close();
610console.log(fails ? `\n❌ ${fails} failed` : '\n✅ all passed');
611process.exit(fails ? 1 : 0);