Skip to content

Disable Windows glob expansion for CLI args#6166

Open
Abdullah-k0de wants to merge 4 commits into
google:mainfrom
Abdullah-k0de:fix-windows-click-glob-expansion
Open

Disable Windows glob expansion for CLI args#6166
Abdullah-k0de wants to merge 4 commits into
google:mainfrom
Abdullah-k0de:fix-windows-click-glob-expansion

Conversation

@Abdullah-k0de

Copy link
Copy Markdown

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

2. Or, if no issue exists, describe the change:

No ADK issue currently exists for this specific root-cause fix, so this PR describes the bug directly using the issue-template structure.

Describe the Bug

On Windows, running adk web with --allow_origins "*" causes the * argument to be expanded into filenames from the current working directory before the web command handler is invoked.

This causes Click to reject those expanded filenames as unexpected positional arguments.

This issue was originally observed through google/agents-cli playground, where agents-cli invokes adk web with --allow_origins "*". The same behavior reproduces directly with adk web, so this PR addresses the root ADK CLI behavior.

Steps to Reproduce

  1. Clone and set up google/adk-python on Windows.

  2. Create a local test directory containing files/folders such as:

    text, Dockerfile, README.md, show_argv.py, tests

  3. From that directory, run:

    uv run --project "..\adk-python" adk web . --host 127.0.0.1 --port 8080 --allow_origins "*" --reload_agents

  4. Observe that the command fails before the web command handler runs.

Expected Behavior

adk web should treat * as the literal value for --allow_origins, start the local ADK web server, and make the UI available at:

http://127.0.0.1:8080

Observed Behavior

Before this change, the command fails with:


Try 'adk web --help' for help.

Error: Got unexpected extra arguments (Dockerfile README.md show_argv.py tests)

Environment Details

  • ADK Library Version: local google/adk-python checkout from main
  • Desktop OS: Windows
  • Python Version: Python 3.12.8

Model Information

  • Are you using LiteLLM: N/A
  • Which model is being used: N/A

Problem:
On Windows, running adk web with --allow_origins "*" causes Click to expand the * into filenames from the current working directory before the web command handler runs. This makes the CLI fail with unexpected extra arguments such as Dockerfile, README.md, and tests instead of treating * as the intended literal CORS origin.

Root Cause

I verified that the expansion was not caused by PowerShell, cmd.exe, or uv by testing a simple sys.argv script:

  • python .\show_argv.py "*"

  • uv run --project "..\adk-python" python .\show_argv.py "*"

Both commands correctly passed * as a literal argument.
The failure happens before cli_web() runs, which points to Click's Windows argument expansion behavior at the root CLI invocation layer.

Solution:
This PR introduces a small custom Click group that disables Click's Windows glob expansion by setting:
windows_expand_args=False at the root ADK CLI group.
This prevents Click from expanding wildcard arguments on Windows and allows --allow_origins "*" to be passed correctly as a literal CORS origin.

The change is intentionally scoped to the root CLI group so it applies consistently across ADK CLI commands without changing the behavior of individual command handlers.

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 have added or updated unit tests for my change.
  • All unit tests pass locally.

I added a focused unit test to verify that the root ADK CLI disables Click's Windows glob expansion.

Passed:
uv run pytest tests/unittests/cli/utils/test_cli_tools_click.py -k "windows_glob_expansion"

Result:
1 passed, 41 deselected, 4 warnings

I also ran the related CLI option mismatch tests:
uv run pytest tests/unittests/cli/test_cli_tools_click_option_mismatch.py

Result:
8 passed, 4 warnings

I also attempted to run the full related test file:
uv run pytest tests/unittests/cli/utils/test_cli_tools_click.py

That run produced one failure in:
test_cli_eval_with_eval_set_file_path

To verify this was unrelated to my change, I switched back to main and ran the failing test directly:

git switch main
uv run pytest tests/unittests/cli/utils/test_cli_tools_click.py::test_cli_eval_with_eval_set_file_path

The same test also failed on main, so this appears unrelated to this PR. The failing test concerns eval result storage, while this PR only changes Click argument expansion behavior at the root CLI layer.

Manual End-to-End (E2E) Tests:

I manually verified the fix on Windows.

Test setup:
I created a local test directory containing files/folders that would expose unwanted wildcard expansion:
Dockerfile, README.md, show_argv.py, tests

Manual test command:
uv run --project "..\adk-python" adk web . --host 127.0.0.1 --port 8080 --allow_origins "*" --reload_agents

Before this change, the command failed with:
Error: Got unexpected extra arguments (Dockerfile README.md show_argv.py tests)

After this change, the ADK web server started successfully:

For local testing, access at http://127.0.0.1:8080.

The server then shut down cleanly after pressing CTRL+C.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

This fix helps unblock Windows users who run ADK through tools that pass --allow_origins "*", including google/agents-cli playground.

This was initially reported in google/agents-cli, where a maintainer confirmed that the same behavior reproduces when invoking adk web directly and that the root issue appears to belong in ADK rather than agents-cli.

Screenshot from the related google/agents-cli discussion:
issue on agents-cli

The issue is Windows-specific because Click performs argument expansion on Windows unless windows_expand_args=False is set.

@Abdullah-k0de

Copy link
Copy Markdown
Author

Pushed an update to address the CI feedback.

Changes made:

  • Kept the Windows glob-expansion fix scoped to the Click entrypoint.
  • Replaced direct click.Group subclassing with a typed alias/cast-based approach to avoid the new mypy subclassing error.
  • Added type annotations to the custom main() override.
  • Ran pre-commit on src/google/adk/cli/cli_tools_click.py; the relevant Python hooks (ruff, isort, pyink, and addlicense) pass locally.

Notes:

  • The only local pre-commit failure is check-new-py-prefix, because /bin/bash is not available in my Windows environment. That hook is expected to run in the Linux CI environment.
  • I intentionally did not modify the unrelated eval_result duplicate-definition section, as this PR only changes the Click argument handling path.
  • The remaining Python 3.11 BigQuery unit test failure also appears unrelated to this PR, since the change is isolated to CLI argument handling.

Happy to make any additional changes if you would prefer a different implementation or typing approach.

@rohityan

Copy link
Copy Markdown
Collaborator

Hi @Abdullah-k0de , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Can you please fix the failing unit tests and mypy-diff tests before we can proceed with the review.

@rohityan rohityan added the request clarification [Status] The maintainer need clarification or more information from the author label Jun 26, 2026
@Abdullah-k0de Abdullah-k0de force-pushed the fix-windows-click-glob-expansion branch from ad5ff76 to b1e0fa3 Compare June 26, 2026 10:34
@Abdullah-k0de

Copy link
Copy Markdown
Author

Pushed an update addressing the failing unit tests and mypy-diff feedback.

Changes made:

  • Removed the custom Click Group subclass approach.
  • Kept the Windows glob-expansion fix scoped to the CLI entrypoint.
  • Restored Cloud Run argument handling to the upstream behavior.
  • Updated the regression test for the entrypoint behavior.
  • Fixed the duplicate eval_result annotation issue that was causing mypy-diff failures.

Local verification:

  • test_main_disables_click_windows_glob_expansion passes.
  • The three previously failing Cloud Run tests now pass locally:
    • test_cli_deploy_cloud_run_interspersed_options
    • test_cli_deploy_cloud_run_rejects_unknown_option_before_separator
    • test_cli_deploy_cloud_run_forwards_extra_positional_arg

The remaining workflows appear to be awaiting maintainer approval before they can run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

request clarification [Status] The maintainer need clarification or more information from the author tools [Component] This issue is related to tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants