Files
orca/mobile/src/session/mobile-cursor-command.test.ts
T
Jinjing a07efd89fb feat(ai-vault): add cursor command cache with host isolation
Cursor command detection is expensive—spawning a shell process or making
an SSH RPC. Cache detected commands with a 30-second TTL and keep entries
separate per host (SSH connection, WSL distro, local) to avoid repeated
probes and ensure each host resolves correctly. Thread wslDistro through
mobile resume targets so session resumption identifies the right host.
2026-08-05 12:48:01 -07:00

60 lines
1.9 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest'
import { RESUME_RPC_TIMEOUT_MS } from './ai-vault-resume-preparation'
import { resolveMobileCursorCommand } from './mobile-cursor-command'
describe('resolveMobileCursorCommand', () => {
it('preserves the host-matched Cursor command', async () => {
const sendRequest = vi.fn().mockResolvedValue({
ok: true,
result: {
version: 1,
agents: ['cursor'],
matchedCommands: { cursor: 'cursor agent' }
}
})
await expect(resolveMobileCursorCommand({ client: { sendRequest } })).resolves.toBe(
'cursor agent'
)
expect(sendRequest).toHaveBeenCalledWith('preflight.detectAgentInventory', undefined, {
timeoutMs: RESUME_RPC_TIMEOUT_MS
})
})
it('fails closed without a valid inventory unless an override exists', async () => {
const sendRequest = vi.fn().mockResolvedValue({ ok: false })
await expect(resolveMobileCursorCommand({ client: { sendRequest } })).resolves.toBeNull()
sendRequest.mockRejectedValueOnce(new Error('offline'))
await expect(
resolveMobileCursorCommand({
client: { sendRequest },
settings: { agentCmdOverrides: { cursor: 'cursor-dev' } }
})
).resolves.toBe('cursor-dev')
expect(sendRequest).toHaveBeenCalledTimes(1)
})
it('requests inventory from the exact WSL distro context', async () => {
const sendRequest = vi.fn().mockResolvedValue({
ok: true,
result: {
version: 1,
agents: ['cursor'],
matchedCommands: { cursor: 'cursor agent' }
}
})
await expect(
resolveMobileCursorCommand({
client: { sendRequest },
wslDistro: ' Ubuntu '
})
).resolves.toBe('cursor agent')
expect(sendRequest).toHaveBeenCalledWith(
'preflight.detectAgentInventory',
{ wslDistro: 'Ubuntu' },
{ timeoutMs: RESUME_RPC_TIMEOUT_MS }
)
})
})