import assert from 'node:assert/strict'; import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'node:fs'; import { tmpdir } from 'node:os'; import path from 'node:path'; import { launchApp, waitForAsync } from './lib/electron-app.mjs'; const args = process.argv.slice(2); const option = key => args.includes(`--${key}`) ? args[args.indexOf(`--${key}`) + 1] : undefined; const out = path.resolve(option('out') ?? 'smoke-out/whisper-offscreen'); const profile = mkdtempSync(path.join(tmpdir(), 'teamspeach-whisper-qa-')); mkdirSync(out, { recursive: true }); const result = { scope: 'Real isolated local whisper/keybind persistence + native disconnected rejection; no global hooks, server, capture, or audible output', checks: [], errors: [] }; let app, page; try { app = await launchApp({ profile, exe: option('exe') }); page = await app.firstWindow(); page.on('pageerror', e => result.errors.push(e.message)); await page.waitForSelector('#view-onboarding', { state: 'visible' }); await page.fill('#onboarding-nick', 'Whisper QA'); await page.click('#onboarding-submit'); await page.waitForSelector('#view-app', { state: 'visible' }); await page.click('#btn-settings'); await page.click('#settings-nav [data-panel="whispers"]'); // Official manage-whisper-lists: "+" turns the Whisperlist cell into the "New Whisper List Name" editor (Enter commits). await page.locator('#whisper-settings .tsv-whisper-entry-row .is-constructive').click(); await page.locator('#whisper-settings .ts-whisper-list-cell .ts-input').fill('Isolated local list'); await page.keyboard.press('Enter'); await page.waitForFunction(() => document.querySelector('#whisper-settings .ts-whisper-list-cell .tsv-item-text')?.textContent === 'Isolated local list'); // Live Preview starts on; without a connected server there is no input connection, so no "Switch to Server and // Overlay" and no preview highlight anywhere; the status bar history button stays hidden (no received whisper). assert.equal(await page.locator('#whisper-settings .tsv-whisper-list-card input[role="switch"]').isChecked(), true); assert.equal(await page.locator('#whisper-settings .switch-to-overlay-button').count(), 0); assert.equal(await page.locator('#whisper-history-btn').isHidden(), true); assert.equal(await page.locator('.tsv-highlight-whisper-preview').count(), 0); const saved = await page.evaluate(() => window.teamspeach.getWhisper()); assert.equal(saved.ok, true); assert.equal(saved.lists.length, 1); const uuid = saved.lists[0].list_uuid; const receive = page.locator('#whisper-settings [role="radiogroup"] [role="radio"]'); assert.equal(await receive.count(), 2); assert.equal(await receive.nth(0).getAttribute('aria-checked'), 'true'); await receive.nth(1).click(); await waitForAsync(page, async () => (await window.teamspeach.getWhisper()).receiveMode === 'deny_all'); await page.waitForFunction(() => document.querySelectorAll('#whisper-settings [role="radio"]')[1]?.getAttribute('aria-checked') === 'true'); result.checks.push('Real UI creates local list and saves deny-all receive mode through the Allow/Deny radio group without sending'); await page.click('#settings-nav [data-panel="keys"]'); // Official first run: "No Profile"; "+" turns the profile cell into the inline "New Profile Name" editor. await page.locator('#keybind-settings .tsv-settings-keybinds-profile .tsv-bar-item:last-child button').click(); await page.locator('#keybind-settings .ts-keybinds-profile-cell .ts-input').fill('QA profile'); await page.keyboard.press('Enter'); await waitForAsync(page, async () => (await window.teamspeach.getKeybinds()).profiles.length === 1); const listGroup = page.locator('#keybind-settings .ts-keybinds-hotkeys-group').nth(7); // Whisper to List await listGroup.locator('select').selectOption(uuid); await listGroup.locator('.ts-keybinds-hotkeys-entry-unset button').click({ force: true }); const systemShortcut = page.locator('.keybind-menu .menu-item').first(); if (await systemShortcut.count()) await systemShortcut.click(); await page.keyboard.down('F9'); await page.keyboard.up('F9'); await waitForAsync(page, async () => (await window.teamspeach.getKeybinds()).profiles[0]?.bindings.length === 1); await page.locator('#keybind-settings .ts-keybinds-scope').click(); // Global → In this window await waitForAsync(page, async () => (await window.teamspeach.getKeybinds()).profiles[0]?.bindings[0]?.global === false); const keys = await page.evaluate(() => window.teamspeach.getKeybinds()); const bindings = { bindings: keys.profiles[0].bindings, status: keys.status }; assert.equal(keys.activeProfile, keys.profiles[0].id); assert.equal(bindings.bindings[0].global, false); assert.equal(bindings.bindings[0].code, 'F9'); assert.equal(bindings.bindings[0].target, uuid); assert.equal(bindings.status.global, false); await page.screenshot({ path: path.join(out, 'whisper-local-keybind.png') }); const rejection = await page.evaluate(() => window.teamspeach.request('c1', 'whisper_start', { epoch: 1, target: { kind: 'ids', clients: [], channel_ids: [] } })); assert.equal(rejection.ok, false); result.nativeDisconnectedRejection = rejection.error; result.checks.push('Real native core rejects whisper without a connected target; no simulated route success'); await page.evaluate(() => document.activeElement?.blur()); await page.keyboard.down('F9'); await page.keyboard.up('F9'); const held = await page.evaluate(async () => (await import('./js/whisper.js')).whisperHold.held); assert.equal(held, false); assert.equal((await page.evaluate(() => window.teamspeachDiagnostics.snapshot())).voice.capturing, false); await app.close(); app = null; app = await launchApp({ profile, exe: option('exe') }); page = await app.firstWindow(); page.on('pageerror', e => result.errors.push(e.message)); await page.waitForSelector('#view-app', { state: 'visible' }); const restored = await page.evaluate(async () => ({ whisper: await window.teamspeach.getWhisper(), keys: await window.teamspeach.getKeybinds() })); assert.equal(restored.whisper.lists[0].list_uuid, uuid); assert.equal(restored.whisper.receiveMode, 'deny_all'); assert.deepEqual(restored.keys.profiles[0].bindings, bindings.bindings); assert.equal((await page.evaluate(id => window.teamspeach.setKeybinds(id, []), restored.keys.profiles[0].id)).ok, true); assert.equal((await page.evaluate(id => window.teamspeach.deleteWhisperList(id), uuid)).ok, true); assert.equal((await page.evaluate(() => window.teamspeach.getWhisper())).lists.length, 0); result.checks.push('Process restart preserves list/receive/binding; explicit delete removes local state'); assert.deepEqual(result.errors, []); result.ok = true; } catch (error) { result.ok = false; result.failure = error.stack; process.exitCode = 1; result.state = await page?.evaluate(async () => ({ keys: await window.teamspeach.getKeybinds(), panel: document.querySelector('#keybind-settings')?.innerText })).catch(() => null); 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)); }