fix(cli): error on unknown command root when --help/--version is appended (#81077)#81083
Conversation
|
Codex review: needs maintainer review before merge. Summary Reproducibility: yes. source-reproducible: current main skips unknown-primary validation when Real behavior proof Next step before merge Security Review detailsBest possible solution: Land the focused CLI dispatch fix after normal required checks, preserving root/browser help fast paths and the new regression coverage. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: current main skips unknown-primary validation when Is this the best way to solve the issue? Yes. The PR targets the dispatch gate directly and places validation after legitimate root/browser help fast paths, which is narrower than changing Commander help rendering or broad CLI registration behavior. What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against b4284271082f. Re-review progress:
|
c80823c to
cc545c5
Compare
…nded (openclaw#81077) openclaw <unknown-command> --help silently fell through to generic top-level help and exited 0, while the same openclaw <unknown-command> (no --help) correctly errored with "Unknown command" and exited 1. The asymmetry was caused by two short-circuits on invocation.hasHelpOrVersion: resolveUnownedCliPrimary bailed before the unknown-primary check, and the only caller was gated on !isHelpOrVersionInvocation. Drop the hasHelpOrVersion bail in resolveUnownedCliPrimary so the helper continues to validate the primary when --help or --version is present, and add an unconditional caller in runCli after the root and browser help fast paths so legitimate help (openclaw --help, openclaw status --help, openclaw browser --help) still dispatches normally while unknown roots error consistently regardless of trailing flags. Verified: - pnpm test src/cli/run-main.exit.test.ts src/cli/argv.test.ts src/cli/argv-invocation.test.ts (76 passed) - pnpm exec oxfmt --check --threads=1 src/cli/run-main.ts src/cli/run-main.exit.test.ts (clean) - pnpm build && node openclaw.mjs heartbeat --help (exit 1, Unknown command error) - pnpm build && node openclaw.mjs status --help (exit 0, status help renders) - pnpm build && node openclaw.mjs browser --help (exit 0, browser help renders) - pnpm build && node openclaw.mjs --help (exit 0, root help renders) Closes openclaw#81077
cc545c5 to
c6c4d71
Compare
|
Thanks @steipete |
…YB0y) Behavior addressed: Unknown CLI command roots now error consistently even when --help or --version is appended, while legitimate built-in help fast paths still render normally. Real environment tested: Local OpenClaw source checkout plus GitHub workflow run-level status. Exact steps or command run after this patch: pnpm test src/cli/run-main.exit.test.ts src/cli/argv.test.ts src/cli/argv-invocation.test.ts; pnpm exec oxfmt --check --threads=1 src/cli/run-main.ts src/cli/run-main.exit.test.ts; autoreview --mode branch --base origin/main --no-web-search. Evidence after fix: Focused CLI test shards passed 178 tests; formatter clean; autoreview reported no accepted/actionable findings; GitHub CI run 26422344121 and CodeQL Critical Quality run 26422344090 completed successfully. Observed result after fix: `openclaw foo --help` and `openclaw foo --version` reject before proxy/program startup, while known help fast paths remain ahead of the unknown-root guard. What was not tested: Full local build; contributor PR body already supplied build/CLI command proof before rebase. Co-authored-by: YB0y <brianandez6@gmail.com>
…YB0y) Behavior addressed: Unknown CLI command roots now error consistently even when --help or --version is appended, while legitimate built-in help fast paths still render normally. Real environment tested: Local OpenClaw source checkout plus GitHub workflow run-level status. Exact steps or command run after this patch: pnpm test src/cli/run-main.exit.test.ts src/cli/argv.test.ts src/cli/argv-invocation.test.ts; pnpm exec oxfmt --check --threads=1 src/cli/run-main.ts src/cli/run-main.exit.test.ts; autoreview --mode branch --base origin/main --no-web-search. Evidence after fix: Focused CLI test shards passed 178 tests; formatter clean; autoreview reported no accepted/actionable findings; GitHub CI run 26422344121 and CodeQL Critical Quality run 26422344090 completed successfully. Observed result after fix: `openclaw foo --help` and `openclaw foo --version` reject before proxy/program startup, while known help fast paths remain ahead of the unknown-root guard. What was not tested: Full local build; contributor PR body already supplied build/CLI command proof before rebase. Co-authored-by: YB0y <brianandez6@gmail.com>
…YB0y) Behavior addressed: Unknown CLI command roots now error consistently even when --help or --version is appended, while legitimate built-in help fast paths still render normally. Real environment tested: Local OpenClaw source checkout plus GitHub workflow run-level status. Exact steps or command run after this patch: pnpm test src/cli/run-main.exit.test.ts src/cli/argv.test.ts src/cli/argv-invocation.test.ts; pnpm exec oxfmt --check --threads=1 src/cli/run-main.ts src/cli/run-main.exit.test.ts; autoreview --mode branch --base origin/main --no-web-search. Evidence after fix: Focused CLI test shards passed 178 tests; formatter clean; autoreview reported no accepted/actionable findings; GitHub CI run 26422344121 and CodeQL Critical Quality run 26422344090 completed successfully. Observed result after fix: `openclaw foo --help` and `openclaw foo --version` reject before proxy/program startup, while known help fast paths remain ahead of the unknown-root guard. What was not tested: Full local build; contributor PR body already supplied build/CLI command proof before rebase. Co-authored-by: YB0y <brianandez6@gmail.com>
…YB0y) Behavior addressed: Unknown CLI command roots now error consistently even when --help or --version is appended, while legitimate built-in help fast paths still render normally. Real environment tested: Local OpenClaw source checkout plus GitHub workflow run-level status. Exact steps or command run after this patch: pnpm test src/cli/run-main.exit.test.ts src/cli/argv.test.ts src/cli/argv-invocation.test.ts; pnpm exec oxfmt --check --threads=1 src/cli/run-main.ts src/cli/run-main.exit.test.ts; autoreview --mode branch --base origin/main --no-web-search. Evidence after fix: Focused CLI test shards passed 178 tests; formatter clean; autoreview reported no accepted/actionable findings; GitHub CI run 26422344121 and CodeQL Critical Quality run 26422344090 completed successfully. Observed result after fix: `openclaw foo --help` and `openclaw foo --version` reject before proxy/program startup, while known help fast paths remain ahead of the unknown-root guard. What was not tested: Full local build; contributor PR body already supplied build/CLI command proof before rebase. Co-authored-by: YB0y <brianandez6@gmail.com>
…YB0y) Behavior addressed: Unknown CLI command roots now error consistently even when --help or --version is appended, while legitimate built-in help fast paths still render normally. Real environment tested: Local OpenClaw source checkout plus GitHub workflow run-level status. Exact steps or command run after this patch: pnpm test src/cli/run-main.exit.test.ts src/cli/argv.test.ts src/cli/argv-invocation.test.ts; pnpm exec oxfmt --check --threads=1 src/cli/run-main.ts src/cli/run-main.exit.test.ts; autoreview --mode branch --base origin/main --no-web-search. Evidence after fix: Focused CLI test shards passed 178 tests; formatter clean; autoreview reported no accepted/actionable findings; GitHub CI run 26422344121 and CodeQL Critical Quality run 26422344090 completed successfully. Observed result after fix: `openclaw foo --help` and `openclaw foo --version` reject before proxy/program startup, while known help fast paths remain ahead of the unknown-root guard. What was not tested: Full local build; contributor PR body already supplied build/CLI command proof before rebase. Co-authored-by: YB0y <brianandez6@gmail.com>
…YB0y) Behavior addressed: Unknown CLI command roots now error consistently even when --help or --version is appended, while legitimate built-in help fast paths still render normally. Real environment tested: Local OpenClaw source checkout plus GitHub workflow run-level status. Exact steps or command run after this patch: pnpm test src/cli/run-main.exit.test.ts src/cli/argv.test.ts src/cli/argv-invocation.test.ts; pnpm exec oxfmt --check --threads=1 src/cli/run-main.ts src/cli/run-main.exit.test.ts; autoreview --mode branch --base origin/main --no-web-search. Evidence after fix: Focused CLI test shards passed 178 tests; formatter clean; autoreview reported no accepted/actionable findings; GitHub CI run 26422344121 and CodeQL Critical Quality run 26422344090 completed successfully. Observed result after fix: `openclaw foo --help` and `openclaw foo --version` reject before proxy/program startup, while known help fast paths remain ahead of the unknown-root guard. What was not tested: Full local build; contributor PR body already supplied build/CLI command proof before rebase. Co-authored-by: YB0y <brianandez6@gmail.com>
Fixes #81077.
Summary
openclaw <unknown-command> --helpsilently fell through to generic top-level help and exited 0, while the sameopenclaw <unknown-command>(no--help) correctly errored withUnknown command: openclaw <name>. No built-in command or plugin CLI metadata owns "<name>"and exited 1. The asymmetry is atsrc/cli/run-main.ts:369-377and the gated caller at line 494, both of which short-circuited the unknown-primary check wheninvocation.hasHelpOrVersionwas true.This PR:
invocation.hasHelpOrVersion ||bail inresolveUnownedCliPrimaryso the helper continues to validate the primary when--helpor--versionis present.runCliafter the root and browser help fast paths, before any other dispatch. Legitimate help paths (openclaw --help,openclaw status --help,openclaw browser --help, etc.) keep working through the precomputed fast paths or the standard built-in/plugin help routing; unknown roots now error consistently regardless of--help/--version.src/cli/run-main.exit.test.tsparalleling the existing no-help unknown-root test.Real behavior proof
Behavior or issue addressed:
openclaw <unknown-command> --helpsilently rendered generic top-level help and exited 0, hiding from the user that the command they typed does not exist; the same invocation without--helpcorrectly errored and exited 1. See [Bug]:openclaw <unknown-command> --helpsilently shows generic top-level help (exit 0); same command without--helpcorrectly errors withUnknown command(exit 1) #81077.Real environment tested: Local source checkout rebased on
upstream/main,pnpm buildagainst the working tree, Node v22.22.2 via nvm, pnpm 10.33.0, Linux x86_64 (Ubuntu noble). Real CLI invocation vianode openclaw.mjs <args>so the wrapper is exercised the same way an installed npm global runs.Exact steps or command run after this patch:
Evidence after fix: Verbatim terminal output (stdout+stderr merged) from the local CLI:
Observed result after fix:
openclaw heartbeat,openclaw heartbeat --help, andopenclaw heartbeat --versionall error consistently with the sameUnknown commandmessage and all exit 1.openclaw --help,openclaw status --help, andopenclaw browser --helpstill render their respective help and exit 0. This matches the bot's acceptance criteria on [Bug]:openclaw <unknown-command> --helpsilently shows generic top-level help (exit 0); same command without--helpcorrectly errors withUnknown command(exit 1) #81077 ("Manual/source run after fix …openclaw heartbeat --help; echo exit=$?should show the unknown-command error and exit 1") and preserves the existing built-in / precomputed-help paths.What was not tested: A live invocation through an installed
npm install -g openclawglobal binary. The proof above uses the in-tree wrappernode openclaw.mjs, which exercises the samerunClidispatch path the installed binary runs against the built dist. The unit tests insrc/cli/run-main.exit.test.tsalso pin the rejection behavior through the mocked program builder.Verification