Files
orca/src/cli/command-suggestion.test.ts
T
Neil bb874f6bb3 test: retire cli cases that re-run a contract the sibling already owns (#24000)
Audit sweep over `src/cli`. 23 cases retired and 2 `it.each` tables collapsed
to the rows their parameter actually reaches.

What went, by pattern:

- Table rows whose varied parameter production never reads, so every row ran
  one identical path.
- Second and third invocations of a contract already proven by the case above
  them, differing only in a field the assertion ignores.
- Argument-shape and private-predicate checks duplicated at the real CLI
  boundary, where the same input is already driven end to end.
- Assertions whose expected value came from the same helper under test.

`src/cli/command-suggestion.ts` loses `export { levenshtein }`, a re-export no
production caller used. The one test that stubs edit distance spies on
`../shared/edit-distance` directly, which is the module `command-suggestion`
imports, so the seam it needs is unaffected.

Kept deliberately: `orchestration-lifecycle-json-rejection.test.ts` and
`orchestration-migration.test.ts`, both named in `config/reliability-gates.jsonc`
as sole evidence for a gate.

While auditing the latter, its replay dimension turned out to be inert --
`it.each([false, true])` varies `lifecycle.duplicate`, and `hasLifecycleVerdict`
(`orchestration-worker-settlement.ts:112-132`) reads only `action`, `authority`
and `outcome`. The gate at `reliability-gates.jsonc:15861` nonetheless records
"first and replayed legacy worker_done settlements are accepted". Left exactly
as found and reported rather than collapsed, because correcting a gate's claim
or adding real replay coverage is the owner's call.

Verified: `pnpm test src/cli` (131 files, 1474 passed), `pnpm tc`,
`check-reliability-gates.mjs` (140 gates), `check:code-quality:changed`.
2026-09-29 21:38:09 -07:00

132 lines
4.6 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import type { CommandSpec } from './args'
import { suggestCommands, unknownCommandData } from './command-suggestion'
const specs: CommandSpec[] = [
{
path: ['worktree', 'rm'],
aliases: [
['worktree', 'remove'],
['worktree', 'delete']
],
destructive: true,
summary: 'Remove a worktree',
usage: 'orca worktree rm',
allowedFlags: []
},
{
path: ['worktree', 'list'],
summary: 'List worktrees',
usage: 'orca worktree list',
allowedFlags: []
},
{
path: ['terminal', 'send'],
summary: 'Send input',
usage: 'orca terminal send',
allowedFlags: []
},
{
// A destructive command outside the delete-family, to prove the guard keys
// off the spec flag rather than a hardcoded verb list.
path: ['emulator', 'kill'],
destructive: true,
summary: 'Kill the emulator',
usage: 'orca emulator kill',
allowedFlags: []
},
{
path: ['terminal', 'stop'],
hidden: true,
summary: 'Deprecated terminal stop',
usage: 'orca terminal stop',
allowedFlags: []
}
]
describe('suggestCommands', () => {
it('suggests the closest command for a near-miss verb', () => {
expect(suggestCommands(specs, ['worktree', 'remov'])).toContain('worktree rm')
})
it('includes alias paths among suggestions', () => {
// `worktree remove` is the alias; a typo near it should surface it (an exact
// match would resolve as a real command, not trigger a suggestion).
expect(suggestCommands(specs, ['worktree', 'remov'])).toContain('worktree remove')
})
it('returns nothing for a wildly-off token', () => {
expect(suggestCommands(specs, ['worktree', 'zzzzz'])).toEqual([])
})
it('only considers commands of the same depth', () => {
expect(suggestCommands(specs, ['worktree', 'list', 'extra'])).toEqual([])
})
it('suggests a top-level command group near-miss', () => {
expect(suggestCommands(specs, ['worktre'])).toEqual(['worktree'])
})
it('ranks closer matches first', () => {
const result = suggestCommands(specs, ['terminal', 'sen'])
expect(result[0]).toBe('terminal send')
})
it('never suggests a destructive command for a benign non-destructive typo', () => {
// `worktree move` sits distance 2 from `worktree remove`; without the
// guard it would sole-suggest an irreversible delete on blind retry. #6303
const result = suggestCommands(specs, ['worktree', 'move'])
expect(result).not.toContain('worktree remove')
expect(result).not.toContain('worktree rm')
expect(result).not.toContain('worktree delete')
})
it('still suggests remove for a near-miss of a destructive verb', () => {
const result = suggestCommands(specs, ['worktree', 'remov'])
expect(result).toContain('worktree rm')
expect(result).toContain('worktree remove')
})
it('still suggests delete for a near-miss of the delete alias', () => {
expect(suggestCommands(specs, ['worktree', 'delet'])).toContain('worktree delete')
})
it('guards destructive commands outside the delete-family via the spec flag', () => {
// `emulator ball` is a benign token, distance 2 from the flagged `emulator
// kill` — close enough to otherwise rank, so the guard must exclude it.
expect(suggestCommands(specs, ['emulator', 'ball'])).not.toContain('emulator kill')
// A genuine near-miss of the destructive verb still recovers.
expect(suggestCommands(specs, ['emulator', 'kil'])).toContain('emulator kill')
})
it('still recovers non-destructive near-misses', () => {
expect(suggestCommands(specs, ['worktree', 'lst'])).toContain('worktree list')
})
it('does not suggest hidden compatibility commands', () => {
expect(suggestCommands(specs, ['terminal', 'stp'])).not.toContain('terminal stop')
})
})
describe('unknownCommandData', () => {
it('produces a human nextSteps line when a suggestion exists', () => {
const data = unknownCommandData(specs, ['worktree', 'remov'])
expect(data.suggestions).toContain('worktree rm')
expect(data.nextSteps[0]).toContain('Did you mean')
expect(data.nextSteps[0]).toContain('orca worktree rm')
})
it('produces empty nextSteps when nothing is close', () => {
const data = unknownCommandData(specs, ['worktree', 'zzzzz'])
expect(data.suggestions).toEqual([])
expect(data.nextSteps).toEqual([])
})
it('does not route a benign typo into a destructive nextStep', () => {
const data = unknownCommandData(specs, ['worktree', 'move'])
expect(data.suggestions).not.toContain('worktree remove')
expect(data.nextSteps.join(' ')).not.toContain('remove')
})
})