refactor(cli): move CLI head dispatch into src/cli/root.ts - #1444
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 (1)
📝 WalkthroughWalkthroughThe CLI now delegates argument classification, help and version exits, ChangesCLI orchestration
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant CLIIndex
participant runCli
participant parseCliHead
participant CodexShimRestore
participant ReadyHandler
CLIIndex->>runCli: argv
runCli->>parseCliHead: classify argv
parseCliHead-->>runCli: CliHead with readyArgs
runCli->>CodexShimRestore: auto-restore
CodexShimRestore-->>runCli: completion
runCli-->>CLIIndex: dispatch state
CLIIndex->>ReadyHandler: handleReady(readyArgs)
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 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 |
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 `@tests/cli-head.test.ts`:
- Around line 37-50: Extend the existing “help flag after position 0” test
around parseCliHead to also assert that parseCliHead(["sync", "help"]) returns
the help result for command “sync”, preserving the matching args and helpTarget
values. Keep the new regression assertion alongside the existing --help and -h
cases.
🪄 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: 92717d41-d61c-43dc-b0ad-559e78ec5de9
📒 Files selected for processing (4)
src/cli/index.tssrc/cli/root.tstests/cli-head.test.tstests/cli-ready.test.ts
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.
|
The Phase 1 extraction is directionally sound: the version/help exits, I am not approving the current head yet for two state reasons:
Please rebase #1444 onto current |
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.
2c9694d to
c2da0f6
Compare
Summary
ocx readypre-parse with exit 64, and the Codex-shim auto-restore preflight) fromsrc/cli/index.tsinto the newsrc/cli/root.ts.parseCliHeadis pure (no I/O, no process access), so head ordering and the single-parse contract are unit-testable without subprocesses.runCliowns the exit paths and shim preflight, then returns the dispatchable head; the command switch stays insrc/cli/index.ts.ocx <cmd> --help,ocx help <sub>,ready --help, and invalidready→ exit 64 — and found identical exit codes and help text vs the pre-change head.Verification
bun run typecheck— pass (exit 0)bun test tests/cli-head.test.ts tests/cli-ready.test.ts tests/cli-help.test.ts— 74 pass / 0 failbun run privacy:scan— passbun test tests/repo-hygiene.test.ts— 11 passReview notes
parseCliHeadordering (help/version exits before thereadypre-parse, pre-parse before the shim preflight) and the single-parse contract. The source-level P1 guards intests/cli-ready.test.tswere relocated to pin the newsrc/cli/root.tshead.Checklist
Summary by CodeRabbit
New Features
readycommand arguments, including validation before execution.Bug Fixes
readyarguments now fail safely with exit code 64 without performing I/O.Tests