mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-18 09:51:59 +00:00
A GUI app launched from Explorer inherits the environment block captured at login, so a HERMES_HOME set via 'setx' AFTER login is invisible in process.env even though the CLI (a fresh shell) sees it. The desktop then silently fell back to %LOCALAPPDATA%\hermes and reported 'No inference provider configured' despite a valid configured home (#45471). resolveHermesHome() now consults the live HKCU\Environment registry value on Windows before the LOCALAPPDATA default. New windows-user-env.cjs helper parses 'reg query' output, expands %VAR% refs, and fails safe (returns null off-Windows, on spawn error, or empty value). The registry value is normalized through the same normalizeHermesHomeRoot() path as the env var for consistency. Co-authored-by: jeffrobodie-glitch <jeffrobodie@gmail.com>
90 lines
3.5 KiB
JavaScript
90 lines
3.5 KiB
JavaScript
const assert = require('node:assert/strict')
|
|
const { test } = require('node:test')
|
|
|
|
const {
|
|
expandWindowsEnvRefs,
|
|
parseRegQueryValue,
|
|
readWindowsUserEnvVar
|
|
} = require('./windows-user-env.cjs')
|
|
|
|
// ── parseRegQueryValue ─────────────────────────────────────────────────────
|
|
|
|
test('parseRegQueryValue extracts a REG_SZ value', () => {
|
|
const out = [
|
|
'',
|
|
'HKEY_CURRENT_USER\\Environment',
|
|
' HERMES_HOME REG_SZ F:\\Hermes\\data',
|
|
''
|
|
].join('\r\n')
|
|
assert.equal(parseRegQueryValue(out, 'HERMES_HOME'), 'F:\\Hermes\\data')
|
|
})
|
|
|
|
test('parseRegQueryValue matches the name case-insensitively', () => {
|
|
const out = 'HKEY_CURRENT_USER\\Environment\r\n Hermes_Home REG_EXPAND_SZ %USERPROFILE%\\h\r\n'
|
|
assert.equal(parseRegQueryValue(out, 'HERMES_HOME'), '%USERPROFILE%\\h')
|
|
})
|
|
|
|
test('parseRegQueryValue preserves spaces inside the value', () => {
|
|
const out = ' HERMES_HOME REG_SZ C:\\Program Files\\Hermes\r\n'
|
|
assert.equal(parseRegQueryValue(out, 'HERMES_HOME'), 'C:\\Program Files\\Hermes')
|
|
})
|
|
|
|
test('parseRegQueryValue returns null when the value line is absent', () => {
|
|
const out = 'HKEY_CURRENT_USER\\Environment\r\n Path REG_SZ C:\\x\r\n'
|
|
assert.equal(parseRegQueryValue(out, 'HERMES_HOME'), null)
|
|
assert.equal(parseRegQueryValue('', 'HERMES_HOME'), null)
|
|
assert.equal(parseRegQueryValue('garbage', 'HERMES_HOME'), null)
|
|
})
|
|
|
|
// ── expandWindowsEnvRefs ───────────────────────────────────────────────────
|
|
|
|
test('expandWindowsEnvRefs expands %VAR% case-insensitively', () => {
|
|
assert.equal(
|
|
expandWindowsEnvRefs('%UserProfile%\\h', { USERPROFILE: 'C:\\Users\\jeff' }),
|
|
'C:\\Users\\jeff\\h'
|
|
)
|
|
})
|
|
|
|
test('expandWindowsEnvRefs leaves literal paths and unknown refs intact', () => {
|
|
assert.equal(expandWindowsEnvRefs('F:\\Hermes\\data', {}), 'F:\\Hermes\\data')
|
|
assert.equal(expandWindowsEnvRefs('%NOPE%\\x', {}), '%NOPE%\\x')
|
|
})
|
|
|
|
// ── readWindowsUserEnvVar ──────────────────────────────────────────────────
|
|
|
|
test('readWindowsUserEnvVar returns null off Windows without spawning', () => {
|
|
let spawned = false
|
|
const exec = () => {
|
|
spawned = true
|
|
return ''
|
|
}
|
|
assert.equal(readWindowsUserEnvVar('HERMES_HOME', { platform: 'linux', exec }), null)
|
|
assert.equal(spawned, false)
|
|
})
|
|
|
|
test('readWindowsUserEnvVar queries HKCU\\Environment and expands the value', () => {
|
|
const calls = []
|
|
const exec = (cmd, args) => {
|
|
calls.push([cmd, args])
|
|
return 'HKEY_CURRENT_USER\\Environment\r\n HERMES_HOME REG_EXPAND_SZ %DRIVE%\\Hermes\r\n'
|
|
}
|
|
const value = readWindowsUserEnvVar('HERMES_HOME', {
|
|
platform: 'win32',
|
|
env: { DRIVE: 'F:' },
|
|
exec
|
|
})
|
|
assert.equal(value, 'F:\\Hermes')
|
|
assert.deepEqual(calls, [['reg', ['query', 'HKCU\\Environment', '/v', 'HERMES_HOME']]])
|
|
})
|
|
|
|
test('readWindowsUserEnvVar returns null when reg exits non-zero (value missing)', () => {
|
|
const exec = () => {
|
|
throw new Error('reg exited 1')
|
|
}
|
|
assert.equal(readWindowsUserEnvVar('HERMES_HOME', { platform: 'win32', exec }), null)
|
|
})
|
|
|
|
test('readWindowsUserEnvVar returns null for an empty value', () => {
|
|
const exec = () => ' HERMES_HOME REG_SZ \r\n'
|
|
assert.equal(readWindowsUserEnvVar('HERMES_HOME', { platform: 'win32', exec }), null)
|
|
})
|