From c22ecb2c4c555b739d4736ad04c1f5cb024bbfd9 Mon Sep 17 00:00:00 2001 From: "zenbu-bot[bot]" <5532934+zenbu-bot[bot]@users.noreply.github.com> Date: Fri, 30 Oct 2026 21:09:40 +0000 Subject: [PATCH] Set ELECTRON_RUN_AS_NODE=1 in the --split window command Fixes #36 [skip ci] --- src/launch.ts | 5 +++- test/split-window-env.test.js | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 test/split-window-env.test.js diff --git a/src/launch.ts b/src/launch.ts index 1577fa7..0c58f65 100644 --- a/src/launch.ts +++ b/src/launch.ts @@ -25,8 +25,11 @@ export interface LaunchOptions { partition?: string; } +// A split pane starts with the terminal's environment, not ours, so the +// shim's ELECTRON_RUN_AS_NODE=1 does not reach it. Without it Electron boots +// Chromium instead of node; `env` sets it for any terminal's split. function windowCommand(url: string, options: LaunchOptions): string[] { - const command = [process.execPath, path.resolve(__dirname, "main.js"), "--window", url]; + const command = ["/usr/bin/env", "ELECTRON_RUN_AS_NODE=1", process.execPath, path.resolve(__dirname, "main.js"), "--window", url]; if (options.proxy) command.push(`--proxy=${options.proxy}`); if (options.partition) command.push(`--partition=${options.partition}`); return command; diff --git a/test/split-window-env.test.js b/test/split-window-env.test.js new file mode 100644 index 0000000..fc98d29 --- /dev/null +++ b/test/split-window-env.test.js @@ -0,0 +1,43 @@ +const assert = require("node:assert/strict"); +const path = require("node:path"); +const { test } = require("node:test"); + +// Swap pixel's terminal module for a fake Ghostty that records the command +// --split hands to the new pane, so no real terminal is needed. +const terminalPath = require.resolve("@zenbu-labs/pixel/terminal", { paths: [path.join(__dirname, "..", "dist")] }); +const real = require(terminalPath); +const splits = []; +const fakeGhostty = { + name: "ghostty", + getCurrentPane: async () => ({ id: "pane-1", tab: "1:1", tty: "/dev/ttys001", command: null }), + split: async (request) => { + splits.push(request); + }, +}; +require.cache[terminalPath].exports = { + ...real, + detect: () => fakeGhostty, + canSplit: () => true, + findOwner: () => null, + callerTty: () => ({ path: "/dev/ttys001" }), +}; + +const { Pane } = require("../dist/launch.js"); + +test("--split starts the window process with ELECTRON_RUN_AS_NODE=1", async () => { + delete process.env.PIXEL_EMBED; + const pane = new Pane({ split: "right" }); + pane.open("http://127.0.0.1:8080/"); + assert.equal(await pane.exited(), 0); + assert.equal(splits.length, 1); + const command = splits[0].command; + // A Ghostty split pane gets Ghostty's environment, not the caller's, so the + // shim's `export ELECTRON_RUN_AS_NODE=1` does not reach it. Without it, + // process.execPath (Electron Helper) boots Chromium instead of node. + const exec = command.indexOf(process.execPath); + assert.ok(exec >= 0, `command runs process.execPath: ${JSON.stringify(command)}`); + assert.ok( + command.slice(0, exec).includes("ELECTRON_RUN_AS_NODE=1"), + `split command must set ELECTRON_RUN_AS_NODE=1 before ${process.execPath}, got ${JSON.stringify(command)}`, + ); +});