Files
hermes-agent/apps/desktop/vitest.hermes-python.ts
T
Maciej Lisiewski c5a7e48c12 test(desktop): vitest resolves HERMES_PYTHON from the checkout's test env
The electron contracts that drive real hermes_cli/pm code read
HERMES_PYTHON, which CI exports from setup-pm's test environment. A plain
`npx vitest run` outside that environment left it unset: mac-sign threw
"need HERMES_PYTHON" (2 tests), and source-backend / checkout-source fell
back to the PATH python3, which has no ruamel (2 tests). The electron
project's global setup now resolves __HERMES_TEST_PYTHON through
scripts/run-in-hermes-env, the same path scripts/run_tests.sh takes,
unless HERMES_PYTHON is already set. It is scoped to that project so a
UI-only run never waits on a Python environment sync. POSIX only; Windows
keeps the CI-provided value.
2026-10-15 21:34:21 +02:00

33 lines
1.2 KiB
TypeScript

/**
* HERMES_PYTHON for the electron contracts that drive real hermes_cli / pm code
* (mac-sign, source-backend, checkout-source). CI exports the PM test
* environment's interpreter; a developer's plain `npx vitest` does not, and the
* PATH python3 lacks the application dependencies. Resolve the checkout's test
* interpreter the way scripts/run_tests.sh does. Workers inherit process.env.
*/
import { execFileSync } from 'node:child_process'
import path from 'node:path'
const repo = path.resolve(import.meta.dirname, '../..')
export default function setup(): void {
if (process.env.HERMES_PYTHON || process.platform === 'win32') {
return
}
try {
const python = execFileSync(
'bash',
[path.join(repo, 'scripts', 'run-in-hermes-env'), 'sh', '-c', 'printf %s "$__HERMES_TEST_PYTHON"'],
{ cwd: repo, encoding: 'utf8', stdio: ['ignore', 'pipe', 'inherit'] }
)
if (python) {
process.env.HERMES_PYTHON = python
}
} catch (error: unknown) {
// Electron tests that need no Python still run; only the contracts above fail, naming HERMES_PYTHON.
console.warn(`vitest: could not resolve the Hermes test interpreter: ${String(error)}`)
}
}