Skip to content

The agent that grows with you

fix: run Desktop source checks through PM installation launcher

ethernet099addd62850
diff --git a/apps/desktop/electron/updater/checkout-legacy.test.ts b/apps/desktop/electron/updater/checkout-legacy.test.ts
index b5a937c8631..90333232701 100644
--- a/apps/desktop/electron/updater/checkout-legacy.test.ts
+++ b/apps/desktop/electron/updater/checkout-legacy.test.ts
@@ -73,3 +73,21 @@ it('offers manual recovery only for a missing source probe, never for a broken p
fs.rmSync(root, { recursive: true, force: true })
}
})
+
+it.skipIf(process.platform === 'win32')('uses the install-scoped PM launcher rather than a system Python for source checks', async (): Promise<void> => {
+ const root: string = fs.mkdtempSync(path.join(os.tmpdir(), 'pm-source-check-'))
+ const home: string = path.join(root, 'profile')
+ const launcher: string = path.join(root, '.hermes', 'bin', 'hermes')
+ fs.mkdirSync(path.dirname(launcher), { recursive: true })
+ fs.mkdirSync(path.join(root, 'pm'))
+ fs.mkdirSync(home)
+ fs.writeFileSync(launcher, '#!/bin/sh\n[ "$1" = --run-module ] && [ "$2" = hermes_cli.source_check ] || exit 5\nprintf \'%s\\n\' \'{"supported":true,"channel":"stable","behind":-1}\'\n', { mode: 0o755 })
+ try {
+ const probe = { python: '/nonexistent/system-python', git: 'git', updateRoot: root, hermesHome: home, channel: 'stable' as const }
+ await expect(readSourceUpdate(probe)).resolves.toMatchObject({ supported: true, channel: 'stable', behind: null })
+ fs.rmSync(launcher)
+ await expect(readSourceUpdate(probe)).rejects.toThrow('installation launcher is missing')
+ } finally {
+ fs.rmSync(root, { recursive: true, force: true })
+ }
+})
diff --git a/apps/desktop/electron/updater/checkout-source.ts b/apps/desktop/electron/updater/checkout-source.ts
index 9db5013e4c7..1214941010b 100644
--- a/apps/desktop/electron/updater/checkout-source.ts
+++ b/apps/desktop/electron/updater/checkout-source.ts
@@ -1,7 +1,10 @@
import { execFile } from 'node:child_process'
+import { existsSync } from 'node:fs'
+import path from 'node:path'
import { promisify } from 'node:util'
import { buildDesktopBackendEnv } from '../backend-env'
+import { resolveInstallationLauncher } from '../updater-process'
import { hiddenWindowsChildOptions } from '../windows-child-options'
import type { UpdaterStatusWire } from './index'
@@ -40,17 +43,30 @@ export function sourceUpdateEnvironment(updateRoot: string, hermesHome: string):
/** Python owns config identity and publication checks; this bridge only transports them. */
export async function readSourceUpdate(probe: SourceUpdateProbe): Promise<SourceUpdate | null> {
- if (!probe.python) {
+ // The install launcher boots PM's committed Python and dependency generation.
+ // A PATH Python can import this checkout yet lack its selected dependencies.
+ // Windows command launchers have a separate shell transport; retain their
+ // existing path until that transport is migrated.
+ const managed = process.platform !== 'win32' && existsSync(path.join(probe.updateRoot, 'pm'))
+ const launcher = managed ? resolveInstallationLauncher(probe.updateRoot, false, probe.hermesHome) : null
+ if (managed && !launcher) {
+ throw new Error('The source installation launcher is missing; repair this installation before checking updates.')
+ }
+ if (!managed && !probe.python) {
throw new Error('No Python interpreter is available to check the source update channel.')
}
const result: { stdout: string; stderr: string } = await execute(
- probe.python,
+ (managed ? launcher : probe.python)!,
[
- '-c',
- // Inspect the target checkout's callable, not stderr strings or an editable
- // install elsewhere on sys.path. Exceptions inside a present probe propagate.
- 'from pathlib import Path; import runpy; p = Path("hermes_cli/source_check.py"); entry = runpy.run_path(str(p)).get("main") if p.is_file() else None; entry() if callable(entry) else print("null")',
+ ...(managed
+ ? ['--run-module', 'hermes_cli.source_check']
+ : [
+ '-c',
+ // Inspect the target checkout's callable, not stderr strings or an editable
+ // install elsewhere on sys.path. Exceptions inside a present probe propagate.
+ 'from pathlib import Path; import runpy; p = Path("hermes_cli/source_check.py"); entry = runpy.run_path(str(p)).get("main") if p.is_file() else None; entry() if callable(entry) else print("null")'
+ ]),
'--install-root',
probe.updateRoot,
'--home',