// Disposable Electron + actual tree/menu modules. All server answers are labelled fixtures at the // preload request boundary. No core process, microphone, user profile, network or live moderation. // Run: node scripts/smoke-client-menu.mjs [--out ] import { _electron as electron } from 'playwright-core'; import assert from 'node:assert/strict'; import { mkdtempSync, mkdirSync, writeFileSync, rmSync, readFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import path from 'node:path'; import { fileURLToPath, pathToFileURL } from 'node:url'; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const args = process.argv.slice(2); const out = path.resolve(root, args.includes('--out') ? args[args.indexOf('--out') + 1] : 'smoke-out/client-menu'); const temporary = mkdtempSync(path.join(tmpdir(), 'teamspeach-client-menu-')); mkdirSync(out, { recursive: true }); const result = { evidence: 'Fixture transport only; does not prove live server permissions.', steps: [], errors: [] }; const record = (name, data = {}) => result.steps.push({ name, ...data }); const url = (relative) => pathToFileURL(path.join(root, relative)).href; const sourceHtml = readFileSync(path.join(root, 'app/renderer/index.html'), 'utf8'); const sprite = sourceHtml.match(//)?.[0] || ''; writeFileSync(path.join(temporary, 'fixture.html'), `Client menu fixture — no live server

Client menu fixture — no live server

${sprite}`); writeFileSync(path.join(temporary, 'main.cjs'), `const {app,BrowserWindow,session}=require('electron');app.setPath('userData',${JSON.stringify(path.join(temporary, 'profile'))});app.whenReady().then(()=>{session.defaultSession.setPermissionRequestHandler((_w,_p,done)=>done(false));session.defaultSession.webRequest.onBeforeRequest({urls:['http://*/*','https://*/*']},(_d,done)=>done({cancel:true}));const w=new BrowserWindow({width:1100,height:850,show:false,focusable:false,webPreferences:{contextIsolation:true,nodeIntegration:false,sandbox:true,offscreen:true,backgroundThrottling:false}});w.webContents.setWindowOpenHandler(()=>({action:'deny'}));w.loadFile(${JSON.stringify(path.join(temporary, 'fixture.html'))});});`); 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 requestCount = () => page.evaluate(() => window.fixture.requests.filter((r) => r.cmd === 'client_action').length); const lastAction = () => page.evaluate(() => window.fixture.requests.filter((r) => r.cmd === 'client_action').at(-1)?.args); const open = async (id = 2) => { await page.click(row(id), { button: 'right' }); await page.waitForSelector('.client-menu:not([aria-busy]) [role^="menuitem"]'); }; const confirm = async () => { await page.click('.client-dialog [data-action="confirm"]'); await page.waitForFunction(() => !document.querySelector('.client-action-form')); }; const closeDialog = () => page.keyboard.press('Escape'); try { const env = { ...process.env }; delete env.ELECTRON_RUN_AS_NODE; app = await electron.launch({ args: [path.join(temporary, 'main.cjs')], env, timeout: 30000 }); page = await app.firstWindow(); page.on('pageerror', (error) => result.errors.push(error.message)); await page.evaluate(async ({ stateUrl, menuUrl, treeUrl }) => { const f = window.fixture = { requests: [], mode: 'admin', delay: 0, failAction: '', privateIds: [], volume: 0, muted: false }; const listeners = new Map(); f.listenerCount = () => [...listeners.values()].reduce((sum, set) => sum + set.size, 0); for (const [target, types] of [[document, ['pointerdown']], [window, ['blur', 'resize']]]) { const add = target.addEventListener.bind(target); const remove = target.removeEventListener.bind(target); target.addEventListener = (type, fn, options) => { if (types.includes(type)) { if (!listeners.has(type)) listeners.set(type, new Set()); listeners.get(type).add(fn); } return add(type, fn, options); }; target.removeEventListener = (type, fn, options) => { if (types.includes(type)) listeners.get(type)?.delete(fn); return remove(type, fn, options); }; } const keys = ['commander', 'poke', 'volume', 'connection_info', 'avatar', 'server_group', 'channel_group', 'client_permissions', 'channel_permissions', 'set_client_permission', 'set_channel_permission', 'kick_channel', 'kick_server', 'ban', 'whisper']; const ok = { allowed: true, reason: 'server_hint', source: 'fixture' }; const denied = { allowed: false, reason: 'permission_denied', source: 'fixture' }; window.teamspeach = { log() {}, chooseAvatar: async () => ({ ok: true, data: 'fixture-png-base64' }), setClientVolume: async (_uid, db) => ({ ok: true, db }), request: async (connectionId, cmd, args) => { f.requests.push({ cmd, args: structuredClone(args) }); const delay = f.delay; const mode = f.mode; if (delay) await new Promise((resolve) => setTimeout(resolve, delay)); if (cmd === 'client_context') return { ok: true, result: { generation: 41, client_id: args.client_id, uid: args.uid, is_self: args.client_id === 1, capabilities: Object.fromEntries(keys.map((key) => [key, mode === 'readonly' && !['connection_info', 'client_permissions', 'channel_permissions', 'volume'].includes(key) ? denied : mode === 'unknown' ? { ...ok, allowed: null } : ok])), server_groups: [{ id: 7, name: 'Fixture operators', member: false, can_add: mode === 'readonly' ? denied : ok, can_remove: ok }], channel_groups: [{ id: 9, name: 'Fixture voice', member: true, can_set: ok }], permissions: [{ id: 101, name: 'fixture_permission', description: 'Fixture permission, not live evidence' }], is_channel_commander: false, volume_db: f.volume, volume_muted: f.muted, } }; if (cmd !== 'client_action') throw new Error(`Unexpected fixture command ${cmd}`); if (args.action === f.failAction) return { ok: false, error: { code: 'ts_error', message: 'Fixture permission revoked', ts_error: 2568 } }; if (args.action === 'volume') { f.volume = args.db; f.muted = args.muted; } if (['connection_info', 'client_permissions', 'channel_permissions'].includes(args.action)) return { ok: true, result: { rows: [{ clid: args.client_id, fixture_value: '', value: 75 }] } }; return { ok: true, result: {} }; }, }; const { S, newConnection } = await import(stateUrl); S.connections.set('c1', newConnection('c1')); S.viewId = 'c1'; f.S = S; S.conn = { state: 'connected', address: 'fixture.invalid', reason: null }; S.prefs = { collapsedChannels: [] }; S.snap = { own_client_id: 1, own_channel_id: 10, server: { name: 'Fixture server' }, server_groups: [], channel_groups: [], channels: [{ id: 10, parent_id: 0, depth: 0, name: 'Fixture channel', codec: 'opus_voice' }], clients: [{ id: 1, uid: 'fixture-self-uid', nickname: 'Fixture self', is_self: true, channel_id: 10, input_hardware: true }, { id: 2, uid: 'fixture-other-uid', nickname: 'Fixture other', is_self: false, channel_id: 10, input_hardware: true }] }; const menu = await import(menuUrl); const tree = await import(treeUrl); f.menu = menu; f.tree = tree; menu.initClientMenu({ onPrivateChat: (_conn, id) => f.privateIds.push(id) }); tree.initTree({ contextClient: menu.openClientMenu, openPrivate: id => f.privateIds.push(id) }); tree.renderTree(); }, { stateUrl: url('app/renderer/js/state.js'), menuUrl: url('app/renderer/js/client-menu.js'), treeUrl: url('app/renderer/js/tree.js') }); await open(1); assert.equal(await page.locator(action('commander')).count(), 1); assert.equal(await page.locator(action('avatar')).count(), 1); assert.equal(await page.locator(action('ban')).count(), 0); await page.screenshot({ path: path.join(out, 'self-fixture.png') }); await page.keyboard.press('Escape'); assert.equal(await page.$eval(row(1), (node) => document.activeElement === node), true); record('self menu differs; Escape restores exact tree row'); await page.focus(row(2)); await page.keyboard.press('Shift+F10'); await page.waitForSelector(action('poke')); assert.equal(await page.locator(action('commander')).count(), 0); await page.keyboard.press('Home'); assert.equal(await page.evaluate(() => document.activeElement.dataset.action), 'poke'); await page.keyboard.press('Enter'); await page.fill('#client-field-message', 'Fixture poke'); await confirm(); assert.deepEqual(await lastAction(), { client_id: 2, uid: 'fixture-other-uid', generation: 41, action: 'poke', message: 'Fixture poke' }); await closeDialog(); record('Shift+F10, arrows, Enter; real poke argument dispatch at fixture boundary'); await page.locator(row(2)).dblclick(); assert.deepEqual(await page.evaluate(() => fixture.privateIds), [2]); record('private chat remains reachable through the actual member-row action'); await open(); await page.click(action('ban')); const beforeCancel = await requestCount(); await page.fill('#client-field-reason', 'Fixture test only'); await closeDialog(); assert.equal(await requestCount(), beforeCancel); await open(); await page.click(action('ban')); assert.match(await page.locator('.client-target').innerText(), /fixture-other-uid/); await page.fill('#client-field-reason', 'Fixture test only'); await page.fill('#client-field-duration', '120'); await confirm(); assert.deepEqual(await lastAction(), { client_id: 2, uid: 'fixture-other-uid', generation: 41, action: 'ban', reason: 'Fixture test only', duration: 120 }); await closeDialog(); record('moderation cancel sends nothing; confirm sends exact UID, reason and seconds'); for (const name of ['kick_channel', 'kick_server']) { await open(); await page.click(action(name)); await page.fill('#client-field-reason', 'Fixture kick'); await confirm(); assert.equal((await lastAction()).action, name); await closeDialog(); } await open(1); await page.click(action('commander')); await confirm(); assert.equal((await lastAction()).enabled, true); await closeDialog(); await open(1); await page.click(action('avatar')); await confirm(); assert.equal((await lastAction()).data, 'fixture-png-base64'); await closeDialog(); record('kick scopes, commander and native avatar result dispatch'); await open(); await page.focus(action('server_group')); await page.keyboard.press('ArrowRight'); await page.waitForSelector('.client-menu-page'); await page.keyboard.press('ArrowDown'); await page.keyboard.press('Enter'); await confirm(); assert.deepEqual(await lastAction(), { client_id: 2, uid: 'fixture-other-uid', generation: 41, action: 'server_group', group_id: 7, enabled: true }); await closeDialog(); await open(); await page.click(action('channel_group')); await page.click('.client-menu-page [role^="menuitem"]:not([data-action="back"])'); await confirm(); assert.equal((await lastAction()).channel_id, 10); await closeDialog(); record('server and channel group submenus dispatch concrete group IDs'); await open(); await page.click(action('client_permissions')); await page.waitForSelector('.client-info-table'); assert.match(await page.locator('.client-info-table').innerText(), /