// Real audio devices in Settings → Звук (NO fake-media flags): lists what the engine exposes without any // capture, selects a non-default microphone and output, restarts and checks the choice persisted. // Never connects to a server, never starts the microphone, plays nothing. // node scripts/smoke-devices.mjs --out docs/evidence/runtime/ [--exe packaged.exe] import { _electron as electron } from 'playwright-core'; import { mkdirSync, writeFileSync, mkdtempSync, rmSync } from 'node:fs'; import { tmpdir } from 'node:os'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { createRequire } from 'node:module'; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const electronPath = createRequire(import.meta.url)('electron'); const argv = process.argv.slice(2); const opt = (n, d) => (argv.indexOf(`--${n}`) >= 0 ? argv[argv.indexOf(`--${n}`) + 1] : d); const out = path.resolve(root, opt('out', 'smoke-out')); const exe = opt('exe'); mkdirSync(out, { recursive: true }); const profile = mkdtempSync(path.join(tmpdir(), 'teamspeach-devices-')); const result = { steps: [], console: [] }; const step = (name, data = {}) => { result.steps.push({ name, ...data }); console.log(`[devices] ${name}`, JSON.stringify(data)); }; async function launch(label) { const app = await electron.launch({ executablePath: exe ? path.resolve(exe) : electronPath, args: exe ? [] : [root], env: { ...process.env, TEAMSPEACH_PROFILE_DIR: profile }, colorScheme: null, }); const page = await app.firstWindow(); page.on('console', (m) => result.console.push(`${label} ${m.type()}: ${m.text()}`)); page.on('pageerror', (e) => result.console.push(`${label} pageerror: ${e.message}`)); await page.setViewportSize({ width: 1280, height: 800 }).catch(() => {}); return { app, page }; } const readSelects = (page) => page.evaluate(() => { const read = (id) => Array.from(document.querySelector(id).options).map((o) => ({ value: o.value ? 'id' : '', label: o.textContent })); return { inputs: read('#input-device'), outputs: read('#output-device'), inputValueIsDevice: Boolean(document.querySelector('#input-device').value), outputValueIsDevice: Boolean(document.querySelector('#output-device').value), status: document.querySelector('#device-status').textContent, framesSent: window.teamspeachDiagnostics.snapshot().voice.framesSent, capturing: window.teamspeachDiagnostics.snapshot().voice.capturing, conn: window.teamspeachDiagnostics.snapshot().conn, toasts: Array.from(document.querySelectorAll('.toast[data-kind="error"]')).map((t) => t.textContent), }; }); let app; let page; let failed = null; try { ({ app, page } = await launch('run1')); await page.waitForSelector('#view-onboarding', { state: 'visible', timeout: 20000 }); await page.fill('#onboarding-nick', 'DeviceSmoke'); await page.click('#onboarding-submit'); await page.waitForSelector('#view-app', { state: 'visible', timeout: 20000 }); await page.click('#btn-settings'); await page.click('#settings-nav .nav-item[data-panel="audio"]'); await page.waitForFunction(() => document.querySelector('#device-status').textContent.length > 0, null, { timeout: 10000 }); let s = await readSelects(page); step('listed without capture', { inputs: s.inputs.length - 1, outputs: s.outputs.length - 1, inputLabels: s.inputs.map((o) => o.label), outputLabels: s.outputs.map((o) => o.label), status: s.status, conn: s.conn, framesSent: s.framesSent, capturing: s.capturing }); await page.screenshot({ path: path.join(out, '60-audio-devices-listed.png') }); if (s.inputs.length < 2 || s.outputs.length < 2) throw new Error('no physical devices listed'); // Choose the second physical device of each kind (first non-default entry after index 0). const inputChoice = await page.$eval('#input-device', (el) => el.options[Math.min(2, el.options.length - 1)].textContent); const outputChoice = await page.$eval('#output-device', (el) => el.options[Math.min(2, el.options.length - 1)].textContent); await page.selectOption('#input-device', { label: inputChoice }); await page.selectOption('#output-device', { label: outputChoice }); await page.waitForTimeout(1000); s = await readSelects(page); step('selected', { inputChoice, outputChoice, toasts: s.toasts, framesSent: s.framesSent, capturing: s.capturing }); await app.close(); ({ app, page } = await launch('run2')); await page.waitForSelector('#view-app', { state: 'visible', timeout: 20000 }); await page.click('#btn-settings'); await page.click('#settings-nav .nav-item[data-panel="audio"]'); await page.waitForFunction(() => document.querySelector('#device-status').textContent.length > 0, null, { timeout: 10000 }); s = await readSelects(page); const inputNow = await page.$eval('#input-device', (el) => el.selectedOptions[0].textContent); const outputNow = await page.$eval('#output-device', (el) => el.selectedOptions[0].textContent); step('after restart', { inputNow, outputNow, persisted: inputNow === inputChoice && outputNow === outputChoice, toasts: s.toasts, conn: s.conn }); await page.screenshot({ path: path.join(out, '61-audio-devices-after-restart.png') }); if (inputNow !== inputChoice || outputNow !== outputChoice) throw new Error('selection not persisted'); // Leave the profile as found: back to system defaults (profile is deleted anyway). await page.selectOption('#input-device', ''); await page.selectOption('#output-device', ''); } catch (err) { failed = err; step('FAILED', { error: String(err.stack || err) }); } finally { if (app) await app.close().catch(() => {}); rmSync(profile, { recursive: true, force: true }); } result.ok = !failed; writeFileSync(path.join(out, 'result.json'), JSON.stringify(result, null, 2)); console.log(`[devices] ${result.ok ? 'OK' : 'FAILED'} → ${out}`); process.exit(result.ok ? 0 : 1);