From 2ac8a4867389dfdbf870cf4ecfe3a94725908ef1 Mon Sep 17 00:00:00 2001 From: Samuel K <69881238+skevetter@users.noreply.github.com> Date: Tue, 29 Sep 2026 00:02:15 -0600 Subject: [PATCH] fix(desktop): start local terminals in user home --- desktop/src/main/__tests__/pty.test.ts | 29 ++++++++++++++++++++++++++ desktop/src/main/pty.ts | 8 ++++--- 2 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 desktop/src/main/__tests__/pty.test.ts diff --git a/desktop/src/main/__tests__/pty.test.ts b/desktop/src/main/__tests__/pty.test.ts new file mode 100644 index 0000000000..96c43b5912 --- /dev/null +++ b/desktop/src/main/__tests__/pty.test.ts @@ -0,0 +1,29 @@ +import { homedir, platform } from "node:os" +import type { IPty } from "node-pty" +import { describe, expect, it, vi } from "vitest" +import { PtyManager } from "../pty.js" + +describe("PtyManager", () => { + it("starts local shells in the user's home directory", () => { + const proc = { + onData: vi.fn(), + onExit: vi.fn(), + } as unknown as IPty + const spawnPty = vi.fn(() => proc) + const manager = new PtyManager({ + binaryPath: "/devsy", + getMainWindow: () => null, + spawnPty, + }) + + manager.createSession(80, 24) + + expect(spawnPty).toHaveBeenCalledWith( + platform() === "win32" + ? "powershell.exe" + : process.env.SHELL || "/bin/sh", + [], + expect.objectContaining({ cwd: homedir(), cols: 80, rows: 24 }), + ) + }) +}) diff --git a/desktop/src/main/pty.ts b/desktop/src/main/pty.ts index c8cf3b5db6..1a2441a276 100644 --- a/desktop/src/main/pty.ts +++ b/desktop/src/main/pty.ts @@ -1,4 +1,4 @@ -import { platform } from "node:os" +import { homedir, platform } from "node:os" import { dirname } from "node:path" import type { BrowserWindow } from "electron" import type { IPty } from "node-pty" @@ -25,6 +25,7 @@ function requirePty(): typeof import("node-pty") { interface PtyDeps { binaryPath: string getMainWindow: () => BrowserWindow | null + spawnPty?: typeof import("node-pty").spawn } export class PtyManager { @@ -60,15 +61,16 @@ export class PtyManager { } createSession(cols: number, rows: number): string { - const pty = requirePty() + const spawn = this.deps.spawnPty ?? requirePty().spawn const shell = platform() === "win32" ? "powershell.exe" : process.env.SHELL || "/bin/sh" const sessionId = crypto.randomUUID() - const proc = pty.spawn(shell, [], { + const proc = spawn(shell, [], { name: "xterm-256color", cols, rows, + cwd: homedir(), env: this.env, })