test(cli): add focused dispatch behavior tests - #1457
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review (2)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
|
✅ Deterministic PR hygiene checks passed. |
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)
f1a2233 to
0256994
Compare
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
0256994 to
295a52a
Compare
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.
295a52a to
2315e6c
Compare
Summary
Add focused behavior tests for the CLI dispatch module (final phase of the CLI deepening).
tests/cli-dispatch.test.tscovering the pure dispatch contract:DISPATCH_COMMANDS/DISPATCH_ALIASESinvariants, alias resolution (setup→init,eject→restore,remove→uninstall,model→models), anddispatchCommandexit-code returns for help forms (0) and unknown commands (1).Verification
tests/cli-dispatch.test.ts— 5 pass.bun run typecheck— exit 0.cli-restore-back(2) andPOST /api/syncownership (2) environmental cases.No GUI changes; no screenshot required.
Checklist
Review notes (stacked PR): stacks on #1456 (
codex/cli-help). Does not targetdev. 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.