Files
orca/src/cli/handlers/orchestration-request-show-cli.test.ts
T
Brennan Benson cc6b600e21 Fix orchestration CLI recovery, settled-Dispatch mail, and guide defects (#16919)
* Fix orchestration CLI recovery, settled-Dispatch mail, and guide defects

Five reported orchestration CLI defects, verified individually before fixing.
Two were real code defects, one was a docs error, one was correct as-is, and
one was correct on both ends except for its recovery wording.

- Mail addressed to a settled `dispatch:<id>` was accepted and silently dropped.
  Local sends bypassed the settlement check the federated branch already had, so
  the caller was told success for a delivery no worker would ever read. Reject
  with `dispatch_inactive` and name the Run mailbox to use instead.

- A lost mutation response offered no read-only way to ask whether it took
  effect. `--retry-request` does dedupe correctly, but the recovery guidance
  emitted a query command only when the payload carried a dispatch id, which is
  exactly what a lost response lacks. Add read-only
  `orca orchestration request-show --request <id>` over the durable receipt
  ledger, and always emit a read-only step before the keyed retry.

- The bundled `orca-cli` guide documented `check --unread --inject`, a flag the
  parser rejects. Correct it to `--format` and add a ratchet that runs every
  orchestration invocation in the bundled guides through the real CLI parser.

- `check --json` is one stdout document and its keepalives are stderr-only; the
  reported `Extra data: line 2` came from merging the streams. Document the
  contract rather than changing the wire.

- A rejected lifecycle message is loud on both ends already, but the rejection
  never named the flag that supplies the missing capability. Name it.

* Harden orchestration mutation recovery guidance
2026-08-30 18:12:58 -07:00

69 lines
2.2 KiB
TypeScript

// `request-show` is the recovery path a lost mutation response sends you down, so it must
// stay read-only, render the honest reading, and name a version gap instead of a raw RPC error.
import { beforeEach, describe, expect, it, vi } from 'vitest'
const callMock = vi.fn()
vi.mock('../format', () => ({ printResult: vi.fn() }))
vi.mock('../selectors', () => ({ getTerminalHandle: vi.fn() }))
import { ORCHESTRATION_HANDLERS } from './orchestration'
import { printResult } from '../format'
import { RuntimeClientError } from '../runtime-client'
async function runRequestShow(): Promise<void> {
await ORCHESTRATION_HANDLERS['orchestration request-show']({
flags: new Map<string, string | boolean>([['request', 'request_1']]),
client: { call: callMock },
cwd: '/tmp/repo',
json: false
} as never)
}
describe('orchestration request-show', () => {
beforeEach(() => {
callMock.mockReset()
vi.mocked(printResult).mockReset()
})
it('asks the runtime without sending a mutation request id', async () => {
callMock.mockResolvedValue({ requestId: 'request_1', state: 'absent', interpretation: 'none' })
await runRequestShow()
expect(callMock).toHaveBeenCalledWith('orchestration.requestShow', { request: 'request_1' })
})
it('renders the state and the honest reading of it', async () => {
const result = {
requestId: 'request_1',
state: 'completed',
method: 'orchestration.workerStart',
interpretation: 'Request request_1 already took effect.'
}
callMock.mockResolvedValue(result)
await runRequestShow()
const [value, , render] = vi.mocked(printResult).mock.calls[0] as [
unknown,
boolean,
(value: unknown) => string
]
expect(render(value)).toBe(
'request_1 [completed] orchestration.workerStart\nRequest request_1 already took effect.'
)
})
it('names the version gap when the server predates the command', async () => {
callMock.mockRejectedValue(
new RuntimeClientError('method_not_found', 'Unknown method: orchestration.requestShow')
)
await expect(runRequestShow()).rejects.toMatchObject({
code: 'incompatible_runtime',
message: expect.stringContaining('Update Orca on the server')
})
})
})