hermes-agent/apps/desktop/electron/windows-msys-bash-env.test.ts
islam 0f6554792f fix(desktop): set MSYS path-conversion guards in embedded terminal
Git Bash/MSYS rewrites slash-prefixed native flags such as tasklist /FI into bogus paths. Apply the same MSYS_NO_PATHCONV and MSYS2_ARG_CONV_EXCL setdefault defaults the Python terminal_tool already ships, in the Desktop PTY env.

Fixes #101826
2026-09-29 19:13:25 -05:00

73 lines
2.6 KiB
TypeScript

import assert from 'node:assert/strict'
import { test } from 'vitest'
import { applyWindowsMsysBashEnvDefaults } from './windows-msys-bash-env'
test('applyWindowsMsysBashEnvDefaults sets both MSYS opt-outs on Windows when unset', () => {
const env: NodeJS.ProcessEnv = { FOO: 'bar' }
const result = applyWindowsMsysBashEnvDefaults(env, true)
assert.equal(result, env)
assert.equal(env.MSYS_NO_PATHCONV, '1')
assert.equal(env.MSYS2_ARG_CONV_EXCL, '*')
assert.equal(env.FOO, 'bar')
})
test('applyWindowsMsysBashEnvDefaults preserves an existing MSYS_NO_PATHCONV on Windows', () => {
const env: NodeJS.ProcessEnv = { MSYS_NO_PATHCONV: '0' }
applyWindowsMsysBashEnvDefaults(env, true)
assert.equal(env.MSYS_NO_PATHCONV, '0')
assert.equal(env.MSYS2_ARG_CONV_EXCL, '*')
})
test('applyWindowsMsysBashEnvDefaults preserves an existing MSYS2_ARG_CONV_EXCL on Windows', () => {
const env: NodeJS.ProcessEnv = { MSYS2_ARG_CONV_EXCL: '/custom' }
applyWindowsMsysBashEnvDefaults(env, true)
assert.equal(env.MSYS_NO_PATHCONV, '1')
assert.equal(env.MSYS2_ARG_CONV_EXCL, '/custom')
})
test('applyWindowsMsysBashEnvDefaults preserves both existing MSYS opt-outs on Windows', () => {
const env: NodeJS.ProcessEnv = { MSYS_NO_PATHCONV: '', MSYS2_ARG_CONV_EXCL: '/FO' }
applyWindowsMsysBashEnvDefaults(env, true)
assert.equal(env.MSYS_NO_PATHCONV, '')
assert.equal(env.MSYS2_ARG_CONV_EXCL, '/FO')
})
test('applyWindowsMsysBashEnvDefaults is a no-op off Windows', () => {
const env: NodeJS.ProcessEnv = { FOO: 'bar' }
const result = applyWindowsMsysBashEnvDefaults(env, false)
assert.equal(result, env)
assert.deepEqual(env, { FOO: 'bar' })
})
test('applyWindowsMsysBashEnvDefaults leaves existing MSYS opt-outs unchanged off Windows', () => {
const env: NodeJS.ProcessEnv = { MSYS_NO_PATHCONV: '0', MSYS2_ARG_CONV_EXCL: '/custom' }
applyWindowsMsysBashEnvDefaults(env, false)
assert.deepEqual(env, { MSYS_NO_PATHCONV: '0', MSYS2_ARG_CONV_EXCL: '/custom' })
})
test('applyWindowsMsysBashEnvDefaults defaults isWindows from process.platform when omitted', () => {
const env: NodeJS.ProcessEnv = {}
applyWindowsMsysBashEnvDefaults(env)
if (process.platform === 'win32') {
assert.equal(env.MSYS_NO_PATHCONV, '1')
assert.equal(env.MSYS2_ARG_CONV_EXCL, '*')
} else {
assert.equal(Object.hasOwn(env, 'MSYS_NO_PATHCONV'), false)
assert.equal(Object.hasOwn(env, 'MSYS2_ARG_CONV_EXCL'), false)
}
})
test('applyWindowsMsysBashEnvDefaults does not throw on a shallow clone of process.env', () => {
assert.doesNotThrow(() => {
applyWindowsMsysBashEnvDefaults({ ...process.env }, true)
})
})