// Real application shell/preload and production request validation; only the main->core transport is // replaced with labelled deterministic fixtures. No live server, microphone, private media or moderation. // node scripts/smoke-shell-behavior-offscreen.mjs --out [--baseline] [--exe ] import { launchApp } from './lib/electron-app.mjs'; import assert from 'node:assert/strict'; import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import path from 'node:path'; // launchApp enforces an offscreen, nonfocusable window and rejects packages without that safety code. const args = process.argv.slice(2); const opt = (key, fallback) => args.includes(`--${key}`) ? args[args.indexOf(`--${key}`) + 1] : fallback; const out = path.resolve(opt('out', 'smoke-out/shell-behavior')); const profile = mkdtempSync(path.join(tmpdir(), 'teamspeach-shell-behavior-')); mkdirSync(out, { recursive: true }); const result = { evidence: 'Real application shell + preload + production validateRequest, fixture main/core transport only. No live permission proof.', steps: [], errors: [] }; const record = (name, details = {}) => result.steps.push({ name, ...details }); let app; let page; const row = (id) => `.member-row[data-clid="${id}"] .row-btn`; const action = (name) => `.client-menu:not(.client-submenu) [data-action="${name}"]`; const close = () => page.keyboard.press('Escape'); try { app = await launchApp({ exe: opt('exe'), profile, env: { TEAMSPEACH_DEVTOOLS: '1' } }); page = await app.firstWindow(); page.on('pageerror', (error) => result.errors.push(error.message)); await app.evaluate(({ session }) => { session.defaultSession.setPermissionRequestHandler((_w, _p, done) => done(false)); session.defaultSession.setPermissionCheckHandler(() => false); }); await page.evaluate(() => { navigator.mediaDevices.getUserMedia = async () => { throw new DOMException('Client menu fixture never captures audio', 'NotAllowedError'); }; }); await page.waitForSelector('#view-onboarding', { state: 'visible', timeout: 30000 }); await page.fill('#onboarding-nick', 'MenuFixture'); await page.click('#onboarding-submit'); await page.waitForSelector('#view-app', { state: 'visible' }); const install = await app.evaluate(({ app, ipcMain, BrowserWindow, session }) => { const require = process.mainModule.require.bind(process.mainModule); const { validateRequest } = require(`${app.getAppPath()}/app/main/ipc-validate.js`); const win = BrowserWindow.getAllWindows().find((w) => !w.isDevToolsOpened()) || BrowserWindow.getAllWindows()[0]; const f = globalThis.__menuFixture = { requests: [], rejected: [], mode: 'admin', delay: 0, failAction: '', volume: 0, muted: false, audioFrames: 0 }; const permission = (allowed) => ({ allowed, reason: allowed === false ? 'permission_denied' : allowed === null ? 'server_decides' : 'server_hint', source: 'fixture' }); const keys = ['commander','avatar','poke','volume','connection_info','server_group','channel_group','client_permissions','channel_permissions','set_client_permission','set_channel_permission','kick_channel','kick_server','ban']; ipcMain.removeHandler('core:request'); ipcMain.handle('core:request', async (event, connectionId, cmd, args) => { if (event.sender !== win.webContents) return { ok: false, error: { code: 'forbidden', message: 'fixture sender rejected' } }; let clean; try { clean = validateRequest(cmd, args); } catch (error) { f.rejected.push({ cmd, code: error.code, message: error.message }); return { ok: false, error: { code: error.code || 'bad_request', message: error.message } }; } f.requests.push({ cmd, args: structuredClone(clean) }); const delay = f.delay; if (delay) await new Promise((resolve) => setTimeout(resolve, delay)); if (cmd === 'client_context') return { ok: true, result: { client_id: clean.client_id, uid: clean.uid, generation: 73, is_self: clean.client_id === 1, capabilities: Object.fromEntries(keys.map((key) => [key, permission(f.mode === 'readonly' && !['connection_info','client_permissions','channel_permissions','volume'].includes(key) ? false : f.mode === 'unknown' ? null : true)])), server_groups: [{ id: 7, name: 'Fixture operators', member: false, can_add: permission(f.mode !== 'readonly'), can_remove: permission(true) }], channel_groups: [{ id: 9, name: 'Fixture voice', member: true, can_set: permission(true) }], permissions: [{ id: 101, name: 'fixture_permission', description: 'Fixture only — not live server permission' }], is_channel_commander: false, volume_db: f.volume, volume_muted: f.muted, } }; if (cmd === 'client_action') { if (clean.action === f.failAction) return { ok: false, error: { code: 'ts_error', message: 'Fixture permission revoked', ts_error: 2568 } }; if (clean.action === 'volume') { f.volume = clean.db; f.muted = clean.muted; } return { ok: true, result: ['connection_info','client_permissions','channel_permissions'].includes(clean.action) ? { rows: [{ clid: clean.client_id, fixture: 'Read-only fixture data', value: 75 }] } : {} }; } if (cmd === 'set_transmit') return { ok: true, result: clean }; return { ok: false, error: { code: 'not_connected', message: 'Fixture blocks all unrelated commands; no live core dispatch' } }; }); // Even an accidental capture callback cannot leave the fixture boundary. ipcMain.removeAllListeners('core:audio-frame'); ipcMain.on('core:audio-frame', () => { f.audioFrames++; }); session.defaultSession.webRequest.onBeforeRequest({ urls: ['http://*/*', 'https://*/*'] }, (_details, done) => done({ cancel: true })); f.snapshot = { event: 'snapshot', own_client_id: 1, own_channel_id: 10, server: { name: 'Fixture server — no live permissions', version: 'fixture', welcome_message: '' }, server_groups: [], channel_groups: [], channels: [{ id: 10, parent_id: 0, depth: 0, name: 'Fixture channel', codec: 'opus_voice', max_clients: -1 }], clients: [{ id: 1, uid: 'fixture-self-uid', nickname: 'Fixture self', is_self: true, channel_id: 10, input_hardware: true, input_muted: true, output_muted: true }, { id: 2, uid: 'fixture-other-uid', nickname: 'Fixture other', is_self: false, channel_id: 10, input_hardware: true }], }; f.send = (event) => win.webContents.send('core:event', { ...event, connectionId: 'c1' }); f.send({ event: 'audio_state', input_muted: true, output_muted: true, transmitting: false }); f.send({ event: 'state', state: 'connected', address: 'fixture.invalid', reason: null }); f.send(f.snapshot); return { appPath: app.getAppPath(), version: app.getVersion(), packaged: app.isPackaged }; }); result.application = install; const fixtureRows = [{ clid: '2', connection_client_ip: '2001:db8:1234:5678:90ab:cdef:1234:5678', connection_client_port: '9987', connection_ping: '12.5', connection_ping_deviation: '1.25', connection_connected_time: '123456', connection_idle_time: '1000', connection_packetloss_total: '0.025', future_server_metric: '&fixture', absent_metric: null }]; for (const direction of ['sent', 'received']) for (const kind of ['speech', 'keepalive', 'control', 'total']) { fixtureRows[0]['connection_packets_' + direction + '_' + kind] = '123'; fixtureRows[0]['connection_bytes_' + direction + '_' + kind] = '9007199254740993'; fixtureRows[0]['connection_bandwidth_' + direction + '_last_minute_' + kind] = '2048'; fixtureRows[0]['connection_bandwidth_' + direction + '_last_second_' + kind] = '1024'; } fixtureRows.push({ clid: '2', connection_ping: null, second_record_only: 'second record preserved' }); await app.evaluate(({ ipcMain }, rows) => { const original = ipcMain._invokeHandlers.get('core:request'); ipcMain.removeHandler('core:request'); ipcMain.handle('core:request', async (event, connectionId, cmd, args) => { const response = await original(event, connectionId, cmd, args); if (response.ok && cmd === 'client_action' && args.action === 'connection_info') response.result = { rows }; return response; }); }, fixtureRows); await page.setViewportSize({ width: 1000, height: 820 }); await page.waitForSelector(row(2)); // Real tree contextmenu event at exact CSS viewport coordinates, including a narrow right edge. const pointer = { x: 850, y: 110 }; const bounds = await page.locator(row(2)).evaluate((node, p) => new Promise(resolve => { const observer = new MutationObserver(() => { const menu = document.querySelector('.client-menu:not([aria-busy])'); if (!menu?.querySelector('[data-action="connection_info"]')) return; observer.disconnect(); const rect = menu.getBoundingClientRect(); const result = { x: rect.x, y: rect.y, width: rect.width, height: rect.height }; menu.querySelector('[data-action="connection_info"]').click(); resolve(result); }); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['aria-busy'] }); node.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, cancelable: true, clientX: p.x, clientY: p.y, button: 2 })); }), pointer); record('pointer flips beside click rather than arbitrary viewport slide', { pointer, bounds, pass: Math.abs(bounds.x + bounds.width - pointer.x) <= 2 }); await page.waitForSelector('.client-menu-info .connection-record'); const info = await page.evaluate(() => ({ fields: document.querySelectorAll('.connection-field').length, records: document.querySelectorAll('.connection-record').length, columns: document.querySelectorAll('.client-info-table thead th').length, content: document.querySelector('.client-menu-info').textContent, width: document.querySelector('.client-menu-info').clientWidth, scroll: document.querySelector('.client-menu-info').scrollWidth })); record('42-field first record and second record remain vertical and selectable', { ...info, pass: info.fields === Object.keys(fixtureRows[0]).length + Object.keys(fixtureRows[1]).length && info.records === 2 && info.columns === 0 && info.scroll <= info.width + 1 }); if (!args.includes('--baseline')) { assert.ok(result.steps.every(step => step.pass !== false)); assert.match(info.content, /2[.,]5\s?%/); assert.match(info.content, /second record preserved/); assert.match(info.content, /9[\s,.]?007[\s,.]?199[\s,.]?254[\s,.]?740[\s,.]?993/); const selection = await page.evaluate(() => { const value = document.querySelector('[data-field="connection_client_ip"] dd'); const range = document.createRange(); range.selectNodeContents(value); const selected = getSelection(); selected.removeAllRanges(); selected.addRange(range); const raw = document.querySelector('.connection-raw'); raw.open = true; return { text: selected.toString(), userSelect: getComputedStyle(value).userSelect, rows: JSON.parse(raw.querySelector('pre').textContent) }; }); assert.equal(selection.text, fixtureRows[0].connection_client_ip); assert.equal(selection.userSelect, 'text'); assert.deepEqual(selection.rows, fixtureRows); await close(); const saved = page.locator('#servers-toggle'); assert.equal(await saved.getAttribute('aria-expanded'), 'true'); const before = await app.evaluate(() => __menuFixture.requests.filter(r => ['connect', 'disconnect', 'client_action'].includes(r.cmd)).length); await saved.click(); assert.equal(await saved.getAttribute('aria-expanded'), 'false'); assert.equal(await page.locator('#servers-content').isVisible(), false); await saved.focus(); await page.keyboard.press('Space'); assert.equal(await saved.getAttribute('aria-expanded'), 'true'); assert.equal(await app.evaluate(() => __menuFixture.requests.filter(r => ['connect', 'disconnect', 'client_action'].includes(r.cmd)).length), before); record('saved heading pointer and keyboard toggle without connection commands', { pass: true }); await page.locator(row(2)).focus(); await page.keyboard.press('Shift+F10'); await page.waitForSelector(action('poke')); const keyboard = await page.evaluate(() => { const r = document.querySelector('.member-row[data-clid="2"] .row-btn').getBoundingClientRect(); const m = document.querySelector('.client-menu').getBoundingClientRect(); return { left: r.left, menuLeft: m.left, top: m.top, bottom: m.bottom, height: innerHeight }; }); assert.ok(Math.abs(keyboard.left - keyboard.menuLeft) <= 1); assert.ok(keyboard.top >= 8 && keyboard.bottom <= keyboard.height - 7); await page.setViewportSize({ width: 740, height: 540 }); await page.waitForSelector(action('poke')); await page.waitForFunction(() => { const r = document.querySelector('.client-menu')?.getBoundingClientRect(); return r && r.x >= 8 && r.right <= innerWidth - 7 && r.bottom <= innerHeight - 7; }); const resized = await page.locator('.client-menu').boundingBox(); assert.ok(resized.x >= 8 && resized.x + resized.width <= 733 && resized.y + resized.height <= 533); await page.click(action('volume')); await page.waitForSelector('#client-volume-slider'); const sub = await page.locator('.client-menu-page').boundingBox(); assert.ok(sub.x >= 8 && sub.x + sub.width <= 733 && sub.y + sub.height <= 533); record('keyboard row anchor survives resize and submenu remains in viewport', { keyboard, resized, sub, pass: true }); await close(); await close(); await app.evaluate(() => { for (let id = 3; id <= 32; id++) __menuFixture.snapshot.clients.push({ id, uid: 'fixture-' + id, nickname: 'Fixture member ' + id, channel_id: 10, input_hardware: true }); __menuFixture.send(__menuFixture.snapshot); }); await page.locator(row(32)).scrollIntoViewIfNeeded(); for (const zoom of [1, 1.25]) { await app.evaluate(({ BrowserWindow }, factor) => BrowserWindow.getAllWindows()[0].webContents.setZoomFactor(factor), zoom); await page.locator(row(32)).scrollIntoViewIfNeeded(); const target = await page.locator(row(32)).boundingBox(); const click = { x: target.x + 42, y: target.y + target.height / 2 }; await page.locator(row(32)).click({ button: 'right', position: { x: 42, y: target.height / 2 } }); await page.waitForSelector(action('poke')); const placed = await page.evaluate(() => { const m = document.querySelector('.client-menu').getBoundingClientRect(); return { x: m.x, y: m.y, right: m.right, bottom: m.bottom, width: innerWidth, height: innerHeight, dpr: devicePixelRatio, scroll: document.querySelector('#tree').scrollTop }; }); assert.ok(placed.scroll > 0); assert.ok(Math.abs(placed.x - click.x) < 2, 'pointer stays at actual scrolled-row click, not row left'); assert.ok(placed.y >= 8 && placed.right <= placed.width - 7 && placed.bottom <= placed.height - 7, 'menu fits viewport; integrated pane caption is not an extra top strip'); const beforeSubmenu = await page.locator('.client-menu').boundingBox(); await page.locator(action('volume')).click(); await page.waitForSelector('#client-volume-slider'); const afterSubmenu = await page.locator('.client-menu:not(.client-submenu)').boundingBox(); assert.equal(afterSubmenu.x, beforeSubmenu.x, 'root page keeps the same horizontal anchor'); assert.equal(await page.locator('.client-menu').count(), 1, 'submenu replaces the root instead of opening a flyout'); await page.click('.client-menu-page [data-action="back"]'); assert.equal(await page.locator('.client-menu-page').count(), 0, 'Back restores the root page'); assert.equal(await page.evaluate(() => document.activeElement?.dataset.action), 'volume', 'Back restores parent-item keyboard focus'); await close(); await close(); record('actual scrolled row pointer and stable submenu at zoom ' + zoom, { click, placed, pass: true }); } await app.evaluate(({ BrowserWindow }) => BrowserWindow.getAllWindows()[0].webContents.setZoomFactor(1)); } assert.equal(await app.evaluate(() => __menuFixture.audioFrames), 0); assert.deepEqual(result.errors, []); result.ok = result.steps.every(step => step.pass !== false); } catch (error) { result.ok = false; result.failure = error.stack || String(error); } finally { if (app) await app.close().catch(() => {}); rmSync(profile, { recursive: true, force: true }); writeFileSync(path.join(out, 'result.json'), JSON.stringify(result, null, 2)); } console.log(JSON.stringify(result, null, 2)); process.exitCode = result.ok || args.includes('--baseline') ? 0 : 1;