Fix: restore 'adk help' and 'adk help <command>' at the CLI root - #816
Open
AmaadMartin wants to merge 2 commits into
Open
Fix: restore 'adk help' and 'adk help <command>' at the CLI root#816AmaadMartin wants to merge 2 commits into
AmaadMartin wants to merge 2 commits into
Conversation
The root program sets an action handler so that a bare `adk -v` prints the version. Commander only registers its implicit `help [command]` subcommand when a command has subcommands AND no action handler, so the root lost `help` while the nested `deploy` and `integration` groups kept it. Call `program.helpCommand(true)` to re-enable it, and pin the behaviour with four new tests in `dev/test/cli/cli_test.ts`.
The structural guard accepted any object carrying a string `code`, so a stray Node error such as `ENOENT` would have passed it and the test would have asserted on the wrong error. `commander` exports `CommanderError`, so use it directly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
No existing issue.
Problem:
adk helpandadk help webfail witherror: too many arguments. The root program attaches an action handler so that a bareadk -vprints the version. Commander only registers its implicithelp [command]subcommand when a command has subcommands and no action handler (commander/lib/command.js:463-468), so the root losthelpwhile the nesteddeployandintegrationgroups kept it. The root usage block does not listhelpeither, so the gap is also undiscoverable.Solution:
createProgram()now callsprogram.helpCommand(true). That sets the flag_getHelpCommand()short-circuits on (commander/lib/command.js:409-417), so the implicit help command is registered despite the action handler. The change is additive:adk --help,adk web --helpandadk -vare unchanged, and the root usage block gains onehelp [command]line. A comment on the new statement records why it is needed, because commander addshelpby default everywhere else in this file.Collision check: I listed the open pull requests on the fork and read the diffs of the four that touch
dev/src/cli/cli.ts. None of them callshelpCommand. #597 and #706 rewrite the root.action()body; this statement sits outside that body, so it does not conflict with either.Before, on
main:After:
Testing Plan
Please describe the tests that you ran to verify your changes. This is required for all PRs that are not small documentation or typo fixes.
Unit Tests:
I added one
describe('command: help')block with four tests todev/test/cli/cli_test.ts. No existing test was changed.Two hazards the new block handles. Commander copies the exit callback into a subcommand when the subcommand is created, so the shared
exitOverride()inbeforeEachdoes not reach the subcommands, andadk help webwould call the realprocess.exitand kill the vitest worker. The newexitOverrideDeephelper walks the command tree. The sharedparsehelper also only swallowscommander.exit, so the block uses its own runner that returns theCommanderErrorcode and asserts on it.Mutation test 1 (proves the three help tests fail without the fix). I commented out
program.helpCommand(true)and re-ran the block:Mutation test 2 (proves the fourth test, the
<command> --helpregression guard, can fail). That test pins behaviour the fix must not change, so the first mutation leaves it green by design. I changed thewebdescription to'MUTATED description'instead:Coverage. The production change is one statement with no branches. A v8 run scoped to
dev/src/cli/cli.tsreports 30 hits on that line, so new line and branch coverage is 100%. The file total stays at its pre-existing 95.30% lines / 73.17% branches; the uncovered lines are other command handlers this change does not touch.Type check.
npm run ts:checkreports 287 errors onmainand 287 errors with this branch applied, none of them indev/src/cli/cli.tsordev/test/cli/cli_test.ts. The failures are pre-existing and unrelated.npx eslintandnpx prettier --checkare clean on both changed files.Manual End-to-End (E2E) Tests:
All six exit 0. The first three fail on
main.Checklist