fix: time out computer permission helper launch (#3810)
This commit is contained in:
@@ -66,6 +66,7 @@ describe('openComputerUsePermissions', () => {
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers()
|
||||
setPlatform(originalPlatform)
|
||||
})
|
||||
|
||||
@@ -260,6 +261,48 @@ describe('openComputerUsePermissions', () => {
|
||||
expect(child.off).toHaveBeenCalledWith('close', expect.any(Function))
|
||||
})
|
||||
|
||||
it('times out when the permission status helper launch never closes', async () => {
|
||||
vi.useFakeTimers()
|
||||
const { getComputerUsePermissionStatus } = await import('./macos-computer-use-permissions')
|
||||
resolveHelperAppPathMock.mockReturnValue('/Applications/Orca Computer Use.app')
|
||||
const child = {
|
||||
stdout: { off: vi.fn(), on: vi.fn(), setEncoding: vi.fn() },
|
||||
stderr: { off: vi.fn(), on: vi.fn(), setEncoding: vi.fn() },
|
||||
on: vi.fn(() => child),
|
||||
off: vi.fn(() => child),
|
||||
kill: vi.fn(),
|
||||
unref: vi.fn()
|
||||
}
|
||||
vi.mocked(spawn).mockImplementationOnce(() => child as unknown as ReturnType<typeof spawn>)
|
||||
|
||||
let settled = false
|
||||
const statusPromise = getComputerUsePermissionStatus().then(
|
||||
(status) => {
|
||||
settled = true
|
||||
return status
|
||||
},
|
||||
(error: unknown) => {
|
||||
settled = true
|
||||
throw error
|
||||
}
|
||||
)
|
||||
const rejection = expect(statusPromise).rejects.toMatchObject({
|
||||
name: 'RuntimeClientError',
|
||||
code: 'accessibility_error',
|
||||
message: 'Timed out launching permission helper'
|
||||
})
|
||||
|
||||
await vi.advanceTimersByTimeAsync(5000)
|
||||
|
||||
expect(settled).toBe(true)
|
||||
await rejection
|
||||
expect(child.kill).toHaveBeenCalled()
|
||||
expect(rm).toHaveBeenCalledWith('/tmp/orca-computer-use-permissions-test', {
|
||||
recursive: true,
|
||||
force: true
|
||||
})
|
||||
})
|
||||
|
||||
it('reads permission status through the helper app identity', async () => {
|
||||
const { getComputerUsePermissionStatus } = await import('./macos-computer-use-permissions')
|
||||
resolveHelperAppPathMock.mockReturnValue('/Applications/Orca Computer Use.app')
|
||||
|
||||
@@ -19,6 +19,7 @@ import type {
|
||||
} from '../../shared/computer-use-permissions-types'
|
||||
|
||||
const DEFAULT_COMPUTER_USE_BUNDLE_ID = 'com.stablyai.orca.computer-use'
|
||||
const PERMISSION_STATUS_HELPER_LAUNCH_TIMEOUT_MS = 5_000
|
||||
|
||||
export function openComputerUsePermissions(
|
||||
permissionId?: ComputerUsePermissionId
|
||||
@@ -242,11 +243,16 @@ function launchPermissionStatusHelper(helperAppPath: string, statusPath: string)
|
||||
stderr += chunk
|
||||
}
|
||||
let settled = false
|
||||
let launchTimeout: ReturnType<typeof setTimeout> | null = null
|
||||
const removeListeners = (): void => {
|
||||
launch.stdout?.off('data', onStdoutData)
|
||||
launch.stderr?.off('data', onStderrData)
|
||||
launch.off('error', onError)
|
||||
launch.off('close', onClose)
|
||||
if (launchTimeout) {
|
||||
clearTimeout(launchTimeout)
|
||||
launchTimeout = null
|
||||
}
|
||||
}
|
||||
const settleResolve = (): void => {
|
||||
if (settled) {
|
||||
@@ -282,6 +288,18 @@ function launchPermissionStatusHelper(helperAppPath: string, statusPath: string)
|
||||
new RuntimeClientError('accessibility_error', `Could not check permissions: ${detail}`)
|
||||
)
|
||||
}
|
||||
const onTimeout = (): void => {
|
||||
launch.kill()
|
||||
settleReject(
|
||||
new RuntimeClientError('accessibility_error', 'Timed out launching permission helper')
|
||||
)
|
||||
}
|
||||
// Why: the status-file polling timeout only starts after `open` exits; if
|
||||
// `open` wedges first, permission checks would otherwise stay pending.
|
||||
launchTimeout = setTimeout(onTimeout, PERMISSION_STATUS_HELPER_LAUNCH_TIMEOUT_MS)
|
||||
if (typeof launchTimeout.unref === 'function') {
|
||||
launchTimeout.unref()
|
||||
}
|
||||
launch.stdout?.on('data', onStdoutData)
|
||||
launch.stderr?.on('data', onStderrData)
|
||||
launch.on('error', onError)
|
||||
|
||||
Reference in New Issue
Block a user