// Real Electron UI smoke run (no mocks): first launch → onboarding → restart persistence → rename, // optional live server connect. Uses a disposable profile directory so the user's profile is untouched. // // node scripts/smoke-ui.mjs --out docs/evidence/runtime/ [--server 10.10.10.160:9987] [--profile DIR] // // Writes screenshots and result.json (UIDs are public identifiers; no private key ever leaves the core). import { launchApp } from './lib/electron-app.mjs'; import { mkdirSync, writeFileSync, mkdtempSync } from 'node:fs'; import { tmpdir } from 'node:os'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const args = Object.fromEntries(process.argv.slice(2).reduce((acc, a, i, all) => { if (a.startsWith('--')) acc.push([a.slice(2), all[i + 1] && !all[i + 1].startsWith('--') ? all[i + 1] : 'true']); return acc; }, [])); const out = path.resolve(root, args.out ?? 'smoke-out'); const profile = args.profile ? path.resolve(args.profile) : mkdtempSync(path.join(tmpdir(), 'teamspeach-smoke-')); mkdirSync(out, { recursive: true }); const result = { startedAt: new Date().toISOString(), profile, steps: [], console: [] }; const step = (name, data = {}) => { result.steps.push({ name, at: new Date().toISOString(), ...data }); console.log(`[smoke] ${name}`, JSON.stringify(data)); }; async function launch(label) { const extra = [...(process.env.TEAMSPEACH_SMOKE_EXTRA_ARGS ?? '').split(' ').filter(Boolean), ...(args.fakemic ? ['--use-fake-device-for-media-stream', '--use-fake-ui-for-media-stream'] : [])]; // --exe runs a packaged build instead of the development tree. const app = await launchApp({ exe: args.exe, profile, args: extra }); const page = await app.firstWindow(); page.on('console', (msg) => result.console.push(`${label} ${msg.type()}: ${msg.text()}`)); page.on('pageerror', (err) => result.console.push(`${label} pageerror: ${err.message}`)); await page.setViewportSize({ width: 1280, height: 800 }).catch(() => {}); return { app, page }; } const diag = (page) => page.evaluate(() => window.teamspeachDiagnostics.snapshot()); const visible = (page, sel) => page.waitForSelector(sel, { state: 'visible', timeout: 20000 }); const shot = async (page, name) => { await page.waitForTimeout(300); await page.screenshot({ path: path.join(out, name) }); step(`screenshot ${name}`); }; let failed = null; try { // 1. First launch: onboarding must ask for a nickname once. let { app, page } = await launch('run1'); await visible(page, '#view-onboarding'); await shot(page, '01-first-launch-onboarding.png'); await page.fill('#onboarding-nick', 'ab'); await page.click('#onboarding-submit'); const validation = await page.textContent('#onboarding-error'); step('short nickname rejected', { message: validation }); await page.fill('#onboarding-nick', 'PeachSmoke'); await page.click('#onboarding-submit'); await visible(page, '#view-app'); let d = await diag(page); const uid1 = d.profile.uid; step('profile created', { uid: uid1, nickname: d.profile.nickname }); await shot(page, '02-after-onboarding.png'); await app.close(); // 2. Restart: same identity, no onboarding. ({ app, page } = await launch('run2')); await visible(page, '#view-app'); d = await diag(page); step('restart keeps identity', { uid: d.profile.uid, nickname: d.profile.nickname, same: d.profile.uid === uid1 }); if (d.profile.uid !== uid1) throw new Error('UID changed after restart'); // 3. Rename in settings: UID must not change. await page.click('#btn-settings'); await visible(page, '#settings-view'); await page.fill('#rename-input', 'PeachRenamed'); await page.click('#rename-submit'); await page.waitForFunction(() => window.teamspeachDiagnostics.snapshot().profile.nickname === 'PeachRenamed', null, { timeout: 15000 }); d = await diag(page); step('renamed', { uid: d.profile.uid, nickname: d.profile.nickname, status: await page.textContent('#rename-status'), same: d.profile.uid === uid1 }); if (d.profile.uid !== uid1) throw new Error('UID changed after rename'); await shot(page, '03-settings-renamed.png'); await app.close(); // 4. Restart again: rename persisted. ({ app, page } = await launch('run3')); await visible(page, '#view-app'); d = await diag(page); step('rename persisted', { uid: d.profile.uid, nickname: d.profile.nickname, ok: d.profile.uid === uid1 && d.profile.nickname === 'PeachRenamed' }); if (d.profile.nickname !== 'PeachRenamed') throw new Error('rename not persisted'); // 5. Optional live server connection. if (args.server) { await page.fill('#connect-address', args.server); await page.click('#connect-submit'); await page.waitForFunction(() => window.teamspeachDiagnostics.snapshot().conn === 'connected', null, { timeout: 60000 }); await page.waitForTimeout(1500); d = await diag(page); step('connected', { server: d.server, ownClientId: d.ownClientId, channel: d.ownChannel, clients: d.clients.length, videoCodecs: d.videoCodecs }); await shot(page, '04-connected.png'); await page.click('#btn-disconnect'); await page.waitForFunction(() => window.teamspeachDiagnostics.snapshot().conn === 'disconnected', null, { timeout: 15000 }); step('disconnected'); } // 6. Identity backup through the real export path; only the native save dialog is answered by the test. const exportFile = path.join(mkdtempSync(path.join(tmpdir(), 'teamspeach-export-')), 'identity.ini'); await app.evaluate(({ dialog }, file) => { dialog.showSaveDialog = async () => ({ canceled: false, filePath: file }); }, exportFile); await page.click('#btn-settings'); await page.click('#identity-export'); await page.waitForFunction(() => Boolean(document.querySelector('#identity-status').dataset.state), null, { timeout: 20000 }); const exportStatus = await page.textContent('#identity-status'); const { readFileSync, rmSync } = await import('node:fs'); const exported = readFileSync(exportFile, 'utf8'); step('identity exported', { status: exportStatus, statusHasUid: exportStatus.includes(uid1), iniHeader: exported.split(/\r?\n/)[0], containsIdentityKey: /^identity=/m.test(exported) }); rmSync(path.dirname(exportFile), { recursive: true, force: true }); if (!exportStatus.includes(uid1)) throw new Error('export did not report the profile UID'); // 7. Hardware video decoding: off → restart → reported as disabled at launch. await page.click('#settings-nav .nav-item[data-panel="video"]'); await page.uncheck('#opt-hwdec'); await page.waitForSelector('#hwdec-restart', { state: 'visible', timeout: 5000 }); step('hardware decode disabled, restart required', { status: await page.textContent('#hwdec-status') }); await app.close(); ({ app, page } = await launch('run4')); await visible(page, '#view-app'); await page.click('#btn-settings'); await page.click('#settings-nav .nav-item[data-panel="video"]'); await page.click('.settings-panel[data-panel="video"] summary'); await page.waitForFunction(() => document.querySelector('#hwdec-status').dataset.policy === 'forbidden', null, { timeout: 10000 }); step('after restart', { status: await page.textContent('#hwdec-status'), restartHint: await page.isVisible('#hwdec-restart') }); await shot(page, '05-video-decode-disabled.png'); await page.check('#opt-hwdec'); await app.close(); } catch (err) { failed = err; step('FAILED', { error: String(err.stack || err) }); } result.finishedAt = new Date().toISOString(); result.ok = !failed; writeFileSync(path.join(out, 'result.json'), JSON.stringify(result, null, 2)); console.log(`[smoke] ${result.ok ? 'OK' : 'FAILED'} → ${out}`); process.exit(result.ok ? 0 : 1);