fix false missing Hermes CLI detection after deployment
This commit is contained in:
@@ -4,12 +4,14 @@ import { tmpdir } from 'os'
|
||||
import { join } from 'path'
|
||||
|
||||
const execFileCalls = vi.hoisted(() => [] as Array<{ command: string; args: string[]; options: any }>)
|
||||
const execResult = vi.hoisted(() => ({ error: null as any, delayMs: 0 }))
|
||||
const spawnCalls = vi.hoisted(() => [] as Array<{ command: string; args: string[]; options: any }>)
|
||||
|
||||
vi.mock('child_process', () => ({
|
||||
execFile: vi.fn((command: string, args: string[], options: any, callback: (error: Error | null, stdout: string, stderr: string) => void) => {
|
||||
execFileCalls.push({ command, args, options })
|
||||
callback(null, 'ok\n', '')
|
||||
if (execResult.delayMs) setTimeout(() => callback(execResult.error, 'ok\n', ''), execResult.delayMs)
|
||||
else callback(execResult.error, 'ok\n', '')
|
||||
}),
|
||||
spawn: vi.fn((command: string, args: string[], options: any) => {
|
||||
spawnCalls.push({ command, args, options })
|
||||
@@ -24,6 +26,9 @@ function setPlatform(platform: NodeJS.Platform): void {
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
execResult.error = null
|
||||
execResult.delayMs = 0
|
||||
vi.useRealTimers()
|
||||
execFileCalls.length = 0
|
||||
spawnCalls.length = 0
|
||||
delete process.env.HERMES_AGENT_BRIDGE_PYTHON
|
||||
@@ -122,3 +127,31 @@ describe('Hermes process invocation', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Hermes installation probe', () => {
|
||||
it('uses local help instead of the network-dependent version check and accepts slow startup', async () => {
|
||||
vi.useFakeTimers()
|
||||
execResult.delayMs = 7800
|
||||
const { probeHermesCli } = await import('../../packages/server/src/services/hermes/hermes-process')
|
||||
const pending = probeHermesCli('/opt/hermes/bin/hermes')
|
||||
await vi.advanceTimersByTimeAsync(7800)
|
||||
await expect(pending).resolves.toEqual({ available: true, reason: 'ready' })
|
||||
expect(execFileCalls[0]).toMatchObject({ args: ['--help'], options: { timeout: 15000 } })
|
||||
})
|
||||
|
||||
it.each([
|
||||
[{ code: 'ENOENT' }, 'missing'],
|
||||
[{ code: 'ENOTDIR' }, 'missing'],
|
||||
[{ code: 127 }, 'missing'],
|
||||
[{ code: 'EACCES' }, 'permission_denied'],
|
||||
[{ code: 'EPERM' }, 'permission_denied'],
|
||||
[{ code: 126 }, 'permission_denied'],
|
||||
[{ killed: true, signal: 'SIGTERM' }, 'timeout'],
|
||||
[{ code: 'ETIMEDOUT' }, 'timeout'],
|
||||
[{ code: 1 }, 'failed'],
|
||||
])('distinguishes %j from a missing installation', async (error, reason) => {
|
||||
execResult.error = error
|
||||
const { probeHermesCli } = await import('../../packages/server/src/services/hermes/hermes-process')
|
||||
await expect(probeHermesCli('hermes')).resolves.toEqual({ available: false, reason })
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user