b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
87 lines
3.5 KiB
TypeScript
87 lines
3.5 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import { test } from 'node:test'
|
|
|
|
import { expandWindowsEnvRefs, parseRegQueryValue, readWindowsUserEnvVar } from './windows-user-env'
|
|
|
|
// ── 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)
|
|
})
|