hermes-agent/apps/desktop/electron/renderer-heap-flags.test.ts
Austin Pickett a35f600b8a fix(desktop): resolve the Windows ssh client instead of hard-coding System32 OpenSSH
All ssh spawns (the -G config probe, the ssh-config:resolve IPC, SSH
terminals, and SshConnection) now go through one pure resolver:
desktop.ssh_path in config.yaml, then System32 OpenSSH, then Git for
Windows' usr\bin\ssh.exe, then bare ssh. Non-Windows keeps bare ssh.

A failed local ssh -G probe is now tagged terminal: boot latches on the
failure overlay (naming the client and the ssh_path setting) instead of
re-driving the same probe every ~2s.

Fixes #103288
2026-09-29 22:56:15 -04:00

103 lines
5 KiB
TypeScript

// #77311: the renderer heap ceiling knob (`desktop.renderer_max_old_space_mb`)
// and `desktop.electron_flags` must reach app.commandLine on packaged launches
// that never go through the `hermes desktop` launcher.
import { describe, expect, it, vi } from 'vitest'
import { planLaunchSwitches, readDesktopLaunchConfig } from './renderer-heap-flags'
describe('renderer heap flags', () => {
it('reads both launch keys from config.yaml and plans a well-formed js-flags switch', () => {
const cfg = readDesktopLaunchConfig(
[
'model:',
' default: x',
'desktop:',
' font_family: ""',
' electron_flags:',
' - --ozone-platform=x11',
' - "--js-flags=--expose-gc"',
' renderer_max_old_space_mb: 2048 # ceiling',
'terminal:',
' electron_flags: [--not-desktop]'
].join('\n')
)
expect(cfg).toEqual({
electronFlags: ['--ozone-platform=x11', '--js-flags=--expose-gc'],
rendererMaxOldSpaceMb: 2048
})
expect(planLaunchSwitches(cfg)).toEqual([
{ name: 'ozone-platform', value: 'x11' },
{ name: 'js-flags', value: '--expose-gc --max-old-space-size=2048' }
])
// Default 0 = Chromium's own heap limit, nothing applied.
expect(planLaunchSwitches(readDesktopLaunchConfig('desktop:\n renderer_max_old_space_mb: 0\n'))).toEqual([])
})
it('merges with a js-flags switch already on argv instead of overwriting it', () => {
const cfg = readDesktopLaunchConfig(
'desktop:\n electron_flags: [--disable-gpu]\n renderer_max_old_space_mb: 1536\n'
)
const planned = planLaunchSwitches(cfg, ['/app/hermes', '--js-flags=--expose-gc', '--disable-gpu'])
// --disable-gpu is already on the launcher's argv: not re-applied.
expect(planned).toEqual([{ name: 'js-flags', value: '--expose-gc --max-old-space-size=1536' }])
// Space-separated is the same switch: the argv value must reach the merge
// (and win the ceiling) rather than being scanned as a switch of its own.
expect(planLaunchSwitches(cfg, ['/app/hermes', '--js-flags', '--max-old-space-size=4096'])).toEqual([
{ name: 'disable-gpu' },
{ name: 'js-flags', value: '--max-old-space-size=4096' }
])
})
it('reads the renderer_accessibility opt-out for packaged launches (#118271)', () => {
expect(readDesktopLaunchConfig('desktop:\n renderer_accessibility: false\n').rendererAccessibility).toBe(false)
expect(readDesktopLaunchConfig('desktop:\n renderer_accessibility: "off" # perf\n').rendererAccessibility).toBe(
false
)
expect(readDesktopLaunchConfig('desktop:\n renderer_accessibility: true\n').rendererAccessibility).toBe(true)
// Bare `0` is the string '0' to this reader (no YAML parser), but the
// unquoted form a user actually writes must opt out like the quoted one.
expect(readDesktopLaunchConfig('desktop:\n renderer_accessibility: 0\n').rendererAccessibility).toBe(false)
// `disabled`/`enabled` mirror the launcher's word list so both launch
// paths accept the same vocabulary (#118271 review).
expect(readDesktopLaunchConfig('desktop:\n renderer_accessibility: disabled\n').rendererAccessibility).toBe(false)
expect(readDesktopLaunchConfig('desktop:\n renderer_accessibility: "Disabled"\n').rendererAccessibility).toBe(
false
)
expect(readDesktopLaunchConfig('desktop:\n renderer_accessibility: enabled\n').rendererAccessibility).toBe(true)
// Absent or unreadable: unset, so the app keeps its own default.
expect(readDesktopLaunchConfig('desktop:\n font_family: ""\n').rendererAccessibility).toBeUndefined()
expect(readDesktopLaunchConfig('desktop:\n renderer_accessibility: maybe\n').rendererAccessibility).toBeUndefined()
})
it('warns once when a desktop block names the keys in an indentation it cannot read', () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined)
// Valid YAML, unsupported subset (four-space keys / two-space list items).
expect(readDesktopLaunchConfig('desktop:\n renderer_max_old_space_mb: 2048\n')).toEqual({
electronFlags: [],
rendererMaxOldSpaceMb: 0
})
expect(warn).toHaveBeenCalledTimes(1)
// A desktop block that never mentions them is not a misconfiguration.
readDesktopLaunchConfig('desktop:\n font_family: ""\n')
expect(warn).toHaveBeenCalledTimes(1)
warn.mockRestore()
})
it('#103288: reads desktop.ssh_path as plain, single-quoted, and YAML double-quoted scalars', () => {
const read = (value: string) =>
readDesktopLaunchConfig(['desktop:', ` ssh_path: ${value}`, 'terminal:', ' ssh_path: nope'].join('\n')).sshPath
expect(read('C:\\Program Files\\Git\\usr\\bin\\ssh.exe')).toBe('C:\\Program Files\\Git\\usr\\bin\\ssh.exe')
expect(read("'C:\\Git\\usr\\bin\\ssh.exe' # Git's client")).toBe('C:\\Git\\usr\\bin\\ssh.exe')
expect(read('"C:\\\\Git\\\\usr\\\\bin\\\\ssh.exe"')).toBe('C:\\Git\\usr\\bin\\ssh.exe')
expect(read('""')).toBeUndefined()
expect(readDesktopLaunchConfig('terminal:\n ssh_path: C:\\x.exe').sshPath).toBeUndefined()
})
})