Files
client/scripts/smoke-capture.mjs
T
omar e6464bc4ed feat: checkpoint account-free client workflows and source-matched UI
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.
2026-11-01 19:43:18 +03:00

128 lines
7.9 KiB
JavaScript

// ISOLATED OS DESKTOP ONLY. This script does not create display isolation.
// Never run on the user's interactive Windows desktop, even with a test profile.
// It captures only its generated window and Chromium fake camera; no audio.
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import { launchApp } from './lib/electron-app.mjs';
const args = process.argv.slice(2);
if (!args.includes('--isolated-desktop') || process.env.TEAMSPEACH_ISOLATED_DESKTOP !== '1') throw new Error('Refusing visible capture tests: provide a genuinely isolated OS desktop/VM or Xvfb first, then --isolated-desktop and TEAMSPEACH_ISOLATED_DESKTOP=1. A disposable profile alone is not desktop isolation.');
const at = args.indexOf('--profile');
if (!args.includes('--allow-generated-window-capture') || at < 0 || !args[at + 1]) throw new Error('Required: --allow-generated-window-capture --profile <NEW disposable directory>');
const profile = path.resolve(args[at + 1]);
if (fs.existsSync(profile) || fs.existsSync(`${profile}-fake-camera`)) throw new Error('Profiles must be new disposable directories, never a normal user profile.');
const evidence = { desktopAudioCaptured: false, microphoneCaptured: false, physicalCameraCaptured: false, platform: process.platform, results: [] };
async function addCaptureButton(page, sourceId) {
await page.evaluate(async id => {
const capture = await import('./js/stream/capture.js');
window.__captureFixture = { state: 'ready', stream: null, error: null };
const button = document.createElement('button');
button.id = 'capture-fixture-start';
button.textContent = 'Capture generated test source only';
button.style.cssText = 'position:fixed;left:20px;top:20px;z-index:2147483647;padding:20px';
button.onclick = async () => {
window.__captureFixture.state = 'requesting';
try {
window.__captureFixture.stream = await capture.acquireCapture({ sourceId: id, audioMode: 'none' });
window.__captureFixture.state = 'live';
} catch (error) {
window.__captureFixture.error = { code: error.code, message: error.message };
window.__captureFixture.state = 'failed';
}
};
document.body.append(button);
}, sourceId);
await page.locator('#capture-fixture-start').click();
await page.waitForFunction(() => ['live', 'failed'].includes(window.__captureFixture.state), null, { timeout: 20000 });
const status = await page.evaluate(() => ({ state: window.__captureFixture.state, error: window.__captureFixture.error }));
assert.equal(status.state, 'live', JSON.stringify(status.error));
}
async function stopCapture(page) {
return page.evaluate(async () => {
const stream = window.__captureFixture.stream;
stream.getTracks().forEach(track => track.stop());
await window.teamspeach.cancelCaptureSelection();
return stream.getTracks().every(track => track.readyState === 'ended');
});
}
let app;
try {
app = await launchApp({ profile, timeout: 30000 });
const page = await app.firstWindow();
await page.waitForFunction(() => Boolean(window.teamspeach?.getCaptureCapabilities));
const capabilities = await page.evaluate(() => window.teamspeach.getCaptureCapabilities());
if (capabilities.portal || capabilities.nativePicker) throw new Error('This unattended smoke requires an enumerable own-window backend. Native macOS/Wayland choosers require manual explicit selection; no bypass is attempted.');
evidence.runtime = await app.evaluate(() => process.versions);
const title = `TeamsPeach generated capture fixture ${Date.now()}`;
await app.evaluate(async ({ BrowserWindow }, title) => {
const fixture = new BrowserWindow({ width: 480, height: 320, title, backgroundColor: '#12a34b', show: true, webPreferences: { sandbox: true, contextIsolation: true, nodeIntegration: false, partition: 'capture-fixture-generated' } });
globalThis.__captureSourceFixture = fixture;
await fixture.loadURL(`data:text/html,${encodeURIComponent(`<html><head><title>${title}</title></head><body style="margin:0;background:#12a34b;color:white;font:24px sans-serif"><p style="margin:80px">Generated safe test content</p></body></html>`)}`);
fixture.setTitle(title);
}, title);
const selected = await page.evaluate(async title => {
const result = await window.teamspeach.listCaptureSources({ types: ['window'] });
if (!result.ok) throw new Error(result.error.message);
const source = result.sources.find(source => source.name === title);
if (!source) throw new Error('Own generated window was not enumerated; refusing to capture any alternative source.');
return { id: source.id, kind: source.kind };
}, title);
assert.equal(selected.kind, 'window');
await addCaptureButton(page, selected.id);
const frame = await page.evaluate(async () => {
const stream = window.__captureFixture.stream;
if (stream.getAudioTracks().length) throw new Error('Unexpected audio track');
const video = document.createElement('video');
video.muted = true; video.srcObject = stream; await video.play();
await new Promise(resolve => video.requestVideoFrameCallback(resolve));
const canvas = document.createElement('canvas'); canvas.width = video.videoWidth; canvas.height = video.videoHeight;
const context = canvas.getContext('2d'); context.drawImage(video, 0, 0);
const pixel = [...context.getImageData(Math.floor(canvas.width * .85), Math.floor(canvas.height * .8), 1, 1).data];
video.srcObject = null;
return { width: canvas.width, height: canvas.height, pixel, settings: stream.getVideoTracks()[0].getSettings() };
});
assert.ok(frame.width > 0 && frame.height > 0);
assert.ok(frame.pixel[1] > frame.pixel[0] + 40 && frame.pixel[1] > frame.pixel[2] + 30, `Own generated green content not observed: ${frame.pixel}`);
evidence.results.push({ test: 'own-window-real-capture', passed: true, width: frame.width, height: frame.height, pixel: frame.pixel, displaySurface: frame.settings.displaySurface });
assert.equal(await stopCapture(page), true);
evidence.results.push({ test: 'explicit-stop-all-tracks', passed: true });
await app.evaluate(() => globalThis.__captureSourceFixture.close());
const stale = await page.evaluate(id => window.teamspeach.selectCaptureSource({ sourceId: id }), selected.id);
assert.equal(stale.ok, false);
evidence.results.push({ test: 'closed-source-no-fallback', passed: true });
} finally {
if (app) await app.close();
}
app = null;
try {
app = await launchApp({ profile: `${profile}-fake-camera`, args: ['--use-fake-device-for-media-stream'], timeout: 30000 });
const page = await app.firstWindow();
await page.waitForFunction(() => Boolean(window.teamspeach?.getCaptureCapabilities));
const denied = await page.evaluate(async () => {
try { const stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: false }); stream.getTracks().forEach(track => track.stop()); return false; } catch { return true; }
});
assert.equal(denied, true, 'Camera must not open without an explicit one-use selection');
const camera = await page.evaluate(async () => {
const { listCaptureCameras } = await import('./js/stream/capture.js');
const devices = await listCaptureCameras();
if (!devices.length) throw new Error('Fake-camera enumeration returned no selectable source.');
return devices[0];
});
await addCaptureButton(page, camera.id);
const actual = await page.evaluate(() => {
const stream = window.__captureFixture.stream;
return { video: stream.getVideoTracks().length, audio: stream.getAudioTracks().length, label: stream.getVideoTracks()[0].label, settings: stream.getVideoTracks()[0].getSettings() };
});
assert.equal(actual.video, 1); assert.equal(actual.audio, 0);
assert.equal(await stopCapture(page), true);
evidence.results.push({ test: 'fake-camera-explicit-selection-and-stop', passed: true, label: actual.label, width: actual.settings.width, height: actual.settings.height });
} finally {
if (app) await app.close();
}
console.log(JSON.stringify(evidence, null, 2));