Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

2.6 KB
Raw Blame
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
    })
  })
})