Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

test(live-voice): verify plaintext websocket transport

vastsa9f625da7d1e5
diff --git a/apps/desktop/test/live-voice-websocket-endpoint.test.mjs b/apps/desktop/test/live-voice-websocket-endpoint.test.mjs
index 0d30a7dc5..bf1f5096f 100644
--- a/apps/desktop/test/live-voice-websocket-endpoint.test.mjs
+++ b/apps/desktop/test/live-voice-websocket-endpoint.test.mjs
@@ -1,4 +1,7 @@
import assert from "node:assert/strict";
+import { once } from "node:events";
+import { createServer as createHttpServer } from "node:http";
+import { createRequire } from "node:module";
import test from "node:test";
import { fileURLToPath } from "node:url";
import { createServer } from "vite";
@@ -15,6 +18,82 @@ async function loadEndpoint(t) {
return server.ssrLoadModule("/electron/main/live-voice/websocket-endpoint.ts");
}
+async function loadTransport(t, proxyRoute = "DIRECT") {
+ const electronStub = {
+ name: "live-voice-electron-test-stub",
+ enforce: "pre",
+ resolveId(id) {
+ return id === "electron" ? "\0live-voice-electron-test-stub" : null;
+ },
+ load(id) {
+ if (id !== "\0live-voice-electron-test-stub") return null;
+ return `export const net = { fetch: async () => { throw new Error("unexpected fetch"); } };
+ export const session = { defaultSession: { resolveProxy: async () => ${JSON.stringify(proxyRoute)} } };`;
+ },
+ };
+ const server = await createServer({
+ root: fileURLToPath(new URL("..", import.meta.url)),
+ configFile: false,
+ plugins: [electronStub],
+ ssr: { noExternal: ["electron"] },
+ server: { middlewareMode: true, hmr: false, ws: false },
+ appType: "custom",
+ optimizeDeps: { noDiscovery: true, include: [] },
+ });
+ t.after(() => server.close());
+ return server.ssrLoadModule("/electron/main/live-voice/websocket-transport.ts");
+}
+
+test("Live transport connects to a user-supplied loopback ws endpoint", async (t) => {
+ const { openLiveWebSocket } = await loadTransport(t);
+ const { WebSocketServer } = createRequire(new URL("../package.json", import.meta.url))("ws");
+ const server = createHttpServer();
+ const fixture = new WebSocketServer({ server });
+ let connections = 0;
+ let request;
+ fixture.on("connection", (_socket, incoming) => {
+ connections++;
+ request = incoming;
+ });
+ await new Promise((resolve, reject) => {
+ server.once("error", reject);
+ server.listen(0, "127.0.0.1", resolve);
+ });
+ t.after(async () => {
+ for (const socket of fixture.clients) socket.terminate();
+ await new Promise((resolve) => fixture.close(resolve));
+ server.closeAllConnections();
+ await new Promise((resolve) => server.close(resolve));
+ });
+
+ const client = await openLiveWebSocket({
+ url: `ws://127.0.0.1:${server.address().port}/v1/realtime?model=fixture`,
+ headers: { Authorization: "Bearer local-fixture-key" },
+ signal: new AbortController().signal,
+ endpointOrigin: "user",
+ });
+ assert.equal(connections, 1);
+ assert.ok(request);
+ assert.equal(request.url, "/v1/realtime?model=fixture");
+ assert.equal(request.headers.authorization, "Bearer local-fixture-key");
+ const closed = once(client, "close");
+ client.close();
+ await closed;
+});
+
+test("Live transport refuses plain ws when Electron routes it through a proxy", async (t) => {
+ const { openLiveWebSocket } = await loadTransport(t, "PROXY 127.0.0.1:8080");
+
+ await assert.rejects(
+ openLiveWebSocket({
+ url: "ws://127.0.0.1:8010/v1/realtime?model=fixture",
+ signal: new AbortController().signal,
+ endpointOrigin: "user",
+ }),
+ { errorCode: "LIVE_NETWORK_POLICY_UNSUPPORTED" },
+ );
+});
+
test("Realtime socket URL keeps TLS for HTTPS providers and maps HTTP providers to ws", async (t) => {
const { realtimeSocketUrl } = await loadEndpoint(t);
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 5f44a7700..aed1ac09b 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -40,9 +40,10 @@
### E2E-LIVE-VOICE-public-settings-and-reconnect
- **Preconditions:** A built production Renderer and real Electron/Main/Host,
- isolated data/profile/project, developer mode off, a local TLS Realtime
- fixture and synthetic microphone. Trust only the fixture CA in the child
- process; do not disable TLS, sender, sandbox or microphone checks.
+ isolated data/profile/project, developer mode off, a local TLS or loopback
+ HTTP Realtime fixture and synthetic microphone. For TLS, trust only the
+ fixture CA in the child process; do not disable TLS, sender, sandbox or
+ microphone checks.
- **Steps:** Open Live from Composer while disabled and follow Open settings.
Find Voice through settings search, bind the fixture account, enable Live,
connect, unmute, receive audio/captions, mute and hang up. Cancel a delayed
@@ -55,10 +56,14 @@
call. Settings survive restart without reconnecting. Legacy Dictation
settings are unchanged; a voice-only call creates no Agent session.
- **Coverage:** `pnpm test:e2e:live-voice` drives the built app and its concrete
- Realtime GA adapter against local WSS; `live-voice-owner.test.mjs` bundles
- the production owner module and rejects other files/frames. Fixture audio
- is not physical-device or real-provider acceptance. Commands and results
- are recorded in `docs/implementation/live-voice-public-readiness.md`.
+ Realtime GA adapter against local WSS; `pnpm test:e2e:live-voice --
+ --plain-http` repeats the call flow against a loopback `ws://` endpoint.
+ `live-voice-websocket-endpoint.test.mjs` connects the production transport to
+ a local loopback WebSocket and verifies proxy refusal; `live-voice-owner.test.mjs`
+ bundles the production owner module and rejects other files/frames. Fixture
+ audio is not physical-device or real-provider acceptance. Commands and
+ results are recorded in
+ `docs/implementation/live-voice-public-readiness.md`.
- **Specs:** [Live Voice](../03-runtime/live-voice.md).
### E2E-LIVE-VOICE-provider-call-lifecycle
diff --git a/scripts/e2e-live-voice.mjs b/scripts/e2e-live-voice.mjs
index 7a5f03259..46c94980d 100644
--- a/scripts/e2e-live-voice.mjs
+++ b/scripts/e2e-live-voice.mjs
@@ -12,9 +12,11 @@ import { launchLiveVoiceDesktop } from "./e2e/live-voice-desktop.mjs";
import { startLiveVoiceFixture } from "./e2e/live-voice-fixture.mjs";
import { waitFor } from "./e2e/wait.mjs";
-if (process.argv.slice(2).some((arg) => arg !== "--fixture")) {
- throw new Error("Usage: node scripts/e2e-live-voice.mjs [--fixture]. Real accounts are never used by this suite.");
+const args = process.argv.slice(2);
+if (args.some((arg) => !["--fixture", "--plain-http"].includes(arg))) {
+ throw new Error("Usage: node scripts/e2e-live-voice.mjs [--fixture] [--plain-http]. Real accounts are never used by this suite.");
}
+const plainHttp = args.includes("--plain-http");
const root = repositoryRoot();
assertDesktopBuild(root);
const temp = await mkdtemp(join(tmpdir(), "pi-live-voice-e2e-"));
@@ -24,7 +26,7 @@ const home = join(temp, "home");
const project = join(temp, "project");
const evidence = process.env.PI_LIVE_VOICE_EVIDENCE_DIR || join(temp, "evidence");
for (const path of [dataDir, profile, home, project, evidence]) await mkdir(path, { recursive: true });
-const fixture = await startLiveVoiceFixture(root);
+const fixture = await startLiveVoiceFixture(root, { plainHttp });
const host = new Host(resolveHostBinary(), dataDir);
let desktop;
const results = [];
@@ -110,7 +112,9 @@ try {
const providerId = created.provider.id;
await host.call("providers.update", { id: providerId, enabled: true });
await host.stop();
- const launch = () => launchLiveVoiceDesktop({ root, dataDir, profile, home, certificate: fixture.certificate, evidence });
+ const launch = () => launchLiveVoiceDesktop({
+ root, dataDir, profile, home, certificate: fixture.certificate, evidence,
+ });
desktop = await launch();
const initial = await settings();
assert.equal(initial.developerMode, false);
@@ -156,7 +160,8 @@ try {
assert.equal((await status()).call.muted, true);
assert.equal((await status()).call.workBinding, undefined);
await clickBar("Unmute microphone");
- await waitFor(() => fixture.stats.inputFrames > 0, 10_000, "synthetic microphone reaches the real WSS transport");
+ const socketTransport = plainHttp ? "plain WS" : "WSS";
+ await waitFor(() => fixture.stats.inputFrames > 0, 10_000, `synthetic microphone reaches the real ${socketTransport} transport`);
await waitFor(async () => (await status()).call?.phase === "connected" && fixture.active() === 1,
2_000, "uplink credit keeps the call and provider socket connected");
fixture.reply();
@@ -174,7 +179,7 @@ try {
await waitIdle();
await waitFor(() => fixture.active() === 0, 5_000, "provider socket closes after hangup");
assert.deepEqual((await desktop.invoke("sessionList")).sessions, [], "voice-only call creates no Agent session");
- pass("real Realtime socket, synthetic capture, playback/transcript, mute and hangup");
+ pass(`real Realtime ${socketTransport} socket, synthetic capture, playback/transcript, mute and hangup`);
fixture.holdNextSession();
await desktop.clickSelector(".live-voice-control button");
@@ -217,7 +222,7 @@ try {
candidate: execFileSync("git", ["rev-parse", "HEAD"], { cwd: root, encoding: "utf8" }).trim(),
baseMain: execFileSync("git", ["rev-parse", "origin/main"], { cwd: root, encoding: "utf8" }).trim(),
date: new Date().toISOString(), platform: process.platform, node: process.version,
- boundary: "built Electron, real preload/Main/Host, concrete Realtime GA adapter, local trusted TLS peer and synthetic audio",
+ boundary: `built Electron, real preload/Main/Host, concrete Realtime GA adapter, local ${plainHttp ? "loopback HTTP" : "trusted TLS"} peer and synthetic audio`,
notRun: ["real provider accounts", "physical microphone and audible playback", "Live Work tool execution"],
results, fixture: fixture.stats,
}, null, 2));
diff --git a/scripts/e2e/live-voice-fixture.mjs b/scripts/e2e/live-voice-fixture.mjs
index a213a44d7..23bed8793 100644
--- a/scripts/e2e/live-voice-fixture.mjs
+++ b/scripts/e2e/live-voice-fixture.mjs
@@ -1,18 +1,22 @@
import assert from "node:assert/strict";
-import { createServer } from "node:https";
+import { createServer as createHttpServer } from "node:http";
+import { createServer as createHttpsServer } from "node:https";
import { readFile } from "node:fs/promises";
import { createRequire } from "node:module";
import { join } from "node:path";
-/** Local TLS peer only: the app still owns its real socket, media and IPC path. */
-export async function startLiveVoiceFixture(root) {
+/** Local peer only: the app still owns its real socket, media and IPC path. */
+export async function startLiveVoiceFixture(root, { plainHttp = false } = {}) {
const { WebSocketServer, WebSocket } = createRequire(join(root, "apps/desktop/package.json"))("ws");
const certificates = join(root, "scripts/e2e/fixtures/certificates");
const certificate = join(certificates, "localhost-cert.pem");
- const server = createServer({
- key: await readFile(join(certificates, "localhost-key.pem")),
- cert: await readFile(certificate),
- }, (_request, response) => { response.writeHead(404); response.end(); });
+ const requestHandler = (_request, response) => { response.writeHead(404); response.end(); };
+ const server = plainHttp
+ ? createHttpServer(requestHandler)
+ : createHttpsServer({
+ key: await readFile(join(certificates, "localhost-key.pem")),
+ cert: await readFile(certificate),
+ }, requestHandler);
const sockets = new Set();
const timers = new Set();
const errors = [];
@@ -34,7 +38,8 @@ export async function startLiveVoiceFixture(root) {
const held = holdNext;
holdNext = false;
try {
- assert.equal(new URL(request.url, "https://localhost").pathname, "/v1/realtime");
+ const base = plainHttp ? "http://127.0.0.1" : "https://localhost";
+ assert.equal(new URL(request.url, base).pathname, "/v1/realtime");
assert.equal(request.headers.authorization, "Bearer live-voice-e2e-key");
} catch { errors.push("unexpected Realtime connection metadata"); socket.close(); return; }
socket.once("close", () => { sockets.delete(socket); stats.closed++; });
@@ -74,8 +79,8 @@ export async function startLiveVoiceFixture(root) {
server.listen(0, "127.0.0.1", resolve);
});
return {
- certificate,
- baseUrl: `https://localhost:${server.address().port}/v1`,
+ certificate: plainHttp ? undefined : certificate,
+ baseUrl: `${plainHttp ? "http://127.0.0.1" : "https://localhost"}:${server.address().port}/v1`,
stats,
errors,
active: () => sockets.size,