Skip to content

The agent that grows with you

fix(desktop): E2E and harness launches leave the OS hermes:// handler alone

Tekniumab9633b0af43
diff --git a/apps/desktop/e2e/core/harness.ts b/apps/desktop/e2e/core/harness.ts
index f6cf1e2e4f1..7e2a4b6b8cf 100644
--- a/apps/desktop/e2e/core/harness.ts
+++ b/apps/desktop/e2e/core/harness.ts
@@ -220,6 +220,8 @@ export function coreAppEnv(sandbox: CoreSandbox, extra: Record<string, string> =
...(process.env.HERMES_E2E_PYTHON ? { HERMES_DESKTOP_PYTHON: process.env.HERMES_E2E_PYTHON } : {}),
HERMES_DESKTOP_APP_NAME: `HermesCoreE2E-${path.basename(sandbox.root)}`,
HERMES_DESKTOP_SKIP_QUIT_CONFIRM: '1',
+ // Never repoint the user's OS hermes:// handler (HKCU on Windows) at a test checkout.
+ HERMES_DESKTOP_SKIP_PROTOCOL_REGISTRATION: '1',
HERMES_DESKTOP_CDP_PORT: 'off',
// A partial-clone (blob:none) dev checkout turns some backend git read into
// a lazy `git fetch origin` over the network, which outlived quit by >60 s
diff --git a/apps/desktop/e2e/fixtures.ts b/apps/desktop/e2e/fixtures.ts
index bef7e304b51..fd1a73a244d 100644
--- a/apps/desktop/e2e/fixtures.ts
+++ b/apps/desktop/e2e/fixtures.ts
@@ -216,6 +216,8 @@ export function buildAppEnv(sandbox: Sandbox, extra: Record<string, string> = {}
// mid-flight — otherwise the quit confirmation waits on a click that no
// one is there to make, and the worker dies on a teardown timeout.
HERMES_DESKTOP_SKIP_QUIT_CONFIRM: '1',
+ // Never repoint the user's OS hermes:// handler (HKCU on Windows) at a test checkout.
+ HERMES_DESKTOP_SKIP_PROTOCOL_REGISTRATION: '1',
// Clear dev-server override — we want the built dist/, not a vite server.
// The dev-server check in main.ts looks for this env var; if it's set,
// it loads from the vite URL instead of the local file.
diff --git a/apps/desktop/e2e/update/harness.ts b/apps/desktop/e2e/update/harness.ts
index fbf64939feb..7c4e8273444 100644
--- a/apps/desktop/e2e/update/harness.ts
+++ b/apps/desktop/e2e/update/harness.ts
@@ -201,6 +201,8 @@ export function appEnv(facts: InstallFacts, extra: Record<string, string> = {}):
...displayEnv(),
HERMES_DESKTOP_USER_DATA_DIR: userDataDir(facts),
HERMES_DESKTOP_SKIP_QUIT_CONFIRM: '1',
+ // Never repoint the user's OS hermes:// handler (HKCU on Windows) at a test checkout.
+ HERMES_DESKTOP_SKIP_PROTOCOL_REGISTRATION: '1',
HERMES_DESKTOP_CDP_PORT: 'off',
...extra
}
diff --git a/apps/desktop/electron/deep-link-protocol.test.ts b/apps/desktop/electron/deep-link-protocol.test.ts
new file mode 100644
index 00000000000..a2dd14e7273
--- /dev/null
+++ b/apps/desktop/electron/deep-link-protocol.test.ts
@@ -0,0 +1,33 @@
+import assert from 'node:assert/strict'
+
+import { test } from 'vitest'
+
+import { registerDeepLinkProtocol } from './deep-link-protocol'
+
+function run(env: NodeJS.ProcessEnv, defaultApp = true) {
+ const calls: unknown[][] = []
+ const log: string[] = []
+ registerDeepLinkProtocol({
+ app: { setAsDefaultProtocolClient: (...args: unknown[]) => { calls.push(args);
+
+ return true } },
+ protocol: 'hermes',
+ env,
+ defaultApp,
+ argv: ['/electron', '.'],
+ execPath: '/electron',
+ resolve: entry => `/checkout/${entry}`,
+ log: line => log.push(line)
+ })
+
+ return { calls, log }
+}
+
+test('the E2E/dev guard leaves the OS hermes:// handler untouched; normal launches still register', () => {
+ const skipped = run({ HERMES_DESKTOP_SKIP_PROTOCOL_REGISTRATION: '1' })
+ assert.deepEqual(skipped.calls, [])
+ assert.match(skipped.log.join('\n'), /registration skipped/)
+
+ assert.deepEqual(run({}).calls, [['hermes', '/electron', ['/checkout/.']]])
+ assert.deepEqual(run({}, false).calls, [['hermes']])
+})
diff --git a/apps/desktop/electron/deep-link-protocol.ts b/apps/desktop/electron/deep-link-protocol.ts
new file mode 100644
index 00000000000..cd0e37347b0
--- /dev/null
+++ b/apps/desktop/electron/deep-link-protocol.ts
@@ -0,0 +1,48 @@
+/**
+ * `hermes://` deep-link registration. Every launch rewrites the OS handler (on Windows,
+ * HKCU\Software\Classes\<protocol>), so a test or dev run of an unpackaged checkout would
+ * repoint the user's installed handler at that checkout. `HERMES_DESKTOP_SKIP_PROTOCOL_REGISTRATION=1`
+ * (set by the E2E harnesses) leaves the OS registration untouched; deep links that arrive
+ * through argv / second-instance still route normally.
+ */
+
+export interface ProtocolRegistrar {
+ setAsDefaultProtocolClient: (protocol: string, path?: string, args?: string[]) => boolean
+}
+
+export interface DeepLinkProtocolOptions {
+ app: ProtocolRegistrar
+ protocol: string
+ env: NodeJS.ProcessEnv
+ /** `process.defaultApp`: running as `electron <dir>` rather than a packaged binary. */
+ defaultApp: boolean
+ argv: string[]
+ execPath: string
+ resolve: (entry: string) => string
+ log: (line: string) => void
+}
+
+export function registerDeepLinkProtocol(options: DeepLinkProtocolOptions): void {
+ const { app, protocol, env, defaultApp, argv, execPath, resolve, log } = options
+
+ if (env.HERMES_DESKTOP_SKIP_PROTOCOL_REGISTRATION === '1') {
+ log(`[deeplink] ${protocol}:// registration skipped (HERMES_DESKTOP_SKIP_PROTOCOL_REGISTRATION)`)
+
+ return
+ }
+
+ try {
+ if (defaultApp && argv.length >= 2) {
+ // Dev: register with the electron exec path + entry script so the OS can
+ // relaunch us with the URL. argv[1] is usually "." when launched via
+ // `electron .` from apps/desktop — resolve against cwd.
+ app.setAsDefaultProtocolClient(protocol, execPath, [resolve(argv[1])])
+ } else {
+ app.setAsDefaultProtocolClient(protocol)
+ }
+
+ log(`[deeplink] registered ${protocol}:// handler`)
+ } catch (err) {
+ log(`[deeplink] protocol registration failed: ${(err as Error).message}`)
+ }
+}
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index bd04d88fb02..aa20e0ee043 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -218,6 +218,7 @@ import { liveWindowState, overlayWindowState } from './connection-window-state'
import { describeCrashReason, installCrashForensics } from './crash-forensics'
import { adoptServedDashboardToken } from './dashboard-token'
import { resolveDesktopHermesHome, resolveDesktopUserData } from './data-paths'
+import { registerDeepLinkProtocol as registerDeepLinkProtocolWith } from './deep-link-protocol'
import { loadOrCreateInstallationId, sshOwnershipId } from './desktop-installation'
import { formatDesktopLogLine, formatLogStamp } from './desktop-log-line'
import {
@@ -18084,21 +18085,10 @@ ipcMain.handle('hermes:deep-link-ready', () => {
})
function registerDeepLinkProtocol() {
- try {
- if (process.defaultApp && process.argv.length >= 2) {
- // Dev: register with the electron exec path + entry script so the OS can
- // relaunch us with the URL. argv[1] is usually "." when launched via
- // `electron .` from apps/desktop — resolve against cwd.
- const entry = path.resolve(process.argv[1])
- app.setAsDefaultProtocolClient(HERMES_PROTOCOL, process.execPath, [entry])
- } else {
- app.setAsDefaultProtocolClient(HERMES_PROTOCOL)
- }
-
- rememberLog(`[deeplink] registered ${HERMES_PROTOCOL}:// handler`)
- } catch (err) {
- rememberLog(`[deeplink] protocol registration failed: ${err.message}`)
- }
+ registerDeepLinkProtocolWith({
+ app, protocol: HERMES_PROTOCOL, env: process.env, defaultApp: Boolean(process.defaultApp),
+ argv: process.argv, execPath: process.execPath, resolve: entry => path.resolve(entry), log: rememberLog
+ })
}
// macOS: register the deep link before the lock. Launch Services relaunches