Skip to content

refactor(cli): own shell completion behind new CLI parity goldens - #11662

Merged
morluto merged 4 commits into
mainfrom
test/cli-parity-goldens
Nov 16, 2026
Merged

morluto merged 4 commits into
mainfrom
test/cli-parity-goldens

Conversation

@morluto

@morluto morluto commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

Capture the current CLI behaviour as parity goldens, then move shell completion off incur onto an REA-owned protocol module with the goldens unchanged. 81 cases run the compiled rea and compare exit code, stdout and stderr with reviewed files in tests/fixtures/cli-parity/. This PR carries #11665 (collapsed into it). Refs #11654, refs #10583.

Problem and expected behavior

#11654 replaces incur's parser, help, completions, formatter, errors and dispatch with REA-owned modules, with no user-visible change unless the owner approves one. There was no byte-level record of what the CLI prints today, so a replacement could change help layout, completion protocol output, error codes or output formats without a failing test.

Change and scope

  • tests/boundary/cli/cliParityGoldens.test.ts: one case table, run through the public CLI (cliTest, shared process; the 16 shell-completion protocol cases and the launcher-routed mcp doctor --help use a fresh process).
    • Help and manifests: root help (bare, --help, -h, with --format), --version (root and after a command), per-command help for contract commands (inspect-byte-entropy, instructions, decompile, read-bytes) and hand-built ones (setup, doctor, guidance, capture-process, environment-build, update), mcp, mcp add, mcp doctor, completions, command --schema (TOON and JSON), command --llms and --llms-full.
    • Completions: the script for bash, zsh, fish and nushell, an unknown shell, and the COMPLETE=<shell> protocol for command, option, subcommand, enum and global-flag candidates, a group's no-space marker, short aliases, a hand-built command's enum values, values after an aliased option, words after a boolean flag and after --, mcp doctor options, and zsh/fish/nushell descriptions.
    • Errors: unknown command (root, empty, mcp subcommand), missing/extra positional, unknown flag, missing flag value, invalid and refined numbers (TOON, JSON, Markdown, --full-output), the -- separator, invalid/missing --format, CSV without --columns, a non-collection JSON Lines selection, and --sensitive-value redaction of an output value and a positional.
    • Output: TOON, JSON (--format json, --json, = spellings), YAML, Markdown, CSV, TSV, --full-output (TOON and JSON), --token-count, --token-limit, --token-offset, --timings.
  • Normalization: workspace path, package version, duration/command_ms timings, and control bytes shown as <0x0b>. Each file ends stdout and stderr with <end> so trailing newlines are exact.
  • The root command list grows with every new command, so the test checks its layout (rows sorted, one aligned description column) and keeps only six sample rows (first, longest name, last and three others); the rest are written as <registered command rows elided>.
  • A second test fails when a golden file has no case, so removed cases cannot leave stale files.
  • Recording: REA_RECORD_CLI_PARITY=1 npm run test:focused -- tests/boundary/cli/cliParityGoldens.test.ts, then review the diff.

Completion owner (from #11665):

  • src/cli/bashCompletionRegistration.ts becomes src/cli/completionProtocol.ts and owns:
    • completionScript(shell, name): bash (unchanged) plus zsh, fish and nushell scripts, byte-identical to incur 0.6.1's;
    • completeWords(commands, words, index, globals): scope walk, option and short-alias candidates, enum values after a value-taking option, subcommands in registration order with a no-space marker for groups (the same rules as incur's complete, which took an unused root-command argument);
    • formatCompletions(shell, candidates): bash \v records, zsh value:description, fish value\tdescription, nushell JSON.
  • completions.ts keeps the command tree (still read through Cli.toCommands) and the globals schema; it no longer imports Completions.
  • The hook functions keep the _incur_complete_<name> prefix so hooks users already sourced keep working; renaming it is listed as an owner decision on Remove incur: run the CLI on an REA-owned, contract-generated layer with parity tests #11654.
  • bashCompletionRegistration.test.ts is renamed with its module; its assertions are unchanged.
  • Not included: the command registry and dispatch (Cli.toCommands, Cli.create) and every other incur owner.

Goldens, not included:

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/cli/completionProtocol.ts replaces incur's Completions (scripts, candidates, encoding); the only consumer is src/cli/completions.ts. Everything else is tests.

  • Contribution scope fit and linked maintainer decision: [Design] Replace incur with a contract-generated CLI layer now that REA owns its MCP server #10583 (owner answered yes), tracked by Remove incur: run the CLI on an REA-owned, contract-generated layer with parity tests #11654.

  • CLI and MCP/tool-catalog contract: none changed; the goldens record the current CLI contract and pass unchanged with the REA completion owner.

  • Provider, bridge, target-format, or platform compatibility: macOS and Linux. Windows is not in the curated Windows lane.

  • Evidence, artifact, provenance, or reconstruction contract: none.

  • Target selection, authority, upstream behavior, and cleanup details (if applicable): output cases read one 20-byte file the test writes in its own workspace.

  • Generated metadata, package, or installation impact: none.

  • Read existing files or captured data.

  • Launch or attach to a process.

  • Inject instrumentation or run scripts/code.

  • Change process memory, registers, files, or configuration.

  • Contact network services.

  • Recover protected code or work around protections.

  • Documentation or usability only; no target interaction.

  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: tests/boundary/cli/cliParityGoldens.test.ts and 81 files in tests/fixtures/cli-parity/; bashCompletionRegistration.test.ts renamed to completionProtocol.test.ts with its module.
  • Base reproduction or other evidence: recorded on this branch (based on main 162097b), then passed unchanged in compare mode. Adding one space to a padded option in help-contract-command.txt failed exactly that case (1 failed | 74 passed before the second commit); the file was restored.
  • User-visible CLI/MCP output (if applicable): none changed. Facts the goldens make visible: global help lists --format <toon|json|yaml|md|jsonl> although csv and tsv are accepted (fix(cli): advertise delimited output formats in help #10777); completion candidates follow command registration order, not alphabetical order; -- after a command is reported as Unknown flag: --.
  • Root-help goldens keep six sample rows with a fixed two-space gap; the test asserts the real alignment (description at longest name + 2) on the full output, so a longer new command does not change the goldens. In record mode the inventory test only rejects orphan files, so new cases can be recorded in one run.
  • Remaining proof gaps: recorded on macOS only; Linux CI is the first Linux run. Unknown-command suggestions ("Did you mean ...") depend on the registered names and change if a closer name is added.

Validation performed

  • REA_RECORD_CLI_PARITY=1 npm run test:focused -- tests/boundary/cli/cliParityGoldens.test.ts — recorded 74 files; a second commit added 7 completion cases (81 files).
  • npm run test:focused -- tests/boundary/cli/cliParityGoldens.test.ts — 82 passed after the second commit (75 passed in 13.9 s elapsed, 17.7 s user CPU, 592 MB peak RSS before it). A first version with a workspace per case took 44.9 s because each new environment restarted the shared CLI process; one file-scoped workspace fixed that.
  • Same command with one golden byte mutated — failed that case only, as expected.
  • After the review fixes: deleted version.txt and recorded (82 passed, file recreated byte-identical); npm run test:focused -- tests/boundary/cli/cliParityGoldens.test.ts tests/boundary/cli/completions.test.ts tests/boundary/cli/completionProtocol.test.ts — 90 passed, on both the goldens commit and the completion owner commit.
  • npm run check:fast — passed (goldens commit and completion owner commit).
  • After rebasing onto main 67b65b3 (refactor(cli): import zod directly instead of through incur #11655 merged; one import-line conflict in completions.ts resolved to import { Cli } from "incur";): npm run check:fast passed; the same three focused test files — 90 passed, goldens unchanged.
  • npx oxfmt --check tests/boundary/cli/cliParityGoldens.test.ts — passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: not applicable.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-16T02:18:14.377264Z
We couldn’t complete this review. Comment @codex review to try again.
417e3e2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@greptile-apps

greptile-apps Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge; no blocking issue was established.

Summary

Moves shell completion into REA-owned completionProtocol.ts and adds 81 saved CLI output cases.

  • The CLI keeps a set of saved examples for its current output.
  • REA now owns shell completion scripts and candidate formatting.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Shell[Shell hook] --> Request["COMPLETE request"]
  Request --> Adapter["completions.ts"]
  Registry["Cli.toCommands"] --> Adapter
  Adapter --> Candidates["completeWords"]
  Candidates --> Encoding["formatCompletions"]
  Encoding --> Shell
  Goldens["CLI parity tests"] -. compare saved output .-> Adapter
Loading

Reviews (3) · Last reviewed commit: "test(cli): keep root help goldens stable..." · Reviewed by Greptile

@morluto morluto changed the title test(cli): capture CLI parity goldens before replacing incur refactor(cli): own shell completion behind new CLI parity goldens Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI adapter and one-shot commands

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant