Skip to content

test(cli): add focused dispatch behavior tests - #1457

Open
Wibias wants to merge 10 commits into
codex/cli-helpfrom
codex/cli-tests
Open

test(cli): add focused dispatch behavior tests#1457
Wibias wants to merge 10 commits into
codex/cli-helpfrom
codex/cli-tests

Conversation

@Wibias

@Wibias Wibias commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add focused behavior tests for the CLI dispatch module (final phase of the CLI deepening).

  • Adds tests/cli-dispatch.test.ts covering the pure dispatch contract: DISPATCH_COMMANDS/DISPATCH_ALIASES invariants, alias resolution (setup→init, eject→restore, remove→uninstall, model→models), and dispatchCommand exit-code returns for help forms (0) and unknown commands (1).

Verification

  • tests/cli-dispatch.test.ts — 5 pass.
  • bun run typecheck — exit 0.
  • Full-stack CLI suite — 213 pass; the only 4 failures are the known pre-existing cli-restore-back (2) and POST /api/sync ownership (2) environmental cases.

No GUI changes; no screenshot required.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Review notes (stacked PR): stacks on #1456 (codex/cli-help). Does not target dev. Diff is only the new dispatch behavior test (e897d990..f1a22339): 1 file, +50. Merge only after the earlier phases (#1444, #1446, #1451, #1455, #1456) land.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (2)
  • ^dev$
  • ^preview$

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d544f59c-b231-4dad-8b84-2d6fb86fe6df

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature). label Aug 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

Wibias added 5 commits August 11, 2026 07:58
Phase 1 of the CLI deepening: version/help early exits, the ocx ready
pre-parse (exit 64 before any preflight), and the bounded Codex-shim
auto-restore preflight move from src/cli/index.ts into a new pure module
src/cli/root.ts. index.ts now awaits runCli() and dispatches via its
existing switch; behavior is preserved byte-for-byte.

- parseCliHead is pure and unit-tested (tests/cli-head.test.ts)
- P1 source-guards in tests/cli-ready.test.ts relocate to root.ts
- cli-head/cli-ready/cli-help: 74 pass; typecheck green
CodeRabbit finding on #1444: the help-flag test covered --help and -h
after position 0 but not the bare 'help' token, which hasHelpFlag also
matches.
Phase 2 of the CLI deepening: command names, aliases, usage, summary,
and details move from src/cli/help.ts into src/cli/registry.ts
(CLI_COMMANDS + findCommand). help.ts becomes a thin renderer over the
registry; behavior is unchanged.

- 48 visible entries in original order, plus 6 hidden __* entries
- alias pairs: init/setup, restore/eject, uninstall/remove, models/model
- exact-name-wins lookup keeps alias-name entries' own help text
- tests/cli-registry.test.ts pins switch-case <-> registry parity
- all 48 help outputs byte-identical; typecheck green
Addresses CodeRabbit finding on #1446: the previous assertion let an
alias case satisfy a missing canonical case, so dropping e.g. 'init'
while 'setup' remained would pass. Require each entry.name directly in
caseSet.
Phase 3 of the CLI deepening: extract the command switch out of
src/cli/index.ts into src/cli/dispatch.ts as a registry-driven runner
table. index.ts becomes a thin main that passes its local lifecycle
helpers through CliDispatchDeps; aliases resolve via the registry alias
map.

- dispatchCommand(head, deps) replaces the 61-case switch
- behavior preserved: restore/sync/sync-cache/claude/route/integration/
  health/ready/gui/codex-shim/update runners match the original bodies
- source-level tests migrated to read dispatch.ts
- typecheck green; CLI suite 211 pass (4 known pre-existing failures)
Wibias added 2 commits August 11, 2026 08:30
Phase 3 moved the command switch into src/cli/dispatch.ts as runner
keys, but tests/codex-app-server-processes.test.ts still sliced the old
case labels out of src/cli/index.ts. Update it to read the sync,
sync-cache, v2, and gui runner bodies from dispatch.ts (using deps.args),
which restores the #476 sync/sync-cache app-server-wiring assertions.
Phase 4 of the CLI deepening: dispatch runners now RETURN exit codes
instead of calling process.exit/setting process.exitCode directly.
dispatchCommand aggregates and returns the final code; index.ts performs
the single process.exit(await dispatchCommand(...)).

- CommandRunner becomes (deps) => Promise<number>
- unknown command -> 1, help/--help/-h/undefined -> 0
- restore/route/integration/claude/ready/health runners return their codes
- behavior preserved: smoke tests (version 0, help nosuch 1, ready
  invalid 64, sync --help 0) pass; cli-ready runner assertion updated
Wibias added 2 commits August 11, 2026 09:01
Phase 4 exit normalization made runners return 0, but handlers passed via
deps (handleStart/handleStop/handleStatus/handleEnsure/handleUninstall/
handleRecoverHistory/handleProxyRestart/handleTrayProxyRestart) and
runInit set process.exitCode internally. The hardcoded return 0 overrode
those codes (e.g. ocx init exited 0 instead of 1 on stdin EOF). Return
process.exitCode ?? 0 so the handler-set codes are preserved.
Phase 5 of the CLI deepening:
- fold src/cli/internal-dispatch.ts into src/cli/dispatch.ts as three
  explicit runner entries (__tray-start, __tray-restart,
  __startup-health) that use the injected deps directly; delete the
  module and its dedicated test
- add banner-coverage test to cli-registry.test.ts and fix the drift it
  caught: printUsage now lists the previously-missing visible commands
  (route, logs, api-key)

Behavior preserved: typecheck green; 144 pass / 4 known pre-existing
environmental failures; smoke tests (version 0, help nosuch 1, ready
invalid 64, --help header+new lines) pass
Phase 6 (final) of the CLI deepening: add tests/cli-dispatch.test.ts
covering the pure dispatch contract — DISPATCH_COMMANDS/DISPATCH_ALIASES
invariants, alias resolution (setup/init, eject/restore, remove/uninstall,
model/models), and dispatchCommand exit-code returns for help forms (0)
and unknown commands (1).

Full-stack verification: 213 pass / 4 known pre-existing environmental
failures; typecheck green.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant