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.
262 lines
18 KiB
JavaScript
262 lines
18 KiB
JavaScript
// 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 <directory>]
|
|
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(/<svg\b[\s\S]*?<\/svg>/)?.[0] || '';
|
|
writeFileSync(path.join(temporary, 'fixture.html'), `<!doctype html><html><head><meta charset="utf-8"><link rel="stylesheet" href="${url('app/renderer/styles/app.css')}"><title>Client menu fixture — no live server</title></head><body style="display:block;padding:24px"><h1>Client menu fixture — no live server</h1><p id="tree-empty"></p><ul id="tree" style="width:330px"></ul><button id="outside">Outside</button>${sprite}</body></html>`);
|
|
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: '<script>not executable</script>', 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(), /<script>not executable<\/script>/);
|
|
assert.equal(await page.locator('.client-info-table script').count(), 0);
|
|
await page.click('.client-dialog-footer button:first-child');
|
|
await page.fill('#client-field-value', '42'); await page.check('#client-field-skip'); await confirm();
|
|
assert.deepEqual(await lastAction(), { client_id: 2, uid: 'fixture-other-uid', generation: 41, action: 'set_client_permission', permission_id: 101, value: 42, skip: true });
|
|
await closeDialog();
|
|
record('safe selectable read rows and explicit client permission payload');
|
|
|
|
await page.evaluate(() => { fixture.mode = 'readonly'; });
|
|
await open();
|
|
assert.equal(await page.locator(action('ban')).getAttribute('aria-disabled'), 'true');
|
|
assert.equal(await page.locator(action('connection_info')).getAttribute('aria-disabled'), 'false');
|
|
await page.screenshot({ path: path.join(out, '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 closeDialog(); record('read-only fixture capability visibility; no live permission claim');
|
|
|
|
await page.evaluate(() => { fixture.mode = 'unknown'; fixture.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 closeDialog(); await page.evaluate(() => { fixture.mode = 'admin'; fixture.failAction = ''; });
|
|
record('unknown capability remains server checked; rejection visible and retry enabled');
|
|
|
|
await open(); await page.click(action('volume'));
|
|
await page.focus('#client-volume-slider');
|
|
await page.keyboard.press('End');
|
|
await page.waitForFunction(() => fixture.volume === 10);
|
|
await page.click('.client-menu-page [role="menuitemcheckbox"]');
|
|
await page.waitForFunction(() => fixture.muted);
|
|
assert.equal(await page.inputValue('#client-volume-slider'), '100');
|
|
await page.click('.client-menu-page [role="menuitemcheckbox"]');
|
|
await page.waitForFunction(() => !fixture.muted);
|
|
assert.equal(await page.evaluate(() => fixture.volume), 10);
|
|
await page.locator('.client-menu-page [data-action="volume"]').last().click();
|
|
await page.waitForFunction(() => fixture.volume === 0 && !fixture.muted);
|
|
await page.screenshot({ path: path.join(out, 'volume-fixture.png') });
|
|
await page.keyboard.press('Escape'); await page.keyboard.press('Escape');
|
|
record('volume slider, mute-preserve, unmute, reset exact backend fields');
|
|
|
|
await open(); await page.click(action('ban'));
|
|
await page.evaluate(() => { fixture.S.snap.clients[1].uid = 'reused-id-new-uid'; fixture.menu.syncClientMenu(); });
|
|
assert.equal(await page.locator('.client-dialog').count(), 0);
|
|
const staleCount = await requestCount();
|
|
await page.evaluate(() => { fixture.S.snap.clients[1].uid = 'fixture-other-uid'; fixture.delay = 150; });
|
|
await page.click(row(2), { button: 'right' });
|
|
await page.click(row(1), { button: 'right' });
|
|
await page.waitForSelector(action('commander'));
|
|
assert.equal(await page.locator('.client-menu').count(), 1);
|
|
assert.equal(await page.locator('.client-menu-title').innerText(), 'Fixture self');
|
|
await page.keyboard.press('Escape');
|
|
await page.click(row(2), { button: 'right' });
|
|
await page.keyboard.press('Escape');
|
|
await page.waitForTimeout(200);
|
|
assert.equal(await page.locator('.client-menu').count(), 0);
|
|
assert.equal(await requestCount(), staleCount);
|
|
await page.evaluate(() => { fixture.delay = 0; });
|
|
record('UID reuse closes dialog; pending context target switch/close cannot reopen');
|
|
await open(); await page.click(action('kick_channel'));
|
|
await page.evaluate(() => { fixture.delay = 150; });
|
|
await page.click('[data-action="confirm"]');
|
|
await closeDialog();
|
|
await page.evaluate(() => { fixture.delay = 0; });
|
|
await open(1);
|
|
await page.waitForTimeout(200);
|
|
assert.equal(await page.locator('.client-menu-title').innerText(), 'Fixture self');
|
|
assert.equal(await page.locator('.client-dialog').count(), 0);
|
|
await page.keyboard.press('Escape');
|
|
await open();
|
|
await page.evaluate(() => { fixture.S.snap.clients.pop(); fixture.menu.syncClientMenu(); });
|
|
assert.equal(await page.locator('.client-menu').count(), 0);
|
|
await page.evaluate(() => { fixture.S.snap.clients.push({ id: 2, uid: 'fixture-other-uid', nickname: 'Fixture other', is_self: false, channel_id: 10, input_hardware: true }); fixture.tree.renderTree(); });
|
|
record('pending action cannot change replacement target UI; client departure closes menu');
|
|
|
|
await open();
|
|
await page.evaluate(() => { fixture.S.conn.state = 'disconnected'; fixture.menu.syncClientMenu(); });
|
|
assert.equal(await page.locator('.client-menu').count(), 0);
|
|
await page.evaluate(() => { fixture.S.conn.state = 'connected'; });
|
|
await page.setViewportSize({ width: 520, height: 520 });
|
|
await page.evaluate(() => { document.querySelector('#tree').style.marginTop = '250px'; });
|
|
await open();
|
|
assert.equal(await page.$eval('.client-menu', (node) => { const r = node.getBoundingClientRect(); return r.left >= 0 && r.top >= 0 && r.right <= innerWidth && r.bottom <= innerHeight; }), true);
|
|
await page.screenshot({ path: path.join(out, 'bounded-fixture.png') });
|
|
await page.keyboard.press('Escape');
|
|
for (let i = 0; i < 20; i++) { await open(); await page.keyboard.press('Escape'); }
|
|
assert.equal(await page.locator('.client-menu,.client-dialog').count(), 0);
|
|
assert.equal(await page.evaluate(() => fixture.listenerCount()), 0);
|
|
record('disconnect cleanup, viewport clamp and repeated lifecycle cleanup');
|
|
assert.deepEqual(result.errors, []);
|
|
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(temporary, { 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;
|