Skip to content

Commit 2638155

Browse files
Abdullah-k0decopybara-github
authored andcommitted
fix: disable Windows glob expansion for CLI args
This prevents Click from expanding wildcard arguments on Windows (e.g. `*` in `--allow_origins "*"`), avoiding errors when Click attempts to parse expanded filenames as unexpected positional arguments. Fixes #6248 PiperOrigin-RevId: 966756317
1 parent 2876987 commit 2638155

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

‎src/google/adk/cli/cli_tools_click.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ def _warn_if_with_ui(with_ui: bool) -> None:
276276
class TelemetryGroup(click.Group):
277277
"""Custom Click Group to wrap execution for telemetry tracking."""
278278

279+
def main(self, *args, **kwargs):
280+
kwargs.setdefault("windows_expand_args", False)
281+
return super().main(*args, **kwargs)
282+
279283
def parse_args(self, ctx: click.Context, args: list[str]) -> list[str]:
280284
ctx.telemetry_args = list(args) # type: ignore[attr-defined]
281285
return super().parse_args(ctx, args)

‎tests/unittests/cli/utils/test_cli_tools_click.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ def _mute_click(request, monkeypatch: pytest.MonkeyPatch) -> None:
102102
# monkeypatch.setattr(click, "secho", lambda *a, **k: None)
103103

104104

105+
def test_main_disables_click_windows_glob_expansion() -> None:
106+
"""Verifies the ADK CLI disables Click's Windows glob expansion."""
107+
with mock.patch.object(click.Group, "main", return_value=None) as mock_main:
108+
from google.adk.cli import main
109+
110+
main(args=["web", ".", "--allow_origins", "*"])
111+
assert mock_main.call_args.kwargs["windows_expand_args"] is False
112+
113+
105114
# validate_exclusive
106115
def test_validate_exclusive_allows_single() -> None:
107116
"""Providing exactly one exclusive option should pass."""

0 commit comments

Comments
 (0)