Skip to content

The agent that grows with you

fix(desktop): resolve the pre-launch home through the shared resolver

Brooklyn Nicholson89cc403b2317
diff --git a/apps/desktop/electron/entry.ts b/apps/desktop/electron/entry.ts
index 63998750250..2b0c151c70e 100644
--- a/apps/desktop/electron/entry.ts
+++ b/apps/desktop/electron/entry.ts
@@ -4,18 +4,24 @@ import path from 'node:path'
import { app } from 'electron'
+import { resolveDesktopHermesHome } from './data-paths'
import { readDesktopLaunchConfig } from './renderer-heap-flags'
import { wslgLaunchArgs } from './wslg-launch'
import { spawnWslgLaunch } from './wslg-launch-process'
function configuredElectronFlags(env: NodeJS.ProcessEnv): string[] {
- const raw = env.HERMES_HOME
-
- const home = raw
- ? path.resolve(raw === '~' || raw.startsWith('~/') ? path.join(os.homedir(), raw.slice(1)) : raw)
- : env.HERMES_DESKTOP_USER_DATA_DIR
- ? path.join(path.resolve(env.HERMES_DESKTOP_USER_DATA_DIR), 'hermes-home')
- : path.join(os.homedir(), '.hermes')
+ // Resolve the home exactly like main.ts does, through the shared resolver:
+ // HERMES_DATA_DIR_SUFFIX channel installs and profiles/-rooted HERMES_HOME
+ // values must pick the same config.yaml before the relaunch and inside the
+ // app, or desktop.electron_flags silently never reaches the relaunch.
+ const home = resolveDesktopHermesHome({
+ home: os.homedir(),
+ env,
+ // Linux-only pre-launch path; the win32 legacy-migration probe is never
+ // consulted on posix, so its directoryExists callback is not needed here.
+ directoryExists: () => false,
+ readWindowsHome: () => null
+ })
try {
return readDesktopLaunchConfig(readFileSync(path.join(home, 'config.yaml'), 'utf8')).electronFlags
diff --git a/apps/desktop/scripts/bundle-electron-main.test.mjs b/apps/desktop/scripts/bundle-electron-main.test.mjs
index f5a95546e56..10865b6a45f 100644
--- a/apps/desktop/scripts/bundle-electron-main.test.mjs
+++ b/apps/desktop/scripts/bundle-electron-main.test.mjs
@@ -58,7 +58,7 @@ beforeAll(async () => {
afterAll(() => rmSync(root, { recursive: true, force: true }))
-function launch(env, config) {
+function launch(env, config, extraEnv = {}) {
const home = mkdtempSync(join(root, 'home-'))
if (config) {
@@ -73,7 +73,8 @@ function launch(env, config) {
PATH: process.env.PATH,
HERMES_HOME: home,
NODE_OPTIONS: `--import=${pathToFileURL(preload).href}`,
- ...env
+ ...env,
+ ...extraEnv
}
})
@@ -99,3 +100,36 @@ test('the bundled entry lets desktop.electron_flags choose the ozone platform',
relaunched: ['.', '--ozone-platform=x11']
})
})
+
+// The bundled entry must read config.yaml from the same home main.ts does
+// (resolveDesktopHermesHome), or desktop.electron_flags set for the real
+// profile silently never reaches the relaunch. The two cases below are the
+// ones the inline resolution in configuredElectronFlags() got wrong: the
+// data-dir suffix channel installs rely on, and multiplexed profiles/ homes.
+test('the bundled entry reads desktop.electron_flags through a suffixed home', () => {
+ const config = 'desktop:\n electron_flags:\n - --ozone-platform=x11\n'
+ const home = mkdtempSync(join(root, 'suffixed-home-'))
+ mkdirSync(join(home, '.hermes-canary'), { recursive: true })
+ writeFileSync(join(home, '.hermes-canary', 'config.yaml'), config)
+
+ expect(
+ launch({ XDG_SESSION_TYPE: 'wayland', WAYLAND_DISPLAY: 'wayland-0', DISPLAY: ':0' }, undefined, {
+ HERMES_DATA_DIR_SUFFIX: '-canary',
+ HERMES_HOME: '',
+ HOME: home
+ })
+ ).toEqual({ relaunched: ['.', '--ozone-platform=x11'] })
+})
+
+test('the bundled entry reads desktop.electron_flags from the parent of a profiles/-rooted HERMES_HOME', () => {
+ const config = 'desktop:\n electron_flags:\n - --ozone-platform=x11\n'
+ const home = mkdtempSync(join(root, 'profiles-home-'))
+ mkdirSync(home, { recursive: true })
+ writeFileSync(join(home, 'config.yaml'), config)
+
+ expect(
+ launch({ XDG_SESSION_TYPE: 'wayland', WAYLAND_DISPLAY: 'wayland-0', DISPLAY: ':0' }, undefined, {
+ HERMES_HOME: join(home, 'profiles', 'alpha')
+ })
+ ).toEqual({ relaunched: ['.', '--ozone-platform=x11'] })
+})