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.4 KB
Raw Blame
import { describe, expect, it } from 'vitest'
import { BUNDLED_SKILL_GUIDES } from '../bundled-skill-guides'
import { validateCommandAndFlags, type CommandSpec } from '../args'
import { COMMAND_SPECS } from './index'

type GuideInvocation = {
  guide: string
  command: string
  flag: string
  snippet: string
}

const CLI_INVOCATION = /(?:^|[\s`(])(?:orca|orca-dev|orca-ide|ORCA)\s+([^\n`]*)/g

// Longest path first so `orchestration worker-start` never resolves as `orchestration worker`.
const SPECS_BY_DEPTH: CommandSpec[] = [...COMMAND_SPECS].sort(
  (a, b) => b.path.length - a.path.length
)

function findSpecForInvocation(invocation: string): CommandSpec | undefined {
  return SPECS_BY_DEPTH.find((spec) => {
    const prefix = `${spec.path.join(' ')} `
    return invocation === spec.path.join(' ') || invocation.startsWith(prefix)
  })
}

function collectGuideInvocations(): GuideInvocation[] {
  const found: GuideInvocation[] = []
  for (const guide of BUNDLED_SKILL_GUIDES) {
    const documents = [guide.markdown, ...guide.references.map((reference) => reference.markdown)]
    for (const match of documents.join('\n').matchAll(CLI_INVOCATION)) {
      const invocation = match[1].trim()
      const spec = findSpecForInvocation(invocation)
      if (!spec) {
        continue
      }
      // Quoted values contain nested commands whose flags do not belong to orca.
      const orcaArgs = invocation.replace(/'[^']*'|"[^"]*"/g, ' ')
      const flags = [...orcaArgs.matchAll(/(?:^|[\s[(])--([a-z][a-z0-9-]*)/g)].map(
        (flag) => flag[1]
      )
      for (const flag of flags) {
        found.push({
          guide: guide.name,
          command: spec.path.join(' '),
          flag,
          snippet: invocation.slice(0, 120)
        })
      }
    }
  }
  return found
}

describe('bundled skill guides', () => {
  const invocations = collectGuideInvocations()

  it('only documents flags the CLI parser accepts', () => {
    expect(invocations.length).toBeGreaterThan(0)
    const rejected = invocations.filter((invocation) => {
      try {
        validateCommandAndFlags(COMMAND_SPECS, {
          commandPath: invocation.command.split(' '),
          flags: new Map([[invocation.flag, 'placeholder']])
        })
        return false
      } catch {
        return true
      }
    })
    expect(
      rejected.map((entry) => `${entry.guide}: ${entry.command} --${entry.flag} (${entry.snippet})`)
    ).toEqual([])
  })
})