fix(cli): bound orchestration ask timeouts (#10689)
* fix(cli): bound orchestration ask timeouts * fix(cli): harden remote timeout boundaries
This commit is contained in:
@@ -19,6 +19,9 @@ import {
|
||||
resolveHostCliKillTimeoutMs,
|
||||
runHostOrcaCliPassthrough
|
||||
} from './ssh-remote-cli-host-passthrough'
|
||||
import { resolveOrchestrationAskClientTimeoutMs } from '../../shared/orchestration-ask-timeout'
|
||||
import { remoteCliRequestTimeoutMs } from '../../relay/remote-cli-timeout'
|
||||
import { MAX_TIMER_DELAY_MS } from '../../shared/timer-delay'
|
||||
|
||||
type FakeChild = EventEmitter & {
|
||||
stdout: EventEmitter
|
||||
@@ -96,6 +99,74 @@ describe('resolveHostCliKillTimeoutMs', () => {
|
||||
)
|
||||
expect(resolveHostCliKillTimeoutMs(['worktree', 'list'])).toBe(600_000)
|
||||
})
|
||||
|
||||
it.each([
|
||||
[[], 720_000],
|
||||
[['--timeout-ms', String(Number.MAX_SAFE_INTEGER)], 1_920_000],
|
||||
[['--timeout-ms', String(Number.MAX_SAFE_INTEGER + 1)], 720_000],
|
||||
[['--timeout-ms', '9007199254740991.1'], 720_000],
|
||||
[['--timeout-ms', '1', '--timeout-ms=1800000'], 1_920_000],
|
||||
[['--timeout-ms=1800000', '--timeout-ms', '1'], 600_000],
|
||||
[['--timeout-ms', '1800000', '--timeout-ms'], 720_000],
|
||||
[['--timeout-ms=1800000', '--timeout-ms='], 720_000],
|
||||
[['--timeout-ms=1800000', '--timeout-ms', 'bad'], 720_000],
|
||||
[['--timeout-ms', 'bad', '--timeout-ms=1800000'], 1_920_000],
|
||||
[['--timeout-ms=bad', '--timeout-ms', '1800000'], 1_920_000]
|
||||
])('bounds ask child timers with last-wins flags %#', (timeoutArgs, expected) => {
|
||||
expect(resolveHostCliKillTimeoutMs(['orchestration', '--json', 'ask', ...timeoutArgs])).toBe(
|
||||
expected
|
||||
)
|
||||
})
|
||||
|
||||
it('does not apply the ask maximum to other commands', () => {
|
||||
expect(resolveHostCliKillTimeoutMs(['terminal', 'wait', '--timeout-ms', '1800001'])).toBe(
|
||||
1_920_001
|
||||
)
|
||||
})
|
||||
|
||||
it.each(['+1000000', '1000000.0', '1e6'])(
|
||||
'extends non-ask child timers using CLI-compatible integer syntax %s',
|
||||
(raw) => {
|
||||
expect(resolveHostCliKillTimeoutMs(['terminal', 'wait', '--timeout-ms', raw])).toBe(1_120_000)
|
||||
}
|
||||
)
|
||||
|
||||
it.each([
|
||||
'Infinity',
|
||||
'1.5',
|
||||
'-1',
|
||||
'bad',
|
||||
String(Number.MAX_SAFE_INTEGER),
|
||||
String(MAX_TIMER_DELAY_MS - 120_000 + 1)
|
||||
])('falls back to the default kill timer when a non-ask --timeout-ms %s is unusable', (raw) => {
|
||||
expect(resolveHostCliKillTimeoutMs(['terminal', 'wait', '--timeout-ms', raw])).toBe(600_000)
|
||||
})
|
||||
|
||||
it('keeps the largest non-ask kill timer that stays inside the timer range', () => {
|
||||
expect(
|
||||
resolveHostCliKillTimeoutMs([
|
||||
'terminal',
|
||||
'wait',
|
||||
'--timeout-ms',
|
||||
String(MAX_TIMER_DELAY_MS - 120_000)
|
||||
])
|
||||
).toBe(MAX_TIMER_DELAY_MS)
|
||||
})
|
||||
|
||||
it.each<[string[], number | undefined]>([
|
||||
[[], undefined],
|
||||
[['--timeout-ms', '1'], 1],
|
||||
[['--timeout-ms', String(Number.MAX_SAFE_INTEGER)], Number.MAX_SAFE_INTEGER],
|
||||
[['--timeout-ms', String(Number.MAX_SAFE_INTEGER + 1)], undefined]
|
||||
])('keeps inner, host, and relay ask deadlines ordered %#', (timeoutArgs, parsedTimeout) => {
|
||||
const argv = ['orchestration', 'ask', '--to', 'term_x', ...timeoutArgs]
|
||||
const innerTimeout = resolveOrchestrationAskClientTimeoutMs(parsedTimeout)
|
||||
const hostTimeout = resolveHostCliKillTimeoutMs(argv)
|
||||
const relayTimeout = remoteCliRequestTimeoutMs({ argv })
|
||||
|
||||
expect(innerTimeout).toBeLessThan(hostTimeout)
|
||||
expect(hostTimeout).toBeLessThan(relayTimeout!)
|
||||
})
|
||||
})
|
||||
|
||||
describe('runHostOrcaCliPassthrough', () => {
|
||||
@@ -191,6 +262,17 @@ describe('runHostOrcaCliPassthrough', () => {
|
||||
expect(spawn).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('rejects an invalid injected kill timeout before spawning', async () => {
|
||||
const spawn = vi.fn()
|
||||
await expect(
|
||||
runHostOrcaCliPassthrough(
|
||||
{ argv: ['status'], cwd: '/', env: {} },
|
||||
{ ...BASE_OPTIONS, spawn: spawn as never, killTimeoutMs: 2_147_483_648 }
|
||||
)
|
||||
).rejects.toBeInstanceOf(RangeError)
|
||||
expect(spawn).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('throws HostCliUnavailableError when the subprocess fails to launch', async () => {
|
||||
const child = createFakeChild()
|
||||
const spawn = vi.fn(() => child)
|
||||
|
||||
Reference in New Issue
Block a user