Files
orca/src/cli/agent-context.test.ts
T
OrcaWinandOrcaWin 5d32f372e7 test: audit CLI output and deferred delivery boundaries (#32498)
* test: audit CLI output and deferred delivery boundaries

* docs: reconcile fifth test audit with main

* test: build process-host for Cloud-only relay validation

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
2026-10-23 06:36:47 -07:00

103 lines
3.4 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import type { CommandSpec } from './args'
import { buildAgentContext, formatAgentContextSummary } from './agent-context'
import { COMMAND_SPECS } from './specs'
describe('buildAgentContext', () => {
const specs: CommandSpec[] = [
{
path: ['worktree', 'rm'],
aliases: [
['worktree', 'remove'],
['worktree', 'delete']
],
summary: 'Remove a worktree',
usage: 'orca worktree rm',
allowedFlags: ['worktree', 'force']
},
{
path: ['agent-context'],
summary: 'Print the schema',
usage: 'orca agent-context',
allowedFlags: []
}
]
it('emits a versioned envelope with a command count', () => {
const schema = buildAgentContext(specs)
expect(schema.schemaVersion).toBe(1)
expect(schema.commandCount).toBe(2)
expect(schema.commands).toHaveLength(2)
})
it('includes resolved aliases for a command', () => {
const schema = buildAgentContext(specs)
const rm = schema.commands.find((command) => command.command === 'worktree rm')
expect(rm?.aliases).toEqual([
['worktree', 'remove'],
['worktree', 'delete']
])
})
it('reports effective flags including globals, not just allowedFlags', () => {
const schema = buildAgentContext(specs)
const rm = schema.commands.find((command) => command.command === 'worktree rm')
expect(rm?.flags).toContain('worktree')
expect(rm?.flags).toContain('force')
expect(rm?.flags).toContain('json')
expect(rm?.flags).toContain('help')
})
it('orders commands deterministically', () => {
const schema = buildAgentContext(specs)
expect(schema.commands.map((command) => command.command)).toEqual([
'agent-context',
'worktree rm'
])
})
it('omits hidden specs so agents do not discover an unadvertised command', () => {
const schema = buildAgentContext([
...specs,
{
path: ['terminal', 'stop'],
summary: 'Deprecated',
usage: 'orca terminal stop',
allowedFlags: [],
hidden: true
}
])
expect(schema.commandCount).toBe(2)
expect(schema.commands.map((command) => command.command)).not.toContain('terminal stop')
})
it('defaults optional fields to empty arrays', () => {
const schema = buildAgentContext(specs)
const agentContext = schema.commands.find((command) => command.command === 'agent-context')
expect(agentContext?.aliases).toEqual([])
expect(agentContext?.examples).toEqual([])
})
})
describe('agent-context over the live registry', () => {
it('human summary count matches the command count', () => {
const schema = buildAgentContext(COMMAND_SPECS)
expect(formatAgentContextSummary(schema)).toContain(`${schema.commandCount} commands`)
})
it('does not advertise browser page targeting for local discovery', () => {
const schema = buildAgentContext(COMMAND_SPECS)
const agentContext = schema.commands.find((command) => command.command === 'agent-context')
expect(agentContext).toBeDefined()
expect(agentContext?.flags).not.toContain('page')
})
it('marks raw passthrough commands without synthesizing Orca flags', () => {
const schema = buildAgentContext(COMMAND_SPECS)
const claudeTeams = schema.commands.find((command) => command.command === 'claude-teams')
expect(claudeTeams?.argumentMode).toBe('passthrough')
expect(claudeTeams?.flags).toEqual([])
})
})