| 1 | // Commands of a real web extension in Code, and Code's own shortcuts beside it. |
| 2 | // |
| 3 | // node tests/x2_commands.mjs (own server; without the pinned .vsix |
| 4 | // in tests/.cache and no network: NOT RUN) |
| 5 | // |
| 6 | // Tyriar.sort-lines 1.12.0 (pinned, SHA-256 checked) is installed with its code |
| 7 | // through Code's own install path for a .vsix file, next to "hostile", a |
| 8 | // synthetic extension built here whose command titles are HTML and whose |
| 9 | // keybindings ask for Code's and the browser's chords and for sort-lines' F9. |
| 10 | // |
| 11 | // K1 both install with their code and the sandbox runs them |
| 12 | // K2 Code's palette (Cmd+Shift+P, ">"): sort-lines' commands with its |
| 13 | // name; choosing one sorts the selection |
| 14 | // K3 F1 (Monaco's command list): the same commands; running one works |
| 15 | // K4 F9 with the editor focused sorts the selection: one undo step, the |
| 16 | // tab shows unsaved changes, Cmd+S writes the file to the project |
| 17 | // K5 the editor's context menu carries the command sort-lines puts there |
| 18 | // K6 hostile's chords for Cmd+P, Cmd+Shift+P, Ctrl+`, Cmd+S, F1, |
| 19 | // Cmd+Shift+O and Cmd+W are not bound, and its F9 loses to sort-lines; |
| 20 | // the Extensions panel lists each with the reason |
| 21 | // K7 with both running, Cmd+P, Cmd+Shift+P, Ctrl+`, "@" in the palette, |
| 22 | // Cmd+Shift+O and Cmd+S do exactly what they do with no extension |
| 23 | // (the same steps in a profile without extensions) |
| 24 | // K8 hostile titles stay text in the palette, F1, the context menu and the |
| 25 | // panel: no element is created and no handler runs |
| 26 | // K9 the beacon gets nothing, the sandbox site only its two documents, no |
| 27 | // page errors |
| 28 | import { chromium } from 'playwright'; |
| 29 | import { startServer } from './lib/x2-server.mjs'; |
| 30 | import { startBeacon } from './lib/beacon.mjs'; |
| 31 | import { fetchVsix, PINNED } from './lib/x2-vsix.mjs'; |
| 32 | import { zip } from './ext_fixtures.mjs'; |
| 33 | |
| 34 | let fails = 0; |
| 35 | const ok = (name, c, extra = '') => { console.log((c ? '✅' : '❌') + ' ' + name + (extra ? ' — ' + extra : '')); if (!c) fails++; }; |
| 36 | const sleep = ms => new Promise(r => setTimeout(r, ms)); |
| 37 | async function until(fn, { timeout = 20000, every = 150 } = {}) { |
| 38 | const end = Date.now() + timeout; |
| 39 | let v; |
| 40 | while (Date.now() < end) { try { v = await fn(); if (v) return v; } catch { /* reintenta */ } await sleep(every); } |
| 41 | return v; |
| 42 | } |
| 43 | const MOD = process.platform === 'darwin' ? 'Meta' : 'Control'; |
| 44 | |
| 45 | let sortLines; |
| 46 | try { sortLines = (await fetchVsix({ ...PINNED.find(p => p.name === 'sort-lines'), offline: process.env.X2_OFFLINE === '1' })).bytes; } |
| 47 | catch (e) { console.log(`⏭️ NOT RUN x2_commands — Tyriar.sort-lines@1.12.0: ${e.message}`); process.exit(0); } |
| 48 | |
| 49 | // «hostile»: títulos con HTML y atajos que no le tocan |
| 50 | const EVIL_TITLE = '<img src=x onerror="window.__pwned=1">Hostile <b>title</b>'; |
| 51 | const hostile = zip(Object.entries({ |
| 52 | 'extension/package.json': JSON.stringify({ |
| 53 | name: 'hostile', publisher: 'elffuss-test', version: '1.0.0', displayName: 'Hostile <i>name</i>', license: 'MIT', |
| 54 | engines: { vscode: '^1.80.0' }, browser: './extension.js', activationEvents: [], |
| 55 | contributes: { |
| 56 | commands: [ |
| 57 | { command: 'hostile.run', title: EVIL_TITLE, category: '<svg onload="window.__pwned=2">X2' }, |
| 58 | { command: 'hostile.alt', title: 'Hostile alt' }, |
| 59 | { command: 'hostile.count', title: 'Hostile count' }, |
| 60 | ], |
| 61 | menus: { 'editor/context': [{ command: 'hostile.run', group: 'z_hostile' }] }, |
| 62 | keybindings: [ |
| 63 | ['cmd+p', 'ctrl+p'], ['cmd+shift+p', 'ctrl+shift+p'], ['ctrl+`', 'ctrl+`'], ['cmd+s', 'ctrl+s'], ['f1', 'f1'], |
| 64 | ['cmd+shift+o', 'ctrl+shift+o'], ['cmd+w', 'ctrl+w'], ['f9', 'f9'], |
| 65 | ].map(([mac, key]) => ({ command: 'hostile.run', key, mac })) |
| 66 | .concat([{ command: 'hostile.alt', key: 'alt+f9', when: 'editorTextFocus' }]), |
| 67 | }, |
| 68 | }), |
| 69 | 'extension/extension.js': `const vscode = require('vscode'); |
| 70 | exports.activate = c => { |
| 71 | c.subscriptions.push(vscode.commands.registerCommand('hostile.run', () => { globalThis.__hostileRan = (globalThis.__hostileRan || 0) + 1; return 'hostile ran'; })); |
| 72 | c.subscriptions.push(vscode.commands.registerCommand('hostile.count', () => String(globalThis.__hostileRan || 0))); |
| 73 | c.subscriptions.push(vscode.commands.registerCommand('hostile.alt', async () => { |
| 74 | const ed = vscode.window.activeTextEditor; |
| 75 | if (ed) await ed.edit(b => b.insert(new vscode.Position(0, 0), 'ALT ')); |
| 76 | return 'alt'; |
| 77 | })); |
| 78 | }; |
| 79 | `, |
| 80 | })); |
| 81 | |
| 82 | const srv = await startServer(); |
| 83 | const beacon = await startBeacon(); |
| 84 | const browser = await chromium.launch({ args: [`--host-resolver-rules=${beacon.resolverRules}`] }); |
| 85 | const errors = []; |
| 86 | |
| 87 | async function profile() { |
| 88 | const ctx = await browser.newContext({ viewport: { width: 1280, height: 860 } }); |
| 89 | await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); localStorage.setItem('elffusscode.ext.onlyWorks', '0'); } catch { /* — */ } }); |
| 90 | const page = await ctx.newPage(); |
| 91 | page.on('pageerror', e => { if (e.message !== 'Canceled') errors.push(e.message); }); |
| 92 | page.on('dialog', d => d.dismiss()); |
| 93 | await page.goto(srv.codeOrigin + '/', { waitUntil: 'domcontentloaded' }); |
| 94 | await page.evaluate(async () => { |
| 95 | const o = await navigator.storage.getDirectory(); |
| 96 | 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(); }; |
| 97 | await w('fruits.txt', 'pear\napple\nfig\n'); |
| 98 | await w('app.js', 'function zeta() {}\nfunction alpha() {}\nclass Beta { gamma() {} }\n'); |
| 99 | }); |
| 100 | return { ctx, page }; |
| 101 | } |
| 102 | const openIde = async page => { |
| 103 | await page.goto(srv.codeOrigin + '/?test-opfs', { waitUntil: 'domcontentloaded' }); |
| 104 | await page.waitForFunction(() => !!window.monaco?.editor?.getEditors?.().length, null, { timeout: 30000 }); |
| 105 | }; |
| 106 | const open = (page, p) => page.evaluate(async p => { await (await import('/js/ide.js')).openFile(p); }, p); |
| 107 | const value = page => page.evaluate(() => window.monaco.editor.getEditors()[0].getModel().getValue()); |
| 108 | const setValue = (page, v) => page.evaluate(v => window.monaco.editor.getEditors()[0].getModel().setValue(v), v); |
| 109 | const select = (page, a, b, c, d) => page.evaluate(([a, b, c, d]) => { const ed = window.monaco.editor.getEditors()[0]; ed.setSelection({ startLineNumber: a, startColumn: b, endLineNumber: c, endColumn: d }); ed.focus(); }, [a, b, c, d]); |
| 110 | const readOpfs = (page, name) => page.evaluate(async n => { const o = await navigator.storage.getDirectory(); return (await (await o.getFileHandle(n)).getFile()).text(); }, name); |
| 111 | const dirty = page => page.evaluate(() => document.querySelector('#tabs-bar .tab.active .tab-x')?.classList.contains('dirty') || false); |
| 112 | const bridgeState = page => page.evaluate(async () => (await import('/js/ext2/bridge.js')).state()); |
| 113 | const focusEditor = async page => { await page.evaluate(() => window.monaco.editor.getEditors()[0].focus()); await sleep(100); }; |
| 114 | async function installFile(page, name, bytes) { |
| 115 | return page.evaluate(async ({ name, b64 }) => { |
| 116 | const bin = atob(b64); |
| 117 | const u8 = new Uint8Array(bin.length); |
| 118 | for (let i = 0; i < bin.length; i++) u8[i] = bin.charCodeAt(i); |
| 119 | const h = await (await import('/js/ide.js')).loadExt(); |
| 120 | return (await h.install(new File([u8], name), { withCode: true })).id; |
| 121 | }, { name, b64: Buffer.from(bytes).toString('base64') }); |
| 122 | } |
| 123 | const closeOverlays = async page => { |
| 124 | await page.keyboard.press('Escape'); |
| 125 | await page.evaluate(() => { const p = document.getElementById('palette'); if (p) p.hidden = true; }); |
| 126 | await sleep(150); |
| 127 | }; |
| 128 | |
| 129 | // K7: lo que hacen los atajos de Code, igual con extensiones que sin ellas |
| 130 | async function shortcuts(page) { |
| 131 | const out = {}; |
| 132 | await open(page, 'app.js'); |
| 133 | await focusEditor(page); |
| 134 | await page.keyboard.press(`${MOD}+KeyP`); |
| 135 | out.cmdP = await until(() => page.evaluate(() => { const p = document.getElementById('palette'); return p && !p.hidden ? { open: true, value: document.getElementById('pal-input').value } : null; }), { timeout: 5000 }); |
| 136 | await closeOverlays(page); |
| 137 | await focusEditor(page); |
| 138 | await page.keyboard.press(`${MOD}+Shift+KeyP`); |
| 139 | out.cmdShiftP = await until(() => page.evaluate(() => { const p = document.getElementById('palette'); return p && !p.hidden ? { open: true, value: document.getElementById('pal-input').value } : null; }), { timeout: 5000 }); |
| 140 | await closeOverlays(page); |
| 141 | await focusEditor(page); |
| 142 | const termBefore = await page.evaluate(() => document.getElementById('terminal-panel').hidden); |
| 143 | await page.keyboard.press('Control+Backquote'); |
| 144 | const termAfter = await until(() => page.evaluate(b => (document.getElementById('terminal-panel').hidden !== b ? String(document.getElementById('terminal-panel').hidden) : null), termBefore), { timeout: 5000 }); |
| 145 | out.ctrlBackquote = { before: termBefore, after: termAfter }; |
| 146 | await page.evaluate(() => { const t = document.getElementById('terminal-panel'); if (!t.hidden) document.getElementById('act-term')?.click(); }); |
| 147 | await sleep(200); |
| 148 | // «@» en la paleta → Ir a símbolo (quickOutline de Monaco) |
| 149 | await focusEditor(page); |
| 150 | await page.keyboard.press(`${MOD}+KeyP`); |
| 151 | await page.waitForSelector('#palette:not([hidden])'); |
| 152 | await page.fill('#pal-input', '@'); |
| 153 | await sleep(200); |
| 154 | out.atRows = await page.evaluate(() => [...document.querySelectorAll('#palette .pal-item .pi-hint')].map(x => x.textContent)); |
| 155 | await page.keyboard.press('Enter'); |
| 156 | out.atOutline = await until(() => page.evaluate(() => { |
| 157 | const w = document.querySelector('.quick-input-widget'); |
| 158 | if (!w || w.style.display === 'none') return null; |
| 159 | const names = [...w.querySelectorAll('.monaco-list-row .label-name')].map(x => x.textContent.trim()).filter(Boolean); |
| 160 | return names.length ? names.sort() : null; |
| 161 | }), { timeout: 8000 }); |
| 162 | await page.keyboard.press('Escape'); |
| 163 | await sleep(200); |
| 164 | await focusEditor(page); |
| 165 | await page.keyboard.press(`${MOD}+Shift+KeyO`); |
| 166 | out.cmdShiftO = await until(() => page.evaluate(() => { |
| 167 | const w = document.querySelector('.quick-input-widget'); |
| 168 | if (!w || w.style.display === 'none') return null; |
| 169 | const names = [...w.querySelectorAll('.monaco-list-row .label-name')].map(x => x.textContent.trim()).filter(Boolean); |
| 170 | return names.length ? names.sort() : null; |
| 171 | }), { timeout: 8000 }); |
| 172 | await page.keyboard.press('Escape'); |
| 173 | await sleep(200); |
| 174 | // Cmd+S guarda |
| 175 | await open(page, 'fruits.txt'); |
| 176 | await setValue(page, 'saved-by-shortcut\n'); |
| 177 | await focusEditor(page); |
| 178 | await page.keyboard.press(`${MOD}+KeyS`); |
| 179 | out.cmdS = await until(async () => ((await readOpfs(page, 'fruits.txt')) === 'saved-by-shortcut\n' && !(await dirty(page)) ? 'saved' : null), { timeout: 5000 }); |
| 180 | await setValue(page, 'pear\napple\nfig\n'); |
| 181 | await page.keyboard.press(`${MOD}+KeyS`); |
| 182 | await until(async () => (await readOpfs(page, 'fruits.txt')) === 'pear\napple\nfig\n', { timeout: 5000 }); |
| 183 | return out; |
| 184 | } |
| 185 | |
| 186 | // ── sin extensiones: la referencia ── |
| 187 | const plain = await profile(); |
| 188 | await openIde(plain.page); |
| 189 | const ref = await shortcuts(plain.page); |
| 190 | await plain.ctx.close(); |
| 191 | |
| 192 | // ── K1: sort-lines y hostile, con su código ── |
| 193 | const { ctx, page } = await profile(); |
| 194 | await openIde(page); |
| 195 | const idSort = await installFile(page, 'sort-lines.vsix', sortLines); |
| 196 | const idHostile = await installFile(page, 'hostile.vsix', hostile); |
| 197 | const st = await until(async () => { const s = await bridgeState(page); return s.state === 'running' && s.commands.length >= 17 ? s : null; }, { timeout: 90000 }); |
| 198 | ok('K1 sort-lines and hostile install with their code; the sandbox runs them', !!st && idSort === 'tyriar.sort-lines' && idHostile === 'elffuss-test.hostile', |
| 199 | JSON.stringify({ state: st?.state, commands: st?.commands?.length, ids: [idSort, idHostile] })); |
| 200 | |
| 201 | // ── K2: la paleta de Code ── |
| 202 | await open(page, 'fruits.txt'); |
| 203 | await select(page, 1, 1, 3, 4); |
| 204 | await page.keyboard.press(`${MOD}+Shift+KeyP`); |
| 205 | await page.waitForSelector('#palette:not([hidden])'); |
| 206 | await page.fill('#pal-input', '>sort lines (descending, case'); |
| 207 | const palRows = await until(() => page.evaluate(() => { |
| 208 | const rows = [...document.querySelectorAll('#palette .pal-item')].map(r => ({ name: r.querySelector('.pi-name').textContent, hint: r.querySelector('.pi-hint').textContent })); |
| 209 | return rows.length ? rows : null; |
| 210 | })); |
| 211 | ok('K2 Code’s palette lists sort-lines’ command, with the extension’s name', !!palRows && palRows.some(r => r.name === 'Sort lines (descending, case sensitive)' && r.hint === 'Sort lines'), JSON.stringify(palRows)); |
| 212 | await page.keyboard.press('Enter'); |
| 213 | ok('K2 choosing it sorts the selection (descending)', !!(await until(async () => (await value(page)) === 'pear\nfig\napple\n')), JSON.stringify(await value(page))); |
| 214 | |
| 215 | // ── K3: F1 ── |
| 216 | await setValue(page, 'pear\napple\nfig\n'); |
| 217 | await select(page, 1, 1, 3, 4); |
| 218 | await page.keyboard.press('F1'); |
| 219 | await page.waitForSelector('.quick-input-widget .quick-input-box input', { state: 'visible' }); |
| 220 | await page.keyboard.type('Sort lines (ascending, case sensitive)'); |
| 221 | const f1Rows = await until(() => page.evaluate(() => { |
| 222 | const names = [...document.querySelectorAll('.quick-input-widget .monaco-list-row .label-name')].map(x => x.textContent.trim()); |
| 223 | return names.length ? names : null; |
| 224 | })); |
| 225 | ok('K3 F1 lists it too', !!f1Rows && f1Rows.includes('Sort lines (ascending, case sensitive)'), JSON.stringify(f1Rows?.slice(0, 4))); |
| 226 | await page.keyboard.press('Enter'); |
| 227 | ok('K3 running it from F1 sorts the selection', !!(await until(async () => (await value(page)) === 'apple\nfig\npear\n')), JSON.stringify(await value(page))); |
| 228 | |
| 229 | // ── K4: F9, un paso de deshacer, cambios sin guardar, Cmd+S ── |
| 230 | await setValue(page, 'pear\napple\nfig\n'); |
| 231 | await page.keyboard.press(`${MOD}+KeyS`); |
| 232 | await until(async () => !(await dirty(page))); |
| 233 | await select(page, 1, 1, 3, 4); |
| 234 | await page.keyboard.press('F9'); |
| 235 | ok('K4 F9 with the editor focused sorts the selection', !!(await until(async () => (await value(page)) === 'apple\nfig\npear\n')), JSON.stringify(await value(page))); |
| 236 | ok('K4 the tab shows unsaved changes', !!(await until(() => dirty(page)))); |
| 237 | await focusEditor(page); |
| 238 | await page.keyboard.press(`${MOD}+KeyZ`); |
| 239 | ok('K4 one undo step brings the file back', !!(await until(async () => (await value(page)) === 'pear\napple\nfig\n')), JSON.stringify(await value(page))); |
| 240 | await page.keyboard.press(`${MOD}+Shift+KeyZ`); |
| 241 | await until(async () => (await value(page)) === 'apple\nfig\npear\n'); |
| 242 | await page.keyboard.press(`${MOD}+KeyS`); |
| 243 | ok('K4 Cmd+S writes the sorted file to the project, and the tab is clean', !!(await until(async () => (await readOpfs(page, 'fruits.txt')) === 'apple\nfig\npear\n' && !(await dirty(page)))), JSON.stringify(await readOpfs(page, 'fruits.txt'))); |
| 244 | |
| 245 | // ── K5: menú contextual del editor ── |
| 246 | await focusEditor(page); |
| 247 | const box = await page.locator('#editor .view-lines').boundingBox(); |
| 248 | await page.mouse.click(box.x + 40, box.y + 8, { button: 'right' }); |
| 249 | // (el menú contextual de Monaco vive en un shadow root: los localizadores de |
| 250 | // Playwright lo atraviesan, querySelector no) |
| 251 | const menu = await until(async () => { |
| 252 | const items = (await page.locator('.monaco-menu .action-label').allTextContents()).map(t => t.trim()).filter(Boolean); |
| 253 | return items.length ? { items, imgs: await page.locator('.monaco-menu img, .monaco-menu svg[onload]').count() } : null; |
| 254 | }, { timeout: 8000 }); |
| 255 | ok('K5 the editor’s context menu carries sort-lines’ command', !!menu && menu.items.includes('Sort lines (ascending, case sensitive)'), JSON.stringify(menu?.items?.slice(-6))); |
| 256 | ok('K8 …and hostile’s title there is text', !!menu && menu.items.some(t => t.includes('<img src=x')) && menu.imgs === 0, JSON.stringify(menu?.items?.filter(t => /Hostile/.test(t)))); |
| 257 | await page.keyboard.press('Escape'); |
| 258 | |
| 259 | // ── K6: atajos reservados y el conflicto, en el panel ── |
| 260 | const skipped = (await bridgeState(page)).extensions.find(e => e.id === idHostile)?.skipped || []; |
| 261 | const why = k => skipped.find(s => s.key === k)?.why || ''; |
| 262 | // la tecla que cuenta en esta plataforma (mac en macOS, key en las demás) |
| 263 | const reserved = ['cmd+p', 'cmd+shift+p', 'ctrl+`', 'cmd+s', 'f1', 'cmd+shift+o', 'cmd+w'].map(k => (process.platform === 'darwin' ? k : k.replace('cmd', 'ctrl'))); |
| 264 | ok('K6 hostile’s chords for Code’s and the browser’s shortcuts are not bound', reserved.every(k => /reserved/.test(why(k))), JSON.stringify(skipped)); |
| 265 | ok('K6 its F9 loses to sort-lines, which was there first', /conflicts with tyriar\.sort-lines/.test(why('f9')), JSON.stringify(skipped.filter(s => s.key === 'f9'))); |
| 266 | await open(page, 'fruits.txt'); |
| 267 | await setValue(page, 'b\na\n'); |
| 268 | await select(page, 1, 1, 2, 2); |
| 269 | await page.keyboard.press('F9'); |
| 270 | ok('K6 so F9 still runs sort-lines', !!(await until(async () => (await value(page)) === 'a\nb\n')), JSON.stringify(await value(page))); |
| 271 | await focusEditor(page); |
| 272 | await page.keyboard.press('Alt+F9'); |
| 273 | ok('K6 a chord nobody else has works (hostile’s Alt+F9)', !!(await until(async () => (await value(page)).startsWith('ALT '))), JSON.stringify(await value(page))); |
| 274 | await page.evaluate(() => { if (!(document.getElementById('ext-panel')?.isConnected && !document.getElementById('settings-panel').hidden)) document.getElementById('act-ext').click(); }); |
| 275 | const keysRow = page.locator(`#ext-installed .ext-row[data-id="${idHostile}"] .ext-x2-keys`); |
| 276 | await until(async () => (await keysRow.count()) === 1); |
| 277 | await keysRow.locator('summary').click(); |
| 278 | const listed = await keysRow.locator('li').allTextContents(); |
| 279 | ok('K6 the Extensions panel lists each one with the reason', listed.length === 8 && listed.filter(t => /reserved/.test(t)).length === 7 && listed.some(t => /f9 .*Sort lines|f9 .*tyriar/.test(t)), JSON.stringify(listed)); |
| 280 | const panelHostile = await page.evaluate(id => { |
| 281 | const row = document.querySelector(`#ext-installed .ext-row[data-id="${id}"]`); |
| 282 | return { text: row?.textContent || '', els: row ? row.querySelectorAll('.ext-x2-cmds img, .ext-x2-cmds svg, .ext-x2-cmds b, .ext-name i').length : -1 }; |
| 283 | }, idHostile); |
| 284 | ok('K8 the panel shows hostile’s name and command titles as text', panelHostile.text.includes('Hostile <i>name</i>') && panelHostile.text.includes('<img src=x') && panelHostile.els === 0, JSON.stringify(panelHostile).slice(0, 300)); |
| 285 | await page.click('#settings-close').catch(() => {}); |
| 286 | |
| 287 | // ── K8: títulos hostiles en la paleta y en F1 ── |
| 288 | await open(page, 'fruits.txt'); |
| 289 | await focusEditor(page); |
| 290 | await page.keyboard.press(`${MOD}+Shift+KeyP`); |
| 291 | await page.waitForSelector('#palette:not([hidden])'); |
| 292 | await page.fill('#pal-input', '>hostile'); |
| 293 | const palHostile = await until(() => page.evaluate(() => { |
| 294 | const rows = [...document.querySelectorAll('#palette .pal-item')]; |
| 295 | return rows.length ? { names: rows.map(r => r.querySelector('.pi-name').textContent), hints: rows.map(r => r.querySelector('.pi-hint').textContent), els: document.querySelectorAll('#palette img, #palette svg, #palette .pal-item b').length } : null; |
| 296 | })); |
| 297 | ok('K8 Code’s palette shows the hostile title and name as text', !!palHostile && palHostile.names.some(n => n.includes(EVIL_TITLE)) && palHostile.hints.includes('Hostile <i>name</i>') && palHostile.els === 0, JSON.stringify(palHostile)); |
| 298 | await closeOverlays(page); |
| 299 | await focusEditor(page); |
| 300 | await page.keyboard.press('F1'); |
| 301 | await page.waitForSelector('.quick-input-widget .quick-input-box input', { state: 'visible' }); |
| 302 | await page.keyboard.type('Hostile'); |
| 303 | const f1Hostile = await until(() => page.evaluate(() => { |
| 304 | const w = document.querySelector('.quick-input-widget'); |
| 305 | const names = [...w.querySelectorAll('.monaco-list-row .label-name')].map(x => x.textContent.trim()); |
| 306 | return names.length ? { names, els: w.querySelectorAll('img, svg[onload]').length } : null; |
| 307 | })); |
| 308 | ok('K8 F1 shows the hostile title as text', !!f1Hostile && f1Hostile.names.some(n => n.includes('<img src=x')) && f1Hostile.els === 0, JSON.stringify(f1Hostile)); |
| 309 | await page.keyboard.press('Escape'); |
| 310 | ok('K8 no handler from a title ran', !(await page.evaluate(() => window.__pwned))); |
| 311 | |
| 312 | // ── K7: los atajos de Code, con las dos en marcha ── |
| 313 | const withExt = await shortcuts(page); |
| 314 | const same = (a, b) => JSON.stringify(a) === JSON.stringify(b); |
| 315 | ok('K7 Cmd+P opens Code’s file palette, as without extensions', same(withExt.cmdP, ref.cmdP) && withExt.cmdP?.value === '', JSON.stringify([withExt.cmdP, ref.cmdP])); |
| 316 | ok('K7 Cmd+Shift+P opens it on commands (">"), as without extensions', same(withExt.cmdShiftP, ref.cmdShiftP) && withExt.cmdShiftP?.value === '>', JSON.stringify([withExt.cmdShiftP, ref.cmdShiftP])); |
| 317 | ok('K7 Ctrl+` toggles the terminal, as without extensions', same(withExt.ctrlBackquote, ref.ctrlBackquote) && ref.ctrlBackquote.after === 'false', JSON.stringify([withExt.ctrlBackquote, ref.ctrlBackquote])); |
| 318 | ok('K7 "@" in the palette goes to the file’s symbols, as without extensions', same(withExt.atRows, ref.atRows) && same(withExt.atOutline, ref.atOutline) && (ref.atOutline || []).includes('alpha'), JSON.stringify([withExt.atOutline, ref.atOutline])); |
| 319 | ok('K7 Cmd+Shift+O opens the same outline', same(withExt.cmdShiftO, ref.cmdShiftO) && (ref.cmdShiftO || []).includes('zeta'), JSON.stringify([withExt.cmdShiftO, ref.cmdShiftO])); |
| 320 | ok('K7 Cmd+S saves, as without extensions', withExt.cmdS === 'saved' && ref.cmdS === 'saved', JSON.stringify([withExt.cmdS, ref.cmdS])); |
| 321 | const ranCount = await page.evaluate(async () => (await import('/js/ext2/bridge.js')).runCommand('hostile.count')); |
| 322 | ok('K7 none of those chords ran hostile’s command (its counter is 0)', ranCount === '0', String(ranCount)); |
| 323 | |
| 324 | // ── K9: privacidad ── |
| 325 | const sbx = [...new Set(srv.requests.filter(r => r.host.startsWith('localhost:')).map(r => r.url.split('?')[0]))]; |
| 326 | ok('K9 the sandbox site was asked only for its two documents', sbx.length > 0 && sbx.every(u => u === '/x2/v1/sandbox.html' || u === '/x2/v1/exthost-iframe.html'), sbx.join(' ')); |
| 327 | ok('K9 beacon: 0 hits', beacon.hits.length === 0, JSON.stringify(beacon.hits.slice(0, 3))); |
| 328 | ok('K9 no page errors', errors.length === 0, errors.slice(0, 3).join(' | ')); |
| 329 | |
| 330 | await ctx.close(); |
| 331 | await browser.close(); |
| 332 | await beacon.close(); |
| 333 | await srv.close(); |
| 334 | console.log(fails ? `\n❌ ${fails} failed` : '\n✅ all passed'); |
| 335 | process.exit(fails ? 1 : 0); |