Skip to content

The agent that grows with you

fix(desktop): quote a spaced Windows install path in gateway ensure

Teknium2e6d4fe0bbb0
diff --git a/apps/desktop/electron/local-gateway.test.ts b/apps/desktop/electron/local-gateway.test.ts
index b5cd444d155..525c9ccc5d7 100644
--- a/apps/desktop/electron/local-gateway.test.ts
+++ b/apps/desktop/electron/local-gateway.test.ts
@@ -1,4 +1,4 @@
-import { expect, test } from 'vitest'
+import { expect, test, vi } from 'vitest'
import { createLocalGatewayDials, ensureLocalGateway, routedGatewayEndpoint, runGatewayEnsure } from './local-gateway'
@@ -16,6 +16,32 @@ test('the ensure client inherits the caller-scrubbed parent env, not the raw Des
expect(JSON.parse(result.stdout)).toEqual({ leak: null, home: '/home/x/.hermes', own: '1' })
})
+test('a shell-delegated ensure quotes a spaced Windows install path (#74064)', async () => {
+ // cmd.exe cuts an unquoted `C:\Users\John Doe\...\hermes.cmd` at the first space.
+ const spawned: string[] = []
+ vi.resetModules()
+ vi.doMock('node:child_process', () => ({
+ spawn: (command: string) => {
+ spawned.push(command)
+ throw new Error('stop after spawn')
+ }
+ }))
+ const platform = Object.getOwnPropertyDescriptor(process, 'platform')!
+ Object.defineProperty(process, 'platform', { value: 'win32' })
+
+ try {
+ const { runGatewayEnsure: ensure } = await import('./local-gateway')
+ const command = 'C:\\Users\\John Doe\\AppData\\Local\\hermes\\hermes.cmd'
+ await expect(ensure({ command, args: ['gateway', 'ensure'], env: {}, shell: true }, 'C:\\', 'C:\\h')).rejects.toThrow('stop after spawn')
+ await expect(ensure({ command, args: [], env: {}, shell: false }, 'C:\\', 'C:\\h')).rejects.toThrow('stop after spawn')
+ expect(spawned).toEqual([`"${command}"`, command])
+ } finally {
+ Object.defineProperty(process, 'platform', platform)
+ vi.doUnmock('node:child_process')
+ vi.resetModules()
+ }
+})
+
test('canonical ensure cannot cross a rejected update or profile lifecycle gate', async () => {
let ran = false
await expect(ensureLocalGateway(async () => { ran = true;
diff --git a/apps/desktop/electron/local-gateway.ts b/apps/desktop/electron/local-gateway.ts
index ba607583865..088ae7fee3f 100644
--- a/apps/desktop/electron/local-gateway.ts
+++ b/apps/desktop/electron/local-gateway.ts
@@ -1,13 +1,15 @@
import { spawn } from 'node:child_process'
import crypto from 'node:crypto'
-import { hiddenWindowsChildOptions } from './windows-child-options'
+import { hiddenWindowsChildOptions, windowsShellCommand } from './windows-child-options'
export function runGatewayEnsure(
backend, cwd: string, home: string, parentEnv: NodeJS.ProcessEnv = process.env
): Promise<{ code: number; stdout: string; stderr: string }> {
return new Promise((resolve, reject) => {
- const child = spawn(backend.command, backend.args, hiddenWindowsChildOptions({ cwd, env: { ...parentEnv, HERMES_HOME: home, ...backend.env }, shell: backend.shell, stdio: ['ignore', 'pipe', 'pipe'] }))
+ // shell: true hands cmd.exe one command line it cuts at the first unquoted space,
+ // so an install under `C:\Users\John Doe\...` must arrive quoted (#74064).
+ const child = spawn(windowsShellCommand(backend.command, Boolean(backend.shell)), backend.args, hiddenWindowsChildOptions({ cwd, env: { ...parentEnv, HERMES_HOME: home, ...backend.env }, shell: backend.shell, stdio: ['ignore', 'pipe', 'pipe'] }))
let stdout = ''
let stderr = ''
// Only the bounded ensure client is ours. Never retain/kill its detached owner.