mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-29 11:42:04 +00:00
Bring apps/desktop and ui-tui to a clean state for typecheck, eslint,
and prettier:
- Run prettier across both trees (printWidth/wrap drift; prettier is not
CI-enforced for these JS projects, so main had accumulated drift).
- Apply eslint --fix for padding-line-between-statements and perfectionist
import/export sorting.
- Manual fixes for non-auto-fixable rules:
- remove unused node:net import in electron/main.cjs (uses Electron net)
- replace inline `typeof import(...)` annotations with top-level
`import type * as EnvModule` in two ui-tui test files
- scoped eslint-disable no-control-regex on intentional sentinel/ANSI
regexes (mathUnicode.ts, text.ts)
- resolve react-hooks/exhaustive-deps per-case: correct swapped/missing
deps, collapse redundant session.* members, and justified disables on
settings mount-only data-load effects to preserve run-once behavior
No behavior changes; test pass/fail counts are unchanged from the main
baseline.
78 lines
3.5 KiB
JavaScript
78 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)
|
|
})
|