Fix: make bare adk telemetry exit 0 on Click >= 8.2 - #53
Open
AmaadMartin wants to merge 1 commit into
Open
Conversation
A plain `click.Group` gets `no_args_is_help=True`. Click 8.1.x printed the group help and exited 0 for a bare invocation; Click 8.2.0 and later raise a usage error instead, still printing the help but exiting 2. `pyproject.toml` allows `click>=8.1.8,<9` and the repo has no lockfile, so CI resolves the newest Click and `adk telemetry` returns a non-zero status for what is really a help request. That also broke `test_telemetry_cli_commands`, the single failing test in `tests/unittests`. Declare the group with `invoke_without_command=True` and echo the help from the callback, which is exit-code 0 on every Click version the project allows. `adk telemetry <unknown>` still exits 2, and the three subcommands are untouched. Also strengthen the bare-invocation assertions so they pin the actual group help (docstring plus the three subcommand names) rather than any output containing "Usage:".
This was referenced Jul 30, 2026
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 public issue is filed for this; it is a CI failure on
main.Problem:
tests/unittests/cli/utils/test_cli_tools_click.py::test_telemetry_cli_commandsis the only failing test intests/unittestsonmain, and it fails on every Python version in the Unit Tests matrix.telemetryis declared as a plain Click group (src/google/adk/cli/cli_tools_click.py:293). Aclick.Groupbuilt that way getsno_args_is_help=True. On Click 8.1.x a bareadk telemetryprinted the group help and exited 0; from Click 8.2.0 onwards the same invocation raisesNoArgsIsHelpError(aUsageErrorsubclass) — it still prints the full help text but exits 2.pyproject.tomlpinsclick>=8.1.8,<9and the repo has no lockfile, souv sync --extra testin CI resolves the newest compatible Click (8.4.2 today). The test was authored against a locally resolved 8.1.x, so it passed then and fails now:Measured exit code of bare
adk telemetryagainst the unchanged group, on this checkout:This is a user-visible regression, not just a test artifact: with a current Click, a plain help request returns a failure status to the shell.
Solution: Declare the group with
invoke_without_command=Trueand echo the help from the callback:Group.__init__setsno_args_is_help = not invoke_without_command, so this disables the implicit usage error and the callback returns normally — exit 0 on every Click version the pin allows, restoring the 8.1.x behaviour rather than baking in 8.2+ behaviour.adk telemetry <unknown>still exits 2 (a genuine usage error), andstatus/enable/disableare untouched.Alternatives rejected: changing the assertion to
== 2(orin (0, 2)) bakes in Click ≥ 8.2 whilepyproject.tomlstill permits 8.1.8, and leaves the user-visible regression in place; raising theclickfloor forces a dependency bump on downstream users to work around a test expectation and still leavesadk telemetryexiting 2. No dependency pin was changed.The usage line legitimately becomes
[COMMAND] [ARGS]...(COMMAND is now optional). No user-facing docs in this repository mentionadk telemetry, so no doc update is needed.Collision check (required by the contribution workflow):
gh pr list --repo AmaadMartin/adk-python --state open --limit 100returned 50 open PRs; 17 of them touchcli_tools_click.py, so each was diffed and grepped forinvoke_without_command,no_args_is_help, andtest_telemetry_cli_commands. Zero hits — no open PR lands or overlaps this change, so this branches frommain.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:
The change adds two executable lines. Both are covered and both branches are exercised, measured with
coverage run --branch --source=google.adk.cli.cli_tools_click: for the patched region,missing_linesis empty and neither branch ofif ctx.invoked_subcommand is Noneappears inmissing_branches— 100% line and branch coverage of the new code. TheNonebranch comes fromrunner.invoke(main, ["telemetry"]); the not-Nonebranch from the fivestatus/enable/disableinvocations that follow.I strengthened the bare-invocation assertions (the group docstring plus all three subcommand names) so the test proves the group help was printed, rather than any output merely containing
"Usage:". The pre-existingassert result.exit_code == 0was deliberately not relaxed — that assertion is what pins the fix. No test was skipped, weakened, or deleted.Proof the tests can fail — each new/changed assertion was run against mutated source and observed to fail:
@main.group("telemetry")assert result.exit_code == 0→E assert 2 == 0invoke_without_command=Truebut replaceclick.echo(ctx.get_help())withpassE AssertionError: assert 'Usage:' in ''click.echo(ctx.get_help())withclick.echo("Usage: adk telemetry")— output contains"Usage:"but is not the group helpE AssertionError: assert 'Manage telemetry settings.' in 'Usage: adk telemetry\n'Mutation C is the one that justifies the added assertions: the pre-existing
"Usage:"check alone survives it.Click-version independence (the whole point of the change) —
pytest tests/unittests/cli/utils/test_cli_tools_click.py -qon each version permitted byclick>=8.1.8,<9:On 8.2.0 exactly one failure remains,
test_cli_deploy_agent_engine_otel_to_cloud_success. It is pre-existing and unrelated — it fails identically on unmodifiedmainwith click 8.2.0 and passes on 8.1.8, 8.3.0 and 8.4.2, so it is a defect specific to that one Click release and out of scope here. It has been filed separately rather than bundled into this fix.Lint and type checks on the changed files, matching the versions pinned in
.pre-commit-config.yaml:Mypy was run the same way the Mypy Check job compares baseline to PR (
mypy ... | grep error: | sed 's/:\([0-9]\+\):/::/g' | sort, thencomm -13): 93 pre-existing errors in this file before the change, 93 after, 0 new errors.Manual End-to-End (E2E) Tests:
Run against the real installed
adkentry point with no mocks, withHOMEpointed at a temporary directory so the consent file is isolated:All of the above were observed with those exact outputs and exit codes, and the enable/disable round trip really wrote
$TEST_HOME/.adk/config.json.CI result on this PR
All test jobs pass — including the Unit Tests matrix this change exists to repair:
The Pre-commit Linter failure is not caused by this diff. Every hook passes; the sole failing hook is
update-constraints, which dies with./scripts/update_constraints.sh: line 103: uv: command not foundbecause the lint job never installsuv. That hook is scoped tofiles: ^(pyproject\.toml|constraints-.*\.txt)$— neither of which this PR touches — and only executes at all because the CI action invokespre-commit run --all-files. The identical failure reproduces on other open PRs with unrelated diffs.Locally,
pre-commit run --files src/google/adk/cli/cli_tools_click.py tests/unittests/cli/utils/test_cli_tools_click.pypasses every hook, withupdate-constraintscorrectly reported as(no files to check) Skipped.That lint-job defect is already being fixed by a separate open PR that moves the hook to
stages: [manual], so it is deliberately not duplicated here.Checklist