mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-17 04:11:35 +00:00
The PM rework dropped the resolver's "existing hermes on PATH" rung, so Desktop only accepts HERMES_DESKTOP_HERMES or $HERMES_HOME/hermes-agent. A healthy install elsewhere (install.sh --dir, a setup-hermes.sh clone) now falls to bootstrap-needed and the first-run choice, offering to install a second copy. The old rung also read raw process.env.PATH, which a Finder/Dock launch inherits without ~/.local/bin. Add a rung before bootstrap-needed: probe the launcher published at its fixed user-bin location (~/.local/bin or $HERMES_HOME/bin; Windows: %LOCALAPPDATA%\hermes\bin), read the install directory its --version reports, and resolve that root through resolveSourceInstallationBackend, the same validated path ACTIVE_HERMES_ROOT uses. HERMES_DESKTOP_IGNORE_EXISTING and repair requests still skip it, and a miss is now logged instead of silent. The launcher lookup is shared with resolveInstallationLauncher. Fixes #73014 Co-authored-by: JonthanaHanh <[email protected]>
89 lines
3.2 KiB
TypeScript
89 lines
3.2 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import fs from 'node:fs'
|
|
import os from 'node:os'
|
|
import path from 'node:path'
|
|
|
|
import { afterEach, test, vi } from 'vitest'
|
|
|
|
import { resolveSourceInstallationBackend } from './source-backend'
|
|
import { userLauncherInstallRoot } from './updater-process'
|
|
|
|
afterEach((): void => {
|
|
vi.unstubAllEnvs()
|
|
})
|
|
|
|
function sourceTree(root: string): void {
|
|
fs.mkdirSync(path.join(root, 'hermes_cli'), { recursive: true })
|
|
fs.mkdirSync(path.join(root, 'pm'))
|
|
fs.writeFileSync(path.join(root, 'hermes_cli', 'main.py'), '')
|
|
fs.writeFileSync(path.join(root, 'hermes_cli', '_launchers.py'), '')
|
|
}
|
|
|
|
function publishLauncher(dir: string, reported: string): string {
|
|
fs.mkdirSync(dir, { recursive: true })
|
|
const launcher: string = path.join(dir, process.platform === 'win32' ? 'hermes.cmd' : 'hermes')
|
|
|
|
const body: string =
|
|
process.platform === 'win32'
|
|
? `@echo off\r\necho Install directory: ${reported}\r\n`
|
|
: `#!/bin/sh\nprintf '%s\\n' 'Install directory: ${reported}'\n`
|
|
|
|
fs.writeFileSync(launcher, body, { mode: 0o755 })
|
|
|
|
return launcher
|
|
}
|
|
|
|
// The reported machine: setup-hermes.sh published ~/.local/bin/hermes for a
|
|
// clone outside ~/.hermes/hermes-agent, and a Finder/Dock launch inherited
|
|
// launchd's PATH, which has no ~/.local/bin. Desktop must still find it.
|
|
test.skipIf(process.platform === 'win32')(
|
|
'a ~/.local/bin launcher resolves its non-canonical install on a GUI PATH without ~/.local/bin',
|
|
async (): Promise<void> => {
|
|
const base: string = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'user-launcher-')))
|
|
|
|
try {
|
|
const home: string = path.join(base, 'home')
|
|
const root: string = path.join(home, 'src', 'hermes-agent')
|
|
sourceTree(root)
|
|
const launcher: string = publishLauncher(path.join(home, '.local', 'bin'), root)
|
|
vi.stubEnv('HOME', home)
|
|
vi.stubEnv('PATH', '/usr/bin:/bin:/usr/sbin:/sbin')
|
|
|
|
const found = userLauncherInstallRoot(false, path.join(home, '.hermes'))
|
|
assert.deepEqual(found, { launcher, root })
|
|
|
|
const backend = await resolveSourceInstallationBackend(root, ['serve'], {
|
|
isWindows: false,
|
|
hermesHome: path.join(home, '.hermes')
|
|
})
|
|
|
|
assert.equal(backend?.command, launcher)
|
|
assert.equal(backend?.root, root)
|
|
assert.deepEqual(backend?.args, ['serve'])
|
|
} finally {
|
|
fs.rmSync(base, { recursive: true, force: true })
|
|
}
|
|
}
|
|
)
|
|
|
|
test('a user-bin launcher is ignored when it reports no Hermes source tree', (): void => {
|
|
const base: string = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'user-launcher-')))
|
|
|
|
try {
|
|
const home: string = path.join(base, 'home')
|
|
const hermesHome: string = path.join(home, '.hermes')
|
|
const notSource: string = path.join(base, 'elsewhere')
|
|
fs.mkdirSync(notSource)
|
|
publishLauncher(path.join(hermesHome, 'bin'), notSource)
|
|
vi.stubEnv('HOME', home)
|
|
vi.stubEnv('USERPROFILE', home)
|
|
vi.stubEnv('LOCALAPPDATA', path.join(home, 'AppData', 'Local'))
|
|
|
|
assert.equal(userLauncherInstallRoot(process.platform === 'win32', hermesHome), null)
|
|
|
|
sourceTree(notSource)
|
|
assert.equal(userLauncherInstallRoot(process.platform === 'win32', hermesHome)?.root, notSource)
|
|
} finally {
|
|
fs.rmSync(base, { recursive: true, force: true })
|
|
}
|
|
})
|