VoiceStudio is the open-source, fully-local ElevenLabs alternative — voice cloning, voice design, video dubbing, dictation, transcription & audiobook creation in 646 languages.
Python aiaudiobookcudadubbingelevenlabs-alternativehuggingfacelocal-firstmlxomnivoice-studiospeech-to-texttext-to-speechtranscriptiontranslatettsvoice-aivoice-cloningvoice-generationvoicestudioworkflow
ci(desktop): bind the dev proxy on an OS-assigned port in UI tests
velixio894405ae6475
diff --git a/electron/src/main/dev-backend-proxy.test.ts b/electron/src/main/dev-backend-proxy.test.tsindex 7f1e127ac..88b682b3c 100644--- a/electron/src/main/dev-backend-proxy.test.ts+++ b/electron/src/main/dev-backend-proxy.test.ts@@ -1,7 +1,9 @@// @vitest-environment nodeimport { createServer } from 'node:http';import { afterEach, expect, it } from 'vitest';+import { DEFAULT_ELECTRON_PROXY_PORT } from '../../../config/app-config.mjs';import {+ electronProxyPort,proxyRequestRefused,startDevBackendProxy,type DevBackendProxy,@@ -124,3 +126,17 @@ it('refuses other websites and rebound host names before injecting credentials',proxyRequestRefused({ host: '127.0.0.1:3903', 'sec-fetch-site': 'cross-site' }, renderer),).toBe(true);});++it('binds an OS-assigned port when asked for port 0, so no pre-picked port can be stolen', async () => {+ expect(electronProxyPort('0')).toBe(0);+ const proxy = await startDevBackendProxy(() => 'http://127.0.0.1:1', () => ({}), 0);+ cleanup.push(proxy.close);+ expect(Number(new URL(proxy.url).port)).toBeGreaterThan(0);+});++it('falls back to the default proxy port for a missing or invalid setting', () => {+ for (const raw of [undefined, '', ' ', 'abc', '-1', '65536', '1.5']) {+ expect(electronProxyPort(raw)).toBe(DEFAULT_ELECTRON_PROXY_PORT);+ }+ expect(electronProxyPort('49305')).toBe(49305);+});diff --git a/electron/src/main/dev-backend-proxy.ts b/electron/src/main/dev-backend-proxy.tsindex 5b11884b4..9e92ab173 100644--- a/electron/src/main/dev-backend-proxy.ts+++ b/electron/src/main/dev-backend-proxy.ts@@ -68,6 +68,19 @@ export interface DevBackendProxy {close: () => Promise<void>;}+/**+ * Port for the dev proxy from `VOICESTUDIO_ELECTRON_PROXY_PORT`. `0` asks the OS+ * for a free port at bind time: test harnesses that load the packaged renderer+ * use it, because a port picked first and bound later can be taken in between+ * (Electron's own debugger listener took one in CI).+ */+export function electronProxyPort(raw: string | undefined): number {+ const port = Number(raw);+ return raw?.trim() && Number.isInteger(port) && port >= 0 && port <= 65535+ ? port+ : DEFAULT_ELECTRON_PROXY_PORT;+}+/** Dev-only same-origin bridge whose target and scoped credentials remain main-owned. */export async function startDevBackendProxy(getBaseUrl: () => string,diff --git a/electron/src/main/index.ts b/electron/src/main/index.tsindex a1ddfe6ed..e51886f03 100644--- a/electron/src/main/index.ts+++ b/electron/src/main/index.ts@@ -10,7 +10,7 @@ import { electronApp, is, optimizer } from '@electron-toolkit/utils';import { BackendSupervisor, backendRoot } from './backend';import { registerIpc, wireWindowMaximizeEvents } from './ipc';import { APP_ORIGIN, installAppProtocol, registerAppScheme } from './protocol';-import { startDevBackendProxy } from './dev-backend-proxy';+import { electronProxyPort, startDevBackendProxy } from './dev-backend-proxy';import { DesktopUpdater, registerUpdateIpc } from './updater';import { registerRepairAgents } from './repair-agents';import { installRendererPermissions } from './media-permissions';@@ -24,7 +24,7 @@ import {import { activateLiveWindow, isLiveWindow } from './window-safety';import { startAccount } from './account';import { installAppIdentity, installMacApplicationMenu } from './app-identity';-import { APP_ID, DEFAULT_ELECTRON_PROXY_PORT, PRODUCT_NAME } from '../../../config/app-config.mjs';+import { APP_ID, PRODUCT_NAME } from '../../../config/app-config.mjs';// Packaged GUI launches can inherit a short-lived terminal pipe. When that// launcher exits, diagnostic console writes emit EPIPE asynchronously and can@@ -288,7 +288,7 @@ if (process.env.VOICESTUDIO_ALLOW_MULTIPLE_INSTANCES !== '1' && !app.requestSingconst proxy = await startDevBackendProxy(() => backend.baseUrl,() => backend.requestHeaders(),- Number(process.env.VOICESTUDIO_ELECTRON_PROXY_PORT) || DEFAULT_ELECTRON_PROXY_PORT,+ electronProxyPort(process.env.VOICESTUDIO_ELECTRON_PROXY_PORT),process.env.ELECTRON_RENDERER_URL? [new URL(process.env.ELECTRON_RENDERER_URL).origin]: [],diff --git a/electron/tests/account-sign-in-live.mjs b/electron/tests/account-sign-in-live.mjsindex fca254072..c9466861e 100644--- a/electron/tests/account-sign-in-live.mjs+++ b/electron/tests/account-sign-in-live.mjs@@ -44,7 +44,7 @@ const app = await electron.launch({...launchEnvironment,ELECTRON_RENDERER_URL: "",VOICESTUDIO_CLOUD_ENV: "dev",- VOICESTUDIO_ELECTRON_PROXY_PORT: "49305",+ VOICESTUDIO_ELECTRON_PROXY_PORT: "0",VOICESTUDIO_SKIP_BACKEND: "1",VOICESTUDIO_ALLOW_MULTIPLE_INSTANCES: "1",},diff --git a/electron/tests/desktop-harness.mjs b/electron/tests/desktop-harness.mjsindex 710e0da4a..1b8e09a38 100644--- a/electron/tests/desktop-harness.mjs+++ b/electron/tests/desktop-harness.mjs@@ -61,7 +61,7 @@ const slug = (name) =>.replace(/^-|-$/g, '').toLowerCase();-async function launch({ profile, backendPort, proxyPort, seed }) {+async function launch({ profile, backendPort, seed }) {// VS Code terminals export ELECTRON_RUN_AS_NODE=1, which makes Electron boot as plain Node.const { ELECTRON_RUN_AS_NODE: _runAsNode, ...inherited } = process.env;const app = await electron.launch({@@ -80,7 +80,8 @@ async function launch({ profile, backendPort, proxyPort, seed }) {VOICESTUDIO_SKIP_BACKEND: '1',VOICESTUDIO_ALLOW_MULTIPLE_INSTANCES: '1',VOICESTUDIO_DISABLE_UPDATER: '1',- VOICESTUDIO_ELECTRON_PROXY_PORT: String(proxyPort),+ // The OS assigns it at bind time; a pre-picked port can be taken before the app binds it.+ VOICESTUDIO_ELECTRON_PROXY_PORT: '0',},timeout: 60000,});@@ -161,11 +162,10 @@ export async function withApp(t, options, body) {}): null;const backendPort = backend ? backend.port : await freePort();- const proxyPort = await freePort();const live = [];const session = { profile, backend, relaunch: null };const start = async () => {- const started = await launch({ profile, backendPort, proxyPort, seed });+ const started = await launch({ profile, backendPort, seed });live.push(started);Object.assign(session, started);return session;diff --git a/electron/tests/native-capture-smoke.mjs b/electron/tests/native-capture-smoke.mjsindex 254d4a58f..bc3285a50 100644--- a/electron/tests/native-capture-smoke.mjs+++ b/electron/tests/native-capture-smoke.mjs@@ -27,7 +27,7 @@ const app = await electron.launch({ELECTRON_RENDERER_URL: '',OMNIVOICE_PORT: String(health.port),VOICESTUDIO_ALLOW_MULTIPLE_INSTANCES: '1',- VOICESTUDIO_ELECTRON_PROXY_PORT: process.env.VOICESTUDIO_ELECTRON_PROXY_PORT || '49313',+ VOICESTUDIO_ELECTRON_PROXY_PORT: process.env.VOICESTUDIO_ELECTRON_PROXY_PORT || '0',VOICESTUDIO_SKIP_BACKEND: '1',},timeout: 30000,diff --git a/electron/tests/native-media-picker-smoke.mjs b/electron/tests/native-media-picker-smoke.mjsindex a0e9a84a7..a5bffea3c 100644--- a/electron/tests/native-media-picker-smoke.mjs+++ b/electron/tests/native-media-picker-smoke.mjs@@ -35,7 +35,7 @@ const app = await electron.launch({env: {...process.env,ELECTRON_RENDERER_URL: '',- VOICESTUDIO_ELECTRON_PROXY_PORT: '49306',+ VOICESTUDIO_ELECTRON_PROXY_PORT: '0',VOICESTUDIO_SKIP_BACKEND: '1',VOICESTUDIO_ALLOW_MULTIPLE_INSTANCES: '1',},diff --git a/electron/tests/native-repair-agent-smoke.mjs b/electron/tests/native-repair-agent-smoke.mjsindex 418033a4a..7e447a779 100644--- a/electron/tests/native-repair-agent-smoke.mjs+++ b/electron/tests/native-repair-agent-smoke.mjs@@ -25,7 +25,7 @@ const app = await electron.launch({env: {...launchEnvironment,ELECTRON_RENDERER_URL: '',- VOICESTUDIO_ELECTRON_PROXY_PORT: '49303',+ VOICESTUDIO_ELECTRON_PROXY_PORT: '0',VOICESTUDIO_SKIP_BACKEND: '1',VOICESTUDIO_ALLOW_MULTIPLE_INSTANCES: '1',},diff --git a/electron/tests/native-report-bug-smoke.mjs b/electron/tests/native-report-bug-smoke.mjsindex 2e1ace49c..b8f6a3b3a 100644--- a/electron/tests/native-report-bug-smoke.mjs+++ b/electron/tests/native-report-bug-smoke.mjs@@ -16,7 +16,7 @@ const app = await electron.launch({...process.env,ELECTRON_RENDERER_URL: '',VOICESTUDIO_ALLOW_MULTIPLE_INSTANCES: '1',- VOICESTUDIO_ELECTRON_PROXY_PORT: '49304',+ VOICESTUDIO_ELECTRON_PROXY_PORT: '0',},});try {diff --git a/electron/tests/native-watch-ui-smoke.mjs b/electron/tests/native-watch-ui-smoke.mjsindex 7866f0571..ea5d7268a 100644--- a/electron/tests/native-watch-ui-smoke.mjs+++ b/electron/tests/native-watch-ui-smoke.mjs@@ -28,7 +28,7 @@ const app = await electron.launch({ELECTRON_RENDERER_URL: '',OMNIVOICE_PORT: String(health.port),VOICESTUDIO_ALLOW_MULTIPLE_INSTANCES: '1',- VOICESTUDIO_ELECTRON_PROXY_PORT: process.env.VOICESTUDIO_ELECTRON_PROXY_PORT || '49314',+ VOICESTUDIO_ELECTRON_PROXY_PORT: process.env.VOICESTUDIO_ELECTRON_PROXY_PORT || '0',VOICESTUDIO_SKIP_BACKEND: '1',},timeout: 30000,