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.

4.1 KB
Raw Blame
import { describe, expect, it } from 'vitest'
import { isDshNonInteractiveCommand } from './dsh-launch-command'
import { recognizeAgentProcessFromCommandLine } from './agent-process-recognition'

function tokens(commandLine: string): string[] {
  return commandLine.split(' ')
}

describe('isDshNonInteractiveCommand', () => {
  it.each([
    'dsh web',
    'dsh headless "run the tests"',
    'dsh sdk',
    'dsh sdk-minimal',
    'dsh acp',
    'dsh desktop',
    'dsh dsh-tui --dump-config',
    'dsh dsh-tui --dump-default-config',
    'dsh dsh-tui --dump-config-schema',
    'dsh --profile web',
    'dsh --profile=web --port 8080',
    'dsh --profile headless "run the tests"',
    'dsh --profile sdk',
    'dsh --profile sdk-minimal',
    'dsh --profile acp',
    'dsh plugin --profile dsh-tui add some-plugin',
    'dsh --profile dsh-tui --dump-config'
  ])('rejects %s', (commandLine) => {
    expect(isDshNonInteractiveCommand(tokens(commandLine))).toBe(true)
  })

  it.each([
    'dsh --profile dsh-tui',
    'dsh dsh-tui',
    'dsh tui --resume web',
    'dsh tui --patch web --resume sdk',
    'dsh tui --patch=web --resume sdk',
    'dsh --profile tui --patch headless --resume sdk',
    'dsh tui --from-default-profile web --resume sdk',
    'dsh tui --resume session --dump-config',
    'dsh --profile tui --resume session --dump-config',
    'dsh --profile=dsh-tui',
    'dsh --profile dsh-tui --resume 9478e2d8-29bc-4009-ab32-657efa2bd763',
    'dsh-tui',
    'dsh-tui --resume',
    'dst'
  ])('accepts %s', (commandLine) => {
    expect(isDshNonInteractiveCommand(tokens(commandLine))).toBe(false)
  })

  it('reads only the first --profile, so app arguments cannot retarget it', () => {
    // `--resume web` belongs to the terminal app, not the launcher.
    expect(isDshNonInteractiveCommand(tokens('dsh --profile dsh-tui --resume web'))).toBe(false)
  })

  it.each([
    'dsh-tui web',
    'dst web',
    'dsh-tui plugin',
    'dsh-tui --continue web',
    'dsh-tui /home/dev/projects/web',
    'node /usr/local/lib/node_modules/.bin/dsh-tui web',
    'C:\\Users\\dev\\AppData\\npm\\dsh-tui.cmd web'
  ])('keeps %s interactive: the launcher already chose the TUI profile', (commandLine) => {
    // TUI launchers forward remaining argv as app targets/resume IDs, so web/plugin folder names cannot become launcher subcommands.
    expect(isDshNonInteractiveCommand(tokens(commandLine))).toBe(false)
  })
})

describe('dsh foreground process recognition', () => {
  it.each([
    'dsh-tui',
    'dst',
    '/opt/homebrew/bin/dsh --profile dsh-tui',
    'node /usr/local/lib/node_modules/.bin/dsh-tui',
    'node /home/dev/.dsh/profiles/dsh-tui/node_modules/@deepseek-harness-tui/dsh-tui/bin/dsh-tui.js',
    'node /usr/local/lib/node_modules/@deepseek-ai/dsh/lib/bin.js --profile dsh-tui'
  ])('recognizes %s as dsh', (commandLine) => {
    expect(recognizeAgentProcessFromCommandLine(commandLine)?.agent).toBe('dsh')
  })

  it.each([
    'dsh web',
    'dsh headless "summarize the diff"',
    'dsh sdk',
    'dsh sdk-minimal',
    'dsh acp',
    'node /usr/local/lib/node_modules/@deepseek-ai/dsh/lib/bin.js headless "go"',
    'node /usr/local/lib/node_modules/@deepseek-ai/dsh/lib/bin.js sdk',
    'node --no-warnings /usr/local/lib/node_modules/@deepseek-ai/dsh/lib/bin.js sdk',
    'C:\\Tools\\dsh.cmd headless go',
    'dsh --profile headless "summarize the diff"',
    'node /usr/local/lib/node_modules/@deepseek-ai/dsh/lib/bin.js --profile acp'
  ])('does not claim %s as an interactive agent pane', (commandLine) => {
    expect(recognizeAgentProcessFromCommandLine(commandLine)).toBeNull()
  })

  it.each(['dsh-tui web', 'dst plugin'])(
    'still recognizes %s as the dsh agent pane',
    (commandLine) => {
      expect(recognizeAgentProcessFromCommandLine(commandLine)?.agent).toBe('dsh')
    }
  )

  it('still reports non-interactive dsh when headless one-shots are included', () => {
    // Reuse guards need all noninteractive agent panes, including dsh web, to avoid treating them as shells.
    expect(
      recognizeAgentProcessFromCommandLine('dsh --profile headless "go"', {
        includeHeadlessOneShot: true
      })?.agent
    ).toBe('dsh')
  })
})