refactor(cli): normalize process exit through dispatchCommand - #1455
Conversation
|
✅ Deterministic PR hygiene checks passed. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe CLI dispatch system now returns numeric exit codes from command runners through ChangesCLI exit-code propagation
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
0bb19e1 to
ee7fdbe
Compare
dc4688b to
b9889ef
Compare
cb952c0 to
46b18f0
Compare
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
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.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/cli/dispatch.ts`:
- Around line 374-375: Update the ready dispatch flow so normal results
propagate through the single top-level exit: change CliDispatchDeps.handleReady
to return Promise<number>, have index.ts handleReady return runReady(args)
instead of exiting, and preserve the missing-arguments 64 result. Add a focused
regression test alongside the existing ready dispatch tests covering a valid
ready command and asserting its result is returned.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: e7552f0b-afe6-42ea-8f30-dee98ae10f71
📒 Files selected for processing (3)
src/cli/dispatch.tssrc/cli/index.tstests/cli-ready.test.ts
Addresses CodeRabbit finding on #1455: handleReady was typed Promise<never> and called process.exit(await runReady(args)), so a valid 'ocx ready' terminated below the dispatcher instead of returning its code to the single top-level process.exit(await dispatchCommand(...)). - handleReady now returns Promise<number> and returns runReady(args) - CliDispatchDeps.handleReady typed Promise<number> - cli-ready source test updated to assert the return-through-dispatch behavior (body returns runReady, no process.exit); invalid-args 64 branch still covered
Summary
Normalize process exit handling so dispatch owns every exit code.
src/cli/dispatch.ts:CommandRunnerbecomes(deps) => Promise<number>. Every runner returns an exit code instead of callingprocess.exitor settingprocess.exitCodedirectly.dispatchCommandaggregates and returns the final code (unknown command → 1, help forms → 0).src/cli/index.ts: the singleprocess.exit(await dispatchCommand(...))is now the only exit site in the CLI entry.restore,route,integration,claude,ready, andhealthrunners preserve their per-branch exit codes as return values.Behavior is unchanged: exit code values and message text are identical; only the mechanism (return vs
process.exit) changed.Verification
bun run typecheck— exit 0.ocx --version— exit 0.ocx help nosuch— exit 1,Unknown command: nosuch.ocx ready --timeout 5— exit 64.ocx sync --help— exit 0.cli-restore-back(2) andPOST /api/sync(2) cases.No GUI changes; no screenshot required.
Checklist
Review notes (stacked PR): stacks on #1451 (
codex/cli-dispatch). Does not targetdev. Diff is only the exit normalization (0bb19e1e..300c9cda): 3 files, +90/−66. Merge only after #1444, #1446, #1451 land.Summary by CodeRabbit
Bug Fixes
Tests