The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: run Windows Desktop source checks through PM launcher
ethernet1695fab334a1
diff --git a/apps/desktop/electron/updater/checkout-legacy.test.ts b/apps/desktop/electron/updater/checkout-legacy.test.tsindex 0a376f26931..403ad3bc219 100644--- a/apps/desktop/electron/updater/checkout-legacy.test.ts+++ b/apps/desktop/electron/updater/checkout-legacy.test.ts@@ -92,3 +92,37 @@ it.skipIf(process.platform === 'win32')('uses the install-scoped PM launcher ratfs.rmSync(root, { recursive: true, force: true })}})++it.skipIf(process.platform !== 'win32')(+ 'runs a PM .cmd source check with quoted paths and refuses a missing launcher',+ async (): Promise<void> => {+ const root: string = fs.mkdtempSync(path.join(os.tmpdir(), 'pm source check '))+ const home: string = path.join(root, 'profile with spaces')+ const launcher: string = path.join(root, '.hermes', 'bin', 'hermes.cmd')+ fs.mkdirSync(path.dirname(launcher), { recursive: true })+ fs.mkdirSync(path.join(root, 'pm'))+ fs.mkdirSync(home)+ fs.writeFileSync(+ launcher,+ '@echo off\r\nif not "%~1"=="--run-module" exit /b 5\r\nif not "%~2"=="hermes_cli.source_check" exit /b 6\r\necho {"supported":true,"channel":"stable","behind":-1}\r\n'+ )++ 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 })+ await expect(readSourceUpdate({ ...probe, branch: 'main&echo INJECTED' })).rejects.toThrow(+ 'unsafe Windows command argument'+ )+ 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.tsindex 746c6339aef..0a0171cbdf6 100644--- a/apps/desktop/electron/updater/checkout-source.ts+++ b/apps/desktop/electron/updater/checkout-source.ts@@ -45,10 +45,10 @@ export function sourceUpdateEnvironment(updateRoot: string, hermesHome: string):export async function readSourceUpdate(probe: SourceUpdateProbe): Promise<SourceUpdate | null> {// 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+ const managed = existsSync(path.join(probe.updateRoot, 'pm'))+ const launcher = managed+ ? resolveInstallationLauncher(probe.updateRoot, process.platform === 'win32', probe.hermesHome)+ : nullif (managed && !launcher) {throw new Error('The source installation launcher is missing; repair this installation before checking updates.')@@ -58,35 +58,46 @@ export async function readSourceUpdate(probe: SourceUpdateProbe): Promise<Sourcethrow new Error('No Python interpreter is available to check the source update channel.')}+ const args: string[] = [+ ...(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',+ probe.hermesHome,+ '--git',+ probe.git,+ ...(probe.branch ? ['--branch', probe.branch] : []),+ ...(probe.channel ? ['--channel', probe.channel] : []),+ ...(probe.force ? ['--force'] : []),+ ...(probe.cachePath ? ['--cache-path', probe.cachePath] : []),+ ...(probe.branchConfigPath ? ['--branch-config-path', probe.branchConfigPath] : [])+ ]+ const command: string = (managed ? launcher : probe.python)!+ const viaCmd: boolean = process.platform === 'win32' && /\.cmd$/i.test(command)+ // Node refuses direct .cmd execFile; shell:true interpolates untrusted branch+ // and path arguments. Keep cmd.exe's one unavoidable parse fail-closed.+ if (viaCmd && [command, ...args].some((value: string): boolean => /["%&|<>^\r\n]/.test(value))) {+ throw new Error('The source check contains an unsafe Windows command argument.')+ }const result: { stdout: string; stderr: string } = await execute(- (managed ? launcher : probe.python)!,- [- ...(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',- probe.hermesHome,- '--git',- probe.git,- ...(probe.branch ? ['--branch', probe.branch] : []),- ...(probe.channel ? ['--channel', probe.channel] : []),- ...(probe.force ? ['--force'] : []),- ...(probe.cachePath ? ['--cache-path', probe.cachePath] : []),- ...(probe.branchConfigPath ? ['--branch-config-path', probe.branchConfigPath] : [])- ],+ viaCmd ? (process.env.ComSpec ?? 'cmd.exe') : command,+ viaCmd+ ? ['/d', '/v:off', '/s', '/c', `""${command}" ${args.map((arg: string): string => `"${arg}"`).join(' ')}"`]+ : args,hiddenWindowsChildOptions({cwd: probe.updateRoot,env: sourceUpdateEnvironment(probe.updateRoot, probe.hermesHome),encoding: 'utf8',timeout: 360000,- maxBuffer: 1024 * 1024+ maxBuffer: 1024 * 1024,+ windowsVerbatimArguments: viaCmd}))@@ -106,4 +117,4 @@ export async function readSourceUpdate(probe: SourceUpdateProbe): Promise<Source}return selection-}+}\ No newline at end of filediff --git a/tests-js/update-ui.test.mjs b/tests-js/update-ui.test.mjsindex 88ad3637a90..8a8f3ae1caa 100644--- a/tests-js/update-ui.test.mjs+++ b/tests-js/update-ui.test.mjs@@ -100,6 +100,12 @@ test('test-only source probe pins staged main without changing other Python invoexpect(sourceBranchProbe.branchProbeArgs(['--run-module', 'hermes_cli.config', ...managed.slice(2)], root, '/real/git')).toEqual(['--run-module', 'hermes_cli.config', ...managed.slice(2)])expect(sourceBranchProbe.branchProbeArgs([...probe, '--branch', 'topic'], root, '/real/git')).toEqual([...probe, '--branch', 'topic'])expect(sourceBranchProbe.branchProbeArgs(probe, root, '')).toBe(probe)+ const cmd = ['/d', '/v:off', '/s', '/c', `""C:\\fixture\\hermes.cmd" "--run-module" "hermes_cli.source_check" "--install-root" "${root}" "--home" "/profile with spaces" "--git" "/shim/git" "--force""`]+ const rewritten = sourceBranchProbe.branchProbeArgs(cmd, root, '/real/git')+ expect(rewritten.slice(0, 4)).toEqual(cmd.slice(0, 4))+ expect(rewritten[4]).toContain('"--git" "/real/git" "--force" "--branch" "main"')+ expect(sourceBranchProbe.branchProbeArgs(cmd, '/other/install', '/real/git')).toBe(cmd)+ expect(sourceBranchProbe.branchProbeArgs(cmd, root, '/real&git')).toBe(cmd)})test.skipIf(process.platform === 'win32')('probe Git reaches the staged main even with global Git config isolated', () => {@@ -168,4 +174,4 @@ test('does not turn a completed check without an update into success', async ()expect(f.clicks).toEqual(['Check now'])expect(f.log).toHaveBeenCalledWith('[update-status] {"supported":true,"behind":0}')expect(f.shot).toHaveBeenCalledWith(f.page, 'ERROR-no-update-now')-})+})\ No newline at end of filediff --git a/tests/install/e2e-assets/source-branch-probe.cjs b/tests/install/e2e-assets/source-branch-probe.cjsindex 4c40052f893..556668a4707 100644--- a/tests/install/e2e-assets/source-branch-probe.cjs+++ b/tests/install/e2e-assets/source-branch-probe.cjs@@ -46,6 +46,22 @@ function prepareSourceBranchEnvironment(root, expectedSha, realGit, capturedEnv,function branchProbeArgs(args, root, realGit) {if (!root || !realGit || !Array.isArray(args)) return args+ // PM .cmd launchers are passed to cmd.exe as one screened command string.+ // Limit the test-only rewrite to that exact shape; keep every other cmd call intact.+ if (args.length === 5 && args.slice(0, 4).join(' ') === '/d /v:off /s /c') {+ const command = args[4]+ if (+ typeof command !== 'string' ||+ /["%&|<>^\r\n]/.test(realGit) ||+ !/^""[^"\r\n]+\.cmd" "--run-module" "hermes_cli\.source_check" /i.test(command) ||+ !command.includes(`"--install-root" "${root}"`) ||+ command.includes('"--branch"') ||+ !command.endsWith('"') ||+ [...command.matchAll(/"--git" "[^"\r\n]+"/g)].length !== 1+ ) return args+ const selected = command.slice(0, -1).replace(/"--git" "[^"\r\n]+"/, `"--git" "${realGit}"`) + ' "--branch" "main""'+ return [...args.slice(0, 4), selected]+ }const legacy = args[0] === '-c' && args[1]?.includes('runpy.run_path(str(p))')&& args[1]?.includes('hermes_cli/source_check.py')const managed = args[0] === '--run-module' && args[1] === 'hermes_cli.source_check'@@ -72,4 +88,4 @@ if (process.env.HERMES_E2E_SOURCE_ROOT && process.env.HERMES_E2E_SOURCE_GIT) {syncBuiltinESMExports()}-module.exports = { branchProbeArgs, prepareSourceBranchEnvironment, sourceProbeGit }+module.exports = { branchProbeArgs, prepareSourceBranchEnvironment, sourceProbeGit }\ No newline at end of file