mirror of
https://github.com/stablyai/orca.git
synced 2026-10-24 08:03:58 +00:00
fix(pi): validate inherited status owner pid markers
This commit is contained in:
@@ -6,7 +6,13 @@ describe('getPiAgentStatusExtensionSource', () => {
|
||||
it('registers Prime hooks only in the event-emitting daemon worker', () => {
|
||||
const frontend = createHarness({
|
||||
kind: 'prime-agent',
|
||||
env: { PRIME_AGENT_INTERNAL_DAEMON_WORKER: undefined }
|
||||
env: {
|
||||
PRIME_AGENT_INTERNAL_DAEMON_WORKER: undefined,
|
||||
ORCA_PRIME_AGENT_STATUS_OWNED: String(SELF_PID - 1)
|
||||
},
|
||||
killImpl: () => {
|
||||
throw Object.assign(new Error('ESRCH'), { code: 'ESRCH' })
|
||||
}
|
||||
})
|
||||
const worker = createHarness({
|
||||
kind: 'prime-agent',
|
||||
@@ -14,7 +20,8 @@ describe('getPiAgentStatusExtensionSource', () => {
|
||||
})
|
||||
|
||||
expect(frontend.handlers).toEqual({})
|
||||
expect(frontend.processEnv.ORCA_PI_STATUS_OWNED).toBeUndefined()
|
||||
expect(frontend.killMock).not.toHaveBeenCalled()
|
||||
expect(frontend.processEnv.ORCA_PRIME_AGENT_STATUS_OWNED).toBe(String(SELF_PID - 1))
|
||||
expect(worker.handlers.agent_start).toBeTypeOf('function')
|
||||
expect(worker.processEnv.ORCA_PRIME_AGENT_STATUS_OWNED).toBe(String(SELF_PID))
|
||||
})
|
||||
@@ -322,6 +329,30 @@ describe('getPiAgentStatusExtensionSource', () => {
|
||||
expect(harness.processEnv.ORCA_PI_STATUS_OWNED).toBe(String(SELF_PID))
|
||||
})
|
||||
|
||||
it('claims the pane when the inherited owner PID exceeds safe integer precision', () => {
|
||||
const harness = createHarness({
|
||||
kind: 'pi',
|
||||
pid: SELF_PID,
|
||||
env: { ORCA_PI_STATUS_OWNED: '99999999999999999999999' }
|
||||
})
|
||||
|
||||
expect(harness.killMock).not.toHaveBeenCalled()
|
||||
expect(harness.handlers.agent_end).toBeTypeOf('function')
|
||||
expect(harness.processEnv.ORCA_PI_STATUS_OWNED).toBe(String(SELF_PID))
|
||||
})
|
||||
|
||||
it('claims the pane when the inherited owner PID exceeds the process API range', () => {
|
||||
const harness = createHarness({
|
||||
kind: 'pi',
|
||||
pid: SELF_PID,
|
||||
env: { ORCA_PI_STATUS_OWNED: String(2 ** 31) }
|
||||
})
|
||||
|
||||
expect(harness.killMock).not.toHaveBeenCalled()
|
||||
expect(harness.handlers.agent_end).toBeTypeOf('function')
|
||||
expect(harness.processEnv.ORCA_PI_STATUS_OWNED).toBe(String(SELF_PID))
|
||||
})
|
||||
|
||||
it.each(['pi', 'omp', 'prime-agent'] as const)(
|
||||
'registers no status handlers for a nested %s subagent process',
|
||||
(kind) => {
|
||||
|
||||
@@ -66,7 +66,7 @@ export function getPiAgentStatusHandlerSourceLines(kind: PiAgentKind): string[]
|
||||
'// import (the extension loads inside pi/omp with no Orca deps).',
|
||||
'function isStatusOwnerAlive(pid: string): boolean {',
|
||||
' const parsed = Number(pid)',
|
||||
' if (!Number.isInteger(parsed) || parsed < 1) return false',
|
||||
' if (!Number.isSafeInteger(parsed) || parsed < 1 || parsed > 0x7fffffff) return false',
|
||||
" if (typeof process.kill !== 'function') return true",
|
||||
' try {',
|
||||
' process.kill(parsed, 0)',
|
||||
|
||||
Reference in New Issue
Block a user