205 lines
14 KiB
JavaScript
205 lines
14 KiB
JavaScript
// Offscreen shell regression: synthetic core IPC, real renderer, no OS clipboard or physical capture.
|
|
// Requires the shared harness's hidden/offscreen launch path; never run on the interactive desktop.
|
|
import { closeSettings, 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';
|
|
|
|
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/ui-shell'));
|
|
const profile = mkdtempSync(path.join(tmpdir(), 'teamspeach-ui-shell-'));
|
|
mkdirSync(out, { recursive: true });
|
|
const result = { scope: 'Offscreen disposable Electron; synthetic server artwork/state/chat through IPC; renderer Selection/Range and CDP input only, no OS clipboard access or end-to-end clipboard guarantee; no real server/capture or TS6 interoperability claim.', checks: [], screenshots: [], errors: [] };
|
|
let app;
|
|
let page;
|
|
let revision = 0;
|
|
const snapshot = (banner = true, codec = 'opus_voice') => ({
|
|
event: 'snapshot', rev: ++revision, own_client_id: 1, own_channel_id: 10,
|
|
server: { uid: 'c2hlbGwtc2VydmVy', name: 'Shell QA · Сервер', version: 'fixture', welcome_message: '', hostbanner_gfx_url: banner ? 'https://example.invalid/shell-banner' : null, hostbanner_url: null },
|
|
channels: [{ id: 10, parent_id: 0, order: 0, depth: 0, name: 'Lobby · Общение', topic: 'Copyable channel topic', codec, needed_talk_power: 0, has_password: false }],
|
|
clients: [
|
|
{ id: 1, uid: 'c2hlbGwtc2VsZg==', nickname: 'ShellQA', channel_id: 10, is_self: true, input_muted: true, output_muted: true, input_hardware: true, output_hardware: true, server_groups: [] },
|
|
{ id: 2, uid: 'c2hlbGwtcGVlcg==', nickname: 'Mira', channel_id: 10, input_muted: false, output_muted: false, input_hardware: true, output_hardware: true, server_groups: [] },
|
|
], server_groups: [], channel_groups: [],
|
|
});
|
|
const send = (event) => app.evaluate(({ BrowserWindow }, value) => BrowserWindow.getAllWindows()[0].webContents.send('core:event', { ...value, connectionId: 'c1' }), event);
|
|
const resize = (width, height) => app.evaluate(({ BrowserWindow }, size) => BrowserWindow.getAllWindows()[0].setContentSize(...size), [width, height]);
|
|
const check = (name, data = {}) => result.checks.push({ name, ...data });
|
|
const shot = async (name) => { const file = `${name}.png`; await page.screenshot({ path: path.join(out, file) }); result.screenshots.push(file); };
|
|
const dismissToasts = () => page.evaluate(() => document.querySelectorAll('.toast .icon-btn').forEach(button => button.click()));
|
|
const dragText = async (selector) => {
|
|
await page.evaluate(() => getSelection().removeAllRanges());
|
|
const box = await page.locator(selector).first().boundingBox();
|
|
assert.ok(box, `${selector} is visible`);
|
|
await page.mouse.move(box.x + 2, box.y + box.height / 2);
|
|
await page.mouse.down();
|
|
await page.mouse.move(box.x + Math.min(box.width - 2, 230), box.y + box.height / 2, { steps: 15 });
|
|
await page.mouse.up();
|
|
return page.evaluate(() => getSelection().toString());
|
|
};
|
|
try {
|
|
app = await launchApp({ exe: opt('exe'), profile });
|
|
page = await app.firstWindow();
|
|
page.on('pageerror', error => result.errors.push(error.message));
|
|
await page.waitForSelector('#view-onboarding', { state: 'visible', timeout: 30000 });
|
|
await page.evaluate(() => {
|
|
window.__shellCaptureRequests = 0;
|
|
for (const method of ['getUserMedia', 'getDisplayMedia']) navigator.mediaDevices[method] = async () => {
|
|
window.__shellCaptureRequests++;
|
|
throw new DOMException('Physical capture blocked by isolated shell QA', 'NotAllowedError');
|
|
};
|
|
});
|
|
await page.fill('#onboarding-nick', 'ShellQA');
|
|
await page.click('#onboarding-submit');
|
|
await page.waitForSelector('#view-app', { state: 'visible' });
|
|
await page.waitForFunction(() => window.teamspeachDiagnostics?.snapshot().core === 'ready');
|
|
// Only this disposable process replaces its request handler; no request can reach a server.
|
|
await app.evaluate(({ ipcMain }) => {
|
|
globalThis.__shellCommands = [];
|
|
ipcMain.removeHandler('core:request');
|
|
ipcMain.handle('core:request', (_event, connectionId, cmd, args) => {
|
|
globalThis.__shellCommands.push(cmd);
|
|
if (cmd === 'fetch_server_banner') return { ok: true, result: { mime: 'image/svg+xml', data: Buffer.from('<svg xmlns="http://www.w3.org/2000/svg" width="900" height="250"><rect width="900" height="250" fill="#fafafa"/><path d="M0 200L350 0H540L190 250H0ZM580 250L900 0V250Z" fill="#da7548"/><circle cx="690" cy="90" r="90" fill="#709b93"/></svg>').toString('base64') } };
|
|
if (cmd === 'set_transmit') return { ok: true, result: { mode: args.mode, sensitivity: args.sensitivity } };
|
|
if (cmd === 'stream_list') return { ok: true, result: { results: [] } };
|
|
return { ok: false, error: { code: 'not_connected', message: 'Offline shell fixture' } };
|
|
});
|
|
});
|
|
await resize(1280, 800);
|
|
await send({ event: 'audio_state', input_muted: false, output_muted: true, transmitting: false });
|
|
await send(snapshot());
|
|
await page.waitForFunction(() => !document.querySelector('#host-banner').hidden && document.querySelector('#host-banner').naturalWidth > 0);
|
|
await send({ event: 'text', target: 'channel', from_client_id: 2, from_nickname: 'Mira', message: 'Copy this chat message · Можно скопировать https://example.invalid/notes' });
|
|
await page.waitForSelector('#chat-log .msg-body', { state: 'visible' });
|
|
await dismissToasts();
|
|
assert.equal(await page.locator('#transmit-hint').count(), 0);
|
|
assert.equal(await page.isHidden('#session-notice'), true, 'deafen alone no longer inserts the removed notice');
|
|
assert.equal(await page.getAttribute('#btn-deafen', 'aria-pressed'), 'true');
|
|
const safety = await page.evaluate(async () => {
|
|
const voice = await import('./js/voice.js');
|
|
return { forwarding: voice.shouldForward(), actual: voice.isForwarding(), capturing: voice.isCapturing() };
|
|
});
|
|
assert.equal(safety.forwarding, false);
|
|
assert.equal(safety.actual, false);
|
|
assert.equal(safety.capturing, false);
|
|
check('Deafen safety retained without redundant banner', safety);
|
|
|
|
const geometry = await page.evaluate(() => {
|
|
const card = document.querySelector('.server-card');
|
|
const image = document.querySelector('#host-banner');
|
|
const box = element => { const r = element.getBoundingClientRect(); return { x: r.x, y: r.y, width: r.width, height: r.height }; };
|
|
return { card: box(card), image: box(image), inside: image.parentElement === card, overlay: getComputedStyle(card, '::after').backgroundColor, imageAlt: image.alt, backgroundOnly: getComputedStyle(image).pointerEvents };
|
|
});
|
|
assert.equal(geometry.inside, true);
|
|
assert.equal(geometry.backgroundOnly, 'none');
|
|
assert.equal(geometry.imageAlt, '');
|
|
check('Host artwork remains noninteractive behind server controls', geometry);
|
|
const selectedMessage = await dragText('#chat-log .msg-body');
|
|
assert.ok(selectedMessage.length > 4, 'chat message text remains drag-selectable');
|
|
const rangeSelection = await page.evaluate(() => {
|
|
const selection = getSelection();
|
|
const range = selection.getRangeAt(0);
|
|
const message = document.querySelector('#chat-log .msg-body');
|
|
return { count: selection.rangeCount, text: range.toString(), inMessage: message.contains(range.startContainer) && message.contains(range.endContainer), collapsed: range.collapsed };
|
|
});
|
|
assert.equal(rangeSelection.count, 1);
|
|
assert.equal(rangeSelection.text, selectedMessage);
|
|
assert.equal(rangeSelection.inMessage, true);
|
|
assert.equal(rangeSelection.collapsed, false);
|
|
check('Actual chat DOM Range selects text; clipboard intentionally not exercised', rangeSelection);
|
|
await page.fill('#chat-input', 'Keyboard selection remains available');
|
|
await page.focus('#chat-input');
|
|
const cdp = await page.context().newCDPSession(page);
|
|
await cdp.send('Input.dispatchKeyEvent', { type: 'rawKeyDown', key: 'a', code: 'KeyA', windowsVirtualKeyCode: 65, modifiers: 2 });
|
|
await cdp.send('Input.dispatchKeyEvent', { type: 'keyUp', key: 'a', code: 'KeyA', windowsVirtualKeyCode: 65, modifiers: 2 });
|
|
await cdp.detach();
|
|
assert.deepEqual(await page.evaluate(async () => { const editor = (await import('./js/chat.js')).composerEditor(); return { value: editor.value, selected: editor.selectionEnd - editor.selectionStart }; }),
|
|
{ value: 'Keyboard selection remains available', selected: 36 });
|
|
await page.fill('#chat-input', '');
|
|
await page.focus('#servers-toggle');
|
|
await page.keyboard.press('Enter');
|
|
await page.waitForFunction(() => document.querySelector('#servers-toggle').getAttribute('aria-expanded') === 'false');
|
|
await page.keyboard.press('Enter');
|
|
await page.waitForFunction(() => document.querySelector('#servers-toggle').getAttribute('aria-expanded') === 'true');
|
|
check('Inline saved-server heading toggles with keyboard without navigation');
|
|
|
|
await send({ event: 'audio_state', input_muted: true, output_muted: false, transmitting: false });
|
|
await send(snapshot(true, 'speex_narrowband'));
|
|
await page.waitForFunction(() => /Speex|CELT|codec|кодек/i.test(document.querySelector('#session-notice').textContent));
|
|
check('Unsupported-codec notice retained', { text: await page.textContent('#session-notice') });
|
|
await send(snapshot());
|
|
await send({ event: 'audio_state', input_muted: false, output_muted: true, transmitting: false });
|
|
|
|
for (const language of ['en', 'ru']) {
|
|
await page.click('#btn-settings');
|
|
await page.click('#settings-nav [data-panel="appearance"]');
|
|
await page.selectOption('#language-select', language);
|
|
await page.waitForFunction(locale => document.documentElement.lang === locale, language);
|
|
await closeSettings(page);
|
|
for (const theme of ['dark', 'light']) {
|
|
await page.evaluate(value => window.teamspeach.setPrefs({ theme: value }), theme);
|
|
await page.waitForFunction(dark => matchMedia('(prefers-color-scheme: dark)').matches === dark, theme === 'dark');
|
|
for (const [width, height] of [[1280, 800], [880, 560]]) {
|
|
await resize(width, height);
|
|
await dismissToasts();
|
|
await page.waitForTimeout(100);
|
|
const dimensions = await page.evaluate(() => ({ width: innerWidth, height: innerHeight, scrollWidth: document.documentElement.scrollWidth, scrollHeight: document.documentElement.scrollHeight, headerHint: Boolean(document.querySelector('#transmit-hint')), mutedNotice: document.querySelector('#session-notice').hidden }));
|
|
assert.equal(dimensions.scrollWidth, width);
|
|
assert.equal(dimensions.scrollHeight, height);
|
|
assert.equal(dimensions.headerHint, false);
|
|
assert.equal(dimensions.mutedNotice, true);
|
|
await shot(`${language}-${theme}-${width}x${height}`);
|
|
check('Locale/theme/viewport shell', { language, theme, ...dimensions });
|
|
}
|
|
}
|
|
}
|
|
await send(snapshot(false));
|
|
await page.waitForFunction(() => document.querySelector('#host-banner').hidden);
|
|
assert.equal(await page.$eval('#host-banner', image => image.hasAttribute('src')), false);
|
|
const withoutBanner = await page.$eval('.server-card', card => ({ height: card.getBoundingClientRect().height, overlay: getComputedStyle(card, '::after').content }));
|
|
await shot('ru-light-no-banner-880x560');
|
|
check('Absent banner releases its image resource', withoutBanner);
|
|
|
|
// PTT control/key remain real renderer behavior; deafen blocks forwarding throughout.
|
|
await page.click('#btn-settings');
|
|
await page.click('#settings-nav [data-panel="audio"]');
|
|
const pttLabel = await page.evaluate(async () => (await import('./js/i18n.js')).t('settings.audio.ptt'));
|
|
await page.getByRole('switch', { name: pttLabel, exact: false }).check();
|
|
await closeSettings(page);
|
|
await page.waitForSelector('#btn-ptt', { state: 'visible' });
|
|
await page.focus('#btn-ptt');
|
|
await page.keyboard.down('F8');
|
|
assert.equal(await page.getAttribute('#btn-ptt', 'aria-pressed'), 'true');
|
|
await page.keyboard.up('F8');
|
|
assert.equal(await page.getAttribute('#btn-ptt', 'aria-pressed'), 'false');
|
|
check('PTT button/settings/F8 retained with no transmission hint');
|
|
await page.click('#btn-settings');
|
|
await page.click('#settings-nav [data-panel="audio"]');
|
|
await page.getByRole('switch', { name: pttLabel, exact: false }).uncheck();
|
|
const vadLabel = await page.evaluate(async () => (await import('./js/i18n.js')).t('settings.audio.vad.title'));
|
|
await page.getByRole('switch', { name: vadLabel, exact: false }).uncheck();
|
|
await closeSettings(page);
|
|
assert.equal(await page.isHidden('#btn-ptt'), true);
|
|
assert.equal(await page.locator('#transmit-hint').count(), 0);
|
|
assert.equal(await page.evaluate(async () => (await import('./js/voice.js')).shouldForward()), false);
|
|
check('Open microphone mode has no header hint and deafen still blocks transmission');
|
|
assert.deepEqual(result.errors, []);
|
|
result.captureRequestsBlocked = await page.evaluate(() => window.__shellCaptureRequests);
|
|
result.commands = await app.evaluate(() => globalThis.__shellCommands);
|
|
assert.equal(result.commands.includes('connect'), false);
|
|
assert.equal(result.commands.includes('voice_send'), false);
|
|
result.ok = true;
|
|
} catch (error) {
|
|
result.ok = false;
|
|
result.errors.push(error.stack || String(error));
|
|
if (page) await page.screenshot({ path: path.join(out, 'failure.png') }).catch(() => {});
|
|
process.exitCode = 1;
|
|
} 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({ ok: result.ok, out, errors: result.errors }, null, 2));
|