35 lines
1.6 KiB
TypeScript
35 lines
1.6 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
const request = vi.hoisted(() => vi.fn())
|
|
vi.mock('@/api/client', () => ({ request }))
|
|
|
|
beforeEach(() => { vi.resetModules(); request.mockReset() })
|
|
|
|
describe('CLI installation guard', () => {
|
|
it('does not send a slow, installed CLI to the installation page', async () => {
|
|
request.mockResolvedValue({ available: false, reason: 'timeout' })
|
|
const api = await import('@/api/hermes/system')
|
|
expect(await api.checkHermesCliAvailable()).toBe(true)
|
|
expect(await api.getHermesCliStatus()).toMatchObject({ reason: 'timeout' })
|
|
expect(request).toHaveBeenCalledOnce()
|
|
})
|
|
|
|
it.each(['missing', 'permission_denied', 'failed'])('retains a genuine %s error and bypasses server cache on retry', async reason => {
|
|
request.mockResolvedValueOnce({ available: false, reason }).mockResolvedValueOnce({ available: true, reason: 'ready' })
|
|
const api = await import('@/api/hermes/system')
|
|
expect(await api.checkHermesCliAvailable()).toBe(false)
|
|
api.resetHermesCliProbe()
|
|
expect(await api.checkHermesCliAvailable()).toBe(true)
|
|
expect(request).toHaveBeenLastCalledWith('/api/hermes/cli-status?refresh=1')
|
|
})
|
|
|
|
it('continues to work with older servers and transport errors', async () => {
|
|
const api = await import('@/api/hermes/system')
|
|
request.mockResolvedValueOnce({ available: false })
|
|
expect(await api.checkHermesCliAvailable()).toBe(false)
|
|
api.resetHermesCliProbe()
|
|
request.mockRejectedValueOnce(new Error('server restarting'))
|
|
expect(await api.checkHermesCliAvailable()).toBe(true)
|
|
})
|
|
})
|