Files
orca/src/shared/foreground-wrapper-agent.test.ts
T

76 lines
2.6 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
resolveOuterWrapperForegroundIdentity,
resolveOuterWrapperForegroundProcess
} from './foreground-wrapper-agent'
describe('resolveOuterWrapperForegroundProcess', () => {
const omp = { agent: 'omp' as const, processName: 'omp' }
const pi = { agent: 'pi' as const, processName: 'pi' }
it('collapses a wrapped pi read onto the shallower omp wrapper', () => {
expect(
resolveOuterWrapperForegroundProcess(pi, { pid: 102, ppid: 101, command: 'pi' }, [
{ pid: 102, ppid: 101, command: 'pi' },
{ pid: 101, ppid: 100, command: 'omp' }
])
).toBe('omp')
})
it('keeps bare pi when no same-group wrapper is present', () => {
const barePi = { pid: 101, ppid: 100, command: 'pi' }
expect(resolveOuterWrapperForegroundProcess(pi, barePi, [barePi])).toBe('pi')
})
it('keeps Codex identity beneath a shell parent', () => {
const codex = { agent: 'codex' as const, processName: 'codex' }
expect(
resolveOuterWrapperForegroundProcess(
codex,
{ pid: 102, ppid: 101, command: 'node /usr/bin/codex' },
[
{ pid: 102, ppid: 101, command: 'node /usr/bin/codex' },
{ pid: 101, ppid: 100, command: 'bash -l' }
]
)
).toBe('codex')
})
it('does not promote a deeper pi over an already-outer omp winner', () => {
expect(
resolveOuterWrapperForegroundProcess(omp, { pid: 101, ppid: 100, command: 'omp' }, [
{ pid: 101, ppid: 100, command: 'omp' },
{ pid: 102, ppid: 101, command: 'pi' }
])
).toBe('omp')
})
it('does not treat an unrelated shallower omp sibling as the pi wrapper', () => {
expect(
resolveOuterWrapperForegroundProcess(pi, { pid: 103, ppid: 102, command: 'pi' }, [
{ pid: 101, ppid: 100, command: 'omp' },
{ pid: 102, ppid: 100, command: 'node server.js' },
{ pid: 103, ppid: 102, command: 'pi' }
])
).toBe('pi')
})
it('carries the wrapper pid with a collapsed name, so liveness tracks the wrapper', () => {
// Anchoring 'omp' to pi's pid would read a pi restart as omp's exit.
expect(
resolveOuterWrapperForegroundIdentity(pi, { pid: 102, ppid: 101, command: 'pi' }, [
{ pid: 102, ppid: 101, command: 'pi' },
{ pid: 101, ppid: 100, command: 'omp' }
])
).toEqual({ processName: 'omp', processId: 101 })
})
it('keeps the winner pid when nothing collapses', () => {
const barePi = { pid: 101, ppid: 100, command: 'pi' }
expect(resolveOuterWrapperForegroundIdentity(pi, barePi, [barePi])).toEqual({
processName: 'pi',
processId: 101
})
})
})