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`.
This commit is contained in:
Neil
2026-09-29 21:38:09 -07:00
committed by GitHub
parent 91ab51b9fa
commit bb874f6bb3
16 changed files with 13 additions and 432 deletions
@@ -67,10 +67,6 @@ describe('formatSessionSearchResponse: results', () => {
)
})
it('leaves the [[ ]] match marks exactly as the engine wrote them', () => {
expect(formatSessionSearchResponse(results())).toContain('[[resize]]')
})
it('omits the host and the resume line a paired host withheld', () => {
const { executionHostId: _host, resumeCommand: _resume, ...withheld } = localHit
expect(formatSessionSearchResponse(results({ hits: [withheld] }))).toBe(
-4
View File
@@ -213,10 +213,6 @@ describe('command aliases', () => {
expect(findCommandSpec(specs, ['worktree', 'remove'])?.path).toEqual(['worktree', 'rm'])
})
it('resolves each declared alias to the canonical spec', () => {
expect(findCommandSpec(specs, ['worktree', 'delete'])?.path).toEqual(['worktree', 'rm'])
})
it('returns undefined for a path matching neither canonical nor alias', () => {
expect(findCommandSpec(specs, ['worktree', 'destroy'])).toBeUndefined()
})
-23
View File
@@ -471,29 +471,6 @@ describe('orca cli browser tab profiles', () => {
vi.restoreAllMocks()
})
it('lists browser tab profiles', async () => {
queueFixtures(
callMock,
okFixture('req_profiles', {
profiles: [
{ id: 'default', scope: 'default', label: 'Default', partition: 'persist:orca-browser' },
{
id: 'work',
scope: 'isolated',
label: 'Work',
partition: 'persist:orca-browser-session-work'
}
]
})
)
vi.spyOn(console, 'log').mockImplementation(() => {})
await main(['tab', 'profile', 'list', '--json'], '/tmp/not-an-orca-worktree')
expect(callMock).toHaveBeenCalledTimes(1)
expect(callMock).toHaveBeenCalledWith('browser.profileList')
})
it('reports an empty browser tab profile list with a friendly message', async () => {
queueFixtures(callMock, okFixture('req_profiles', { profiles: [] }))
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
+1 -16
View File
@@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest'
import type { CommandSpec } from './args'
import { levenshtein, suggestCommands, unknownCommandData } from './command-suggestion'
import { suggestCommands, unknownCommandData } from './command-suggestion'
const specs: CommandSpec[] = [
{
@@ -45,21 +45,6 @@ const specs: CommandSpec[] = [
}
]
describe('levenshtein', () => {
it('returns 0 for identical strings', () => {
expect(levenshtein('rm', 'rm')).toBe(0)
})
it('counts single-edit distance', () => {
expect(levenshtein('remov', 'remove')).toBe(1)
})
it('handles empty operands', () => {
expect(levenshtein('', 'abc')).toBe(3)
expect(levenshtein('abc', '')).toBe(3)
})
})
describe('suggestCommands', () => {
it('suggests the closest command for a near-miss verb', () => {
expect(suggestCommands(specs, ['worktree', 'remov'])).toContain('worktree rm')
-2
View File
@@ -1,8 +1,6 @@
import { specPaths, type CommandSpec } from './command-spec'
import { levenshtein } from '../shared/edit-distance'
export { levenshtein } from '../shared/edit-distance'
// Why: rank the live registry so typo recovery cannot drift from accepted paths.
const SUGGESTION_THRESHOLD = 3
-24
View File
@@ -389,30 +389,6 @@ describe('agent hooks CLI handler', () => {
}
)
it('keeps missing new card style off when updating offline settings', async () => {
const existing = getDefaultPersistedState(userDataPath)
delete existing.settings.experimentalNewWorktreeCardStyle
writeDataFile(userDataPath, existing)
await runAgentHooksOff(userDataPath)
expect(readDefaultProfileState(userDataPath).settings.experimentalNewWorktreeCardStyle).toBe(
false
)
})
it('preserves an existing explicit new card style opt-in when updating offline settings', async () => {
const existing = getDefaultPersistedState(userDataPath)
existing.settings.experimentalNewWorktreeCardStyle = true
writeDataFile(userDataPath, existing)
await runAgentHooksOff(userDataPath)
expect(readDefaultProfileState(userDataPath).settings.experimentalNewWorktreeCardStyle).toBe(
true
)
})
it.each(['on', 'off', 'status', 'prepare-codex'])(
'refuses explicit remote selection before local hook command %s',
async (command) => {
-78
View File
@@ -7,11 +7,8 @@ import { ARTIFACT_HANDLERS } from './artifacts'
import { ARTIFACT_CLI_MAX_RPC_BYTES } from '../../shared/artifacts'
import {
ARTIFACT_SHARING_DISABLED_CODE,
ARTIFACT_SHARING_DISABLED_MESSAGE,
ARTIFACT_SHARING_DISABLED_NEXT_STEPS
} from '../../shared/artifact-sharing-gate'
import { RuntimeRpcFailureError } from '../runtime-client'
import { reportCliError } from '../format'
const item: ArtifactListItem = {
artifact: {
@@ -196,81 +193,6 @@ describe('artifact CLI handlers', () => {
)
})
it.each(['artifacts share', 'artifacts update'])(
'surfaces the capability denial from `%s` with actionable next steps',
async (command) => {
const cwd = await mkdtemp(join(tmpdir(), 'orca-artifact-cli-'))
await writeFile(join(cwd, 'report.html'), '<h1>Hi</h1>', 'utf8')
const call = vi.fn().mockRejectedValue(
new RuntimeRpcFailureError({
id: 'request-1',
ok: false,
error: {
code: ARTIFACT_SHARING_DISABLED_CODE,
message: ARTIFACT_SHARING_DISABLED_MESSAGE,
data: { nextSteps: [...ARTIFACT_SHARING_DISABLED_NEXT_STEPS] }
},
_meta: { runtimeId: 'runtime-1' }
})
)
const errorLog = vi.spyOn(console, 'error').mockImplementation(() => undefined)
await expect(
ARTIFACT_HANDLERS[command]!({
client: { call } as never,
cwd,
flags: new Map([['file', 'report.html']]),
json: false
})
).rejects.toMatchObject({ code: ARTIFACT_SHARING_DISABLED_CODE })
// The CLI entry point reports the thrown error; assert the rendered text is actionable.
reportCliError(
await ARTIFACT_HANDLERS[command]!({
client: { call } as never,
cwd,
flags: new Map([['file', 'report.html']]),
json: false
}).catch((error: unknown) => error),
false,
{ commandPath: command.split(' ') }
)
const rendered = String(errorLog.mock.calls.at(-1)?.[0])
expect(rendered).toContain(ARTIFACT_SHARING_DISABLED_MESSAGE)
expect(rendered).toContain('Settings → Artifacts')
}
)
it('reports the denial with a stable code in --json mode', async () => {
const cwd = await mkdtemp(join(tmpdir(), 'orca-artifact-cli-'))
await writeFile(join(cwd, 'report.html'), '<h1>Hi</h1>', 'utf8')
const call = vi.fn().mockRejectedValue(
new RuntimeRpcFailureError({
id: 'request-1',
ok: false,
error: {
code: ARTIFACT_SHARING_DISABLED_CODE,
message: ARTIFACT_SHARING_DISABLED_MESSAGE,
data: { nextSteps: [...ARTIFACT_SHARING_DISABLED_NEXT_STEPS] }
},
_meta: { runtimeId: 'runtime-1' }
})
)
const log = vi.spyOn(console, 'log').mockImplementation(() => undefined)
const error = await ARTIFACT_HANDLERS['artifacts share']!({
client: { call } as never,
cwd,
flags: new Map([['file', 'report.html']]),
json: true
}).catch((thrown: unknown) => thrown)
reportCliError(error, true)
expect(JSON.parse(String(log.mock.calls.at(-1)?.[0])).error).toMatchObject({
code: ARTIFACT_SHARING_DISABLED_CODE
})
})
it.each(['environment', 'pairing-code'])(
'rejects explicit remote selector --%s',
async (flag) => {
@@ -53,14 +53,6 @@ describe('orca computer action CLI validation', () => {
expect(process.exitCode).toBe(1)
})
it('rejects actions without an app before resolving a worktree', async () => {
await main(['computer', 'click', '--element-index', '1'], '/tmp/repo/src')
expect(callMock).not.toHaveBeenCalled()
expect(vi.mocked(console.error).mock.calls[0][0]).toContain('Missing required --app')
expect(process.exitCode).toBe(1)
})
it('does not mask missing app with action target errors', async () => {
await main(['computer', 'click'], '/tmp/repo/src')
-39
View File
@@ -157,27 +157,6 @@ describe('orca linear CLI handlers', () => {
expect(vi.mocked(console.error)).not.toHaveBeenCalled()
})
it('keeps global boolean flags before Linear commands from consuming command tokens', async () => {
queueFixtures(callMock, okFixture('req_linear', issueResult()))
await main(['--json', 'linear', 'issue', 'ENG-123', '--full'], '/tmp/repo')
expect(callMock).toHaveBeenCalledWith(
'linear.issueContext',
expect.objectContaining({
input: 'ENG-123',
include: expect.objectContaining({
comments: true,
children: true,
attachments: true,
relations: true,
activity: true
})
}),
{ timeoutMs: 120_000 }
)
})
it('passes verified current-context hints without resolving cwd for remote runtimes', async () => {
process.env.ORCA_TERMINAL_HANDLE = 'term_123'
process.env.ORCA_WORKTREE_ID = 'repo::/srv/app'
@@ -259,24 +238,6 @@ describe('orca linear CLI handlers', () => {
})
})
it('keeps boolean flags between Linear and search from consuming the subcommand', async () => {
queueFixtures(
callMock,
okFixture('req_search', {
issues: [],
meta: { query: 'auth', workspaceId: undefined, limit: 1, returned: 0, limitReached: false }
})
)
await main(['linear', '--json', 'search', 'auth', '--limit', '1'], '/tmp/repo')
expect(callMock).toHaveBeenCalledWith('linear.agentSearchIssues', {
query: 'auth',
limit: 1,
workspaceId: undefined
})
})
it('maps status writes to the agent write RPC with an explicit target', async () => {
queueFixtures(callMock, okFixture('req_status', statusSetResult()))
@@ -273,80 +273,6 @@ describe('orchestration task-create caller handle', () => {
expect(callMock).toHaveBeenCalledTimes(1)
})
it('propagates runtime unavailability while proving the bound coordinator', async () => {
process.env.ORCA_TERMINAL_HANDLE = 'term_creator'
callMock.mockRejectedValueOnce(
new RuntimeClientError('runtime_unavailable', 'runtime_unavailable')
)
await expect(
invokeTaskCreate(new Map<string, string | boolean>([['spec', 'do work']]))
).rejects.toMatchObject({ code: 'runtime_unavailable' })
expect(callMock).toHaveBeenNthCalledWith(1, 'terminal.resolveIdentity', {
terminal: 'term_creator'
})
expect(getTerminalHandleMock).not.toHaveBeenCalled()
expect(callMock).toHaveBeenCalledTimes(1)
})
it('propagates runtime unavailability while reminting the bound coordinator', async () => {
process.env.ORCA_TERMINAL_HANDLE = 'term_stale'
process.env.ORCA_PANE_KEY = 'tab_creator:leaf_creator'
stubStaleHandleRemintFailure(
new RuntimeClientError('runtime_unavailable', 'runtime_unavailable')
)
getTerminalHandleMock.mockResolvedValue('term_wrong_active')
await expect(
invokeTaskCreate(new Map<string, string | boolean>([['spec', 'do work']]))
).rejects.toMatchObject({ code: 'runtime_unavailable' })
expect(callMock).toHaveBeenNthCalledWith(1, 'terminal.resolveIdentity', {
terminal: 'term_stale'
})
expect(callMock).toHaveBeenNthCalledWith(2, 'terminal.resolvePane', {
paneKey: 'tab_creator:leaf_creator'
})
expect(getTerminalHandleMock).not.toHaveBeenCalled()
expect(callMock).toHaveBeenCalledTimes(2)
})
it('propagates unexpected caller pane remint failures for task creation', async () => {
process.env.ORCA_TERMINAL_HANDLE = 'term_stale'
process.env.ORCA_PANE_KEY = 'tab_creator:leaf_creator'
stubStaleHandleRemintFailure(new RuntimeClientError('permission_denied', 'denied'))
getTerminalHandleMock.mockResolvedValue('term_wrong_active')
await expect(
invokeTaskCreate(new Map<string, string | boolean>([['spec', 'do work']]))
).rejects.toMatchObject({
code: 'permission_denied'
})
expect(callMock).toHaveBeenNthCalledWith(1, 'terminal.resolveIdentity', {
terminal: 'term_stale'
})
expect(callMock).toHaveBeenNthCalledWith(2, 'terminal.resolvePane', {
paneKey: 'tab_creator:leaf_creator'
})
expect(callMock).toHaveBeenCalledTimes(2)
expect(getTerminalHandleMock).not.toHaveBeenCalled()
})
it('propagates unexpected env handle validation failures', async () => {
process.env.ORCA_TERMINAL_HANDLE = 'term_creator'
callMock.mockRejectedValueOnce(new RuntimeClientError('permission_denied', 'denied'))
await expect(
invokeTaskCreate(new Map<string, string | boolean>([['spec', 'do work']]))
).rejects.toMatchObject({
code: 'permission_denied'
})
expect(callMock).toHaveBeenCalledTimes(1)
})
it('remints a stale task creator env handle from the caller pane key', async () => {
process.env.ORCA_TERMINAL_HANDLE = 'term_stale'
process.env.ORCA_PANE_KEY = 'tab_creator:leaf_creator'
@@ -94,19 +94,16 @@ describe('orchestration check identity', () => {
)
})
it.each([true, false])(
'surfaces a stale --terminal refusal instead of an empty inbox (json=%s)',
async (json) => {
callMock.mockRejectedValue(
Object.assign(new Error('Terminal term_gone has no live pane bound to a Run'), {
code: 'stable_pane_required'
})
)
it('surfaces a stale --terminal refusal instead of an empty inbox', async () => {
callMock.mockRejectedValue(
Object.assign(new Error('Terminal term_gone has no live pane bound to a Run'), {
code: 'stable_pane_required'
})
)
await expect(
invokeCheck(new Map<string, string | boolean>([['terminal', 'term_gone']]), json)
).rejects.toMatchObject({ code: 'stable_pane_required' })
expect(printResultMock).not.toHaveBeenCalled()
}
)
await expect(
invokeCheck(new Map<string, string | boolean>([['terminal', 'term_gone']]))
).rejects.toMatchObject({ code: 'stable_pane_required' })
expect(printResultMock).not.toHaveBeenCalled()
})
})
@@ -120,47 +120,6 @@ describe('legacy orchestration CLI inspection', () => {
expect(response.result.formatted).not.toContain('orchestration reply')
})
it.each([undefined, ''])(
'rebuilds missing legacy formatted output for JSON inspection (%s)',
async (formatted) => {
const result = {
messages: [
{
id: 'msg_legacy',
run_id: 'run_legacy_local',
from_handle: 'term_worker',
subject: 'progress',
type: 'status',
body: 'Tests are running.',
payload: '{"phase":"testing"}'
}
],
count: 1,
formatted
}
callMock.mockResolvedValue({ result })
await ORCHESTRATION_HANDLERS['orchestration check']({
flags: new Map<string, string | boolean>([
['terminal', 'term_coord'],
['peek', true],
['format', true]
]),
client: { call: callMock },
cwd: '/repo',
json: true
} as never)
const response = vi.mocked(printResult).mock.calls[0]?.[0] as {
result: typeof result & { formatted: string }
}
expect(response.result.formatted).toContain('msg_legacy [legacy, read-only]')
expect(response.result.formatted).toContain('Tests are running.')
expect(response.result.formatted).toContain('[payload]\n {"phase":"testing"}')
expect(response.result.formatted).not.toContain('orchestration reply')
}
)
it('keeps reply guidance only for current rows in a mixed formatted batch', async () => {
const result = {
messages: [
@@ -3,8 +3,6 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
vi.mock('../format', () => ({ printResult: vi.fn() }))
import { printResult } from '../format'
import { HANDLER_GROUPS } from '../handler-group-manifest'
import { ORCHESTRATION_HANDLERS } from './orchestration'
import {
ORCHESTRATION_DISPATCH_HANDLER,
ORCHESTRATION_DISPATCH_INSPECTION_HANDLERS
@@ -38,11 +36,6 @@ describe('extracted orchestration flag parsing', () => {
})
})
it('composes handlers in the canonical command order', () => {
const declared = HANDLER_GROUPS.find((group) => group.name === 'orchestration')?.keys
expect(Object.keys(ORCHESTRATION_HANDLERS)).toEqual(declared)
})
describe('extracted orchestration worker formatting', () => {
it('renders terminal tails without changing line boundaries', () => {
expect(
@@ -6,7 +6,6 @@ const getTerminalHandleMock = vi.hoisted(() => vi.fn())
vi.mock('../format', () => ({ printResult: vi.fn() }))
vi.mock('../selectors', () => ({ getTerminalHandle: getTerminalHandleMock }))
import { printResult } from '../format'
import { ORCHESTRATION_HANDLERS } from './orchestration'
describe('lightweight Run CLI handlers', () => {
@@ -172,46 +171,3 @@ describe('orchestration reset CLI handler', () => {
expect(callMock).not.toHaveBeenCalled()
})
})
describe('orchestration task-list brief output', () => {
it('requests server-side brief and falls back client-side for older runtimes', async () => {
callMock.mockReset().mockResolvedValue({
result: {
tasks: [{ id: 'task_1', spec: `First line\n${'detail '.repeat(40)}`, status: 'ready' }],
count: 1
}
})
vi.mocked(printResult).mockClear()
await ORCHESTRATION_HANDLERS['orchestration task-list']({
flags: new Map([['brief', true]]),
client: { call: callMock },
json: true
} as never)
expect(callMock).toHaveBeenCalledWith(
'orchestration.taskList',
expect.objectContaining({ brief: true })
)
const response = vi.mocked(printResult).mock.calls[0]?.[0] as {
result: { tasks: { spec: string; spec_truncated: boolean }[] }
}
expect(response.result.tasks[0].spec).toHaveLength(160)
expect(response.result.tasks[0].spec_truncated).toBe(true)
})
it('passes server-abbreviated rows through untouched', async () => {
const serverTasks = [
{ id: 'task_1', spec: 'already brief…', status: 'ready', spec_truncated: true }
]
callMock.mockReset().mockResolvedValue({ result: { tasks: serverTasks, count: 1 } })
vi.mocked(printResult).mockClear()
await ORCHESTRATION_HANDLERS['orchestration task-list']({
flags: new Map([['brief', true]]),
client: { call: callMock },
json: true
} as never)
const response = vi.mocked(printResult).mock.calls[0]?.[0] as {
result: { tasks: { spec: string; spec_truncated: boolean }[] }
}
expect(response.result.tasks).toBe(serverTasks)
})
})
@@ -104,34 +104,6 @@ describe('orchestration worker-start CLI contract', () => {
expect(process.exitCode).toBeUndefined()
})
it.each(['succeeded', 'failed'])(
'accepts a successful start whose task already %s',
async (workerOutcome) => {
const receipt = {
taskId: 'task_1',
dispatchId: 'ctx_1',
state: 'ready',
stage: 'settled',
workerOutcome,
effects: [],
residualResources: []
}
callMock.mockResolvedValue({ result: receipt })
await invokeWorkerStart(
new Map([
['task', 'task_1'],
['from', 'term_coord']
])
)
expect(process.exitCode).toBeUndefined()
expect(printResult).toHaveBeenCalledWith(
expect.objectContaining({ result: receipt }),
true,
expect.any(Function)
)
}
)
it('capability-gates and forwards per-invocation launch preferences', async () => {
callMock
.mockResolvedValueOnce({
+1 -26
View File
@@ -532,7 +532,7 @@ describe('orchestration timeout flag validation', () => {
expect(getTerminalHandleMock).not.toHaveBeenCalled()
})
it.each([String(2_147_483_647), String(Number.MAX_SAFE_INTEGER)])(
it.each([String(Number.MAX_SAFE_INTEGER)])(
'clamps a safe ask timeout %s before adding transport headroom',
async (rawTimeout) => {
process.env.ORCA_TERMINAL_HANDLE = 'term_worker'
@@ -557,31 +557,6 @@ describe('orchestration timeout flag validation', () => {
}
)
it.each(['+1000', '1000.0', '1e3', '0x3e8'])(
'preserves CLI-compatible exact integer timeout syntax %s',
async (rawTimeout) => {
process.env.ORCA_TERMINAL_HANDLE = 'term_worker'
callMock.mockResolvedValue({
result: { answer: 'yes', messageId: 'msg_1', threadId: 'thread_1', timedOut: false }
})
vi.spyOn(console, 'log').mockImplementation(() => {})
await invokeAsk(
new Map<string, string | boolean>([
['to', 'term_coord'],
['question', 'Proceed?'],
['timeout-ms', rawTimeout]
])
)
expect(callMock).toHaveBeenCalledWith(
'orchestration.ask',
expect.objectContaining({ timeoutMs: 1_000 }),
{ timeoutMs: 6_000 }
)
}
)
it('keeps an omitted ask timeout out of the payload while using default headroom', async () => {
process.env.ORCA_TERMINAL_HANDLE = 'term_worker'
callMock.mockResolvedValue({