Preserve accumulated client implementation since v0.1.4, including local identities, multi-server state, chat, administration, audio and streaming controls. Refine official-source layout, original artwork, responsive composer overflow, settings navigation and chat scroll anchoring. Current verification: Node suite passes; isolated packaged chat and responsive control smokes pass without device capture. Native core is reused, not rebuilt in this pass. Strict whole-screen visual parity remains incomplete; no 1:1 or cross-platform acceptance claim. Local checkpoint only; no release or push.
187 lines
15 KiB
JavaScript
187 lines
15 KiB
JavaScript
// 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-client-menu-shell.mjs --out <directory> [--exe <unpacked-or-installed-executable>]
|
|
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/client-menu-shell'));
|
|
const profile = mkdtempSync(path.join(tmpdir(), 'teamspeach-client-shell-'));
|
|
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 open = async (id = 2) => { await page.click(row(id), { button: 'right' }); await page.waitForSelector('.client-menu:not([aria-busy]) [role^="menuitem"]'); };
|
|
const configure = (fields) => app.evaluate((_electron, values) => Object.assign(globalThis.__menuFixture, values), fields);
|
|
const last = () => app.evaluate(() => globalThis.__menuFixture.requests.filter((r) => r.cmd === 'client_action').at(-1)?.args);
|
|
const count = () => app.evaluate(() => globalThis.__menuFixture.requests.filter((r) => r.cmd === 'client_action').length);
|
|
const confirm = async () => { await page.click('.client-dialog [data-action="confirm"]'); await page.waitForFunction(() => !document.querySelector('.client-action-form')); };
|
|
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;
|
|
await page.waitForSelector(row(2));
|
|
const invalid = await page.evaluate(() => window.teamspeach.request('c1', 'client_action', { client_id: 2, uid: 'fixture-other-uid', generation: 73, action: 'volume', db: 10.5, muted: false }));
|
|
assert.equal(invalid.ok, false);
|
|
assert.equal(await app.evaluate(() => __menuFixture.rejected.length), 1);
|
|
record('real preload reaches shipped validateRequest; out-of-range gain rejected before fake core');
|
|
|
|
await open(1);
|
|
assert.equal(await page.locator(action('commander')).count(), 1);
|
|
assert.equal(await page.locator(action('ban')).count(), 0);
|
|
await page.screenshot({ path: path.join(out, 'shell-self-fixture.png') });
|
|
await close();
|
|
await page.focus(row(2)); await page.keyboard.press('Shift+F10'); await page.waitForSelector(action('poke'));
|
|
await page.keyboard.press('Home'); await page.keyboard.press('Enter');
|
|
await page.fill('#client-field-message', 'Fixture poke'); await confirm();
|
|
assert.deepEqual(await last(), { client_id: 2, uid: 'fixture-other-uid', generation: 73, action: 'poke', message: 'Fixture poke' });
|
|
await close(); record('real tree hooks: self vs other, ShiftF10/Home/Enter, validated poke');
|
|
|
|
await open(); await page.click(action('ban'));
|
|
const before = await count(); await close(); assert.equal(await count(), before);
|
|
await open(); await page.click(action('ban'));
|
|
await page.fill('#client-field-reason', 'Fixture moderation only'); await page.fill('#client-field-duration', '120'); await confirm();
|
|
assert.deepEqual(await last(), { client_id: 2, uid: 'fixture-other-uid', generation: 73, action: 'ban', reason: 'Fixture moderation only', duration: 120 });
|
|
await close(); record('real app moderation cancel and exact confirmed arguments; no server dispatch');
|
|
|
|
await open(); await page.click(action('server_group')); await page.click('.client-menu-page [role^="menuitem"]:not([data-action="back"])'); await confirm();
|
|
assert.equal((await last()).group_id, 7); await close();
|
|
await open(); await page.click(action('channel_permissions')); await page.waitForSelector('.client-info-table');
|
|
await page.click('.client-dialog-footer button:first-child'); await page.check('#client-field-removePermission'); await confirm();
|
|
assert.deepEqual(await last(), { client_id: 2, uid: 'fixture-other-uid', generation: 73, action: 'set_channel_permission', channel_id: 10, permission_id: 101, value: null });
|
|
await close(); record('real app group and channel permission read/remove validated payload');
|
|
|
|
await configure({ mode: 'readonly' }); await open();
|
|
assert.equal(await page.locator(action('kick_server')).getAttribute('aria-disabled'), 'true');
|
|
await page.screenshot({ path: path.join(out, 'shell-readonly-fixture.png') });
|
|
await page.click(action('client_permissions')); await page.waitForSelector('.client-info-table');
|
|
assert.equal(await page.locator('.client-dialog-footer button').count(), 1); await close();
|
|
await configure({ mode: 'unknown', failAction: 'kick_server' }); await open(); await page.click(action('kick_server'));
|
|
await page.click('[data-action="confirm"]'); await page.waitForSelector('.client-dialog-status[role="alert"]');
|
|
assert.equal(await page.locator('[data-action="confirm"]').isEnabled(), true); await close();
|
|
await configure({ mode: 'admin', failAction: '' }); record('read-only and unknown/rejected capability scenarios through production shell');
|
|
|
|
await open(); await page.click(action('volume')); await page.focus('#client-volume-slider'); await page.keyboard.press('End');
|
|
await page.waitForFunction(() => document.querySelector('#client-volume-slider')?.value === '100');
|
|
await page.click('.client-menu-page [role="menuitemcheckbox"]');
|
|
await page.waitForFunction(() => document.querySelector('.client-menu-page [role="menuitemcheckbox"]')?.getAttribute('aria-checked') === 'true');
|
|
assert.equal(await page.inputValue('#client-volume-slider'), '100');
|
|
await page.click('.client-menu-page [role="menuitemcheckbox"]');
|
|
await page.waitForFunction(() => document.querySelector('.client-menu-page [role="menuitemcheckbox"]')?.getAttribute('aria-checked') === 'false');
|
|
assert.equal(await page.inputValue('#client-volume-slider'), '100');
|
|
await page.locator('.client-menu-page [data-action="volume"]').last().click();
|
|
await page.waitForFunction(() => document.querySelector('#client-volume-slider')?.value === '76');
|
|
await page.screenshot({ path: path.join(out, 'shell-volume-fixture.png') });
|
|
// Drain the renderer's coalesced action before asserting main state.
|
|
await page.evaluate(async () => { await new Promise((resolve) => setTimeout(resolve, 100)); });
|
|
assert.deepEqual(await app.evaluate(() => ({ db: __menuFixture.volume, muted: __menuFixture.muted })), { db: 0, muted: false });
|
|
await close(); await close(); record('native slider/mute/unmute/reset reaches validated gain transport');
|
|
|
|
await open(); await page.click(action('ban'));
|
|
await app.evaluate(() => { __menuFixture.snapshot.clients[1].uid = 'reused-other-uid'; __menuFixture.send(__menuFixture.snapshot); });
|
|
await page.waitForSelector('.client-dialog', { state: 'detached' });
|
|
await app.evaluate(() => { __menuFixture.snapshot.clients[1].uid = 'fixture-other-uid'; __menuFixture.send(__menuFixture.snapshot); });
|
|
// A distinct connection to the same server and identical generation must still invalidate menus.
|
|
const second = await page.evaluate(() => window.teamspeach.createConnection());
|
|
assert.equal(second.ok, true);
|
|
await page.waitForFunction(id => window.teamspeachDiagnostics.snapshot().connections.some(conn => conn.id === id && conn.core === 'ready'), second.connection.id);
|
|
await app.evaluate(({ BrowserWindow }, id) => {
|
|
const wc = BrowserWindow.getAllWindows()[0].webContents;
|
|
wc.send('core:event', { event: 'state', state: 'connected', address: 'fixture.invalid', connectionId: id });
|
|
wc.send('core:event', { ...__menuFixture.snapshot, connectionId: id });
|
|
}, second.connection.id);
|
|
await open(); await page.click(action('ban'));
|
|
const beforeSwitch = await count();
|
|
await page.evaluate(id => document.querySelector(`[data-connection-id="${id}"] .connection-item`).click(), second.connection.id);
|
|
await page.waitForSelector('.client-dialog', { state: 'detached' });
|
|
assert.equal(await count(), beforeSwitch, 'switch cannot dispatch pending destructive action');
|
|
await page.evaluate(() => document.querySelector('[data-connection-id="c1"] .connection-item').click());
|
|
assert.equal((await page.evaluate(id => window.teamspeach.closeConnection(id), second.connection.id)).ok, true);
|
|
record('same-server same-generation second native connection invalidates the first connection action dialog');
|
|
await open();
|
|
await app.evaluate(() => __menuFixture.send({ event: 'state', state: 'disconnected', address: '', reason: 'Fixture disconnect' }));
|
|
await page.waitForSelector('.client-menu', { state: 'detached' });
|
|
assert.equal(await app.evaluate(() => __menuFixture.audioFrames), 0);
|
|
record('actual onSnapshot UID-reuse invalidation and resetConnection menu cleanup; zero audio frames');
|
|
assert.deepEqual(result.errors, []);
|
|
result.transport = await app.evaluate(() => ({ requests: __menuFixture.requests, rejected: __menuFixture.rejected }));
|
|
result.ok = true;
|
|
} catch (error) {
|
|
result.ok = false; result.failure = error.stack || String(error);
|
|
if (page) await page.screenshot({ path: path.join(out, 'failure.png') }).catch(() => {});
|
|
} 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 ? 0 : 1;
|