fix: Validate app name in adk create command

The `adk create` command now checks if the provided agent name is a valid Python identifier. An invalid name, such as one containing hyphens, will raise a `click.BadParameter` error before any files are created.

Close #3977

Co-authored-by: George Weale <gweale@google.com>
PiperOrigin-RevId: 853001295
This commit is contained in:
George Weale
2026-01-06 17:37:36 -08:00
committed by Copybara-Service
parent 9403a44f34
commit 742c9265a2
2 changed files with 25 additions and 0 deletions
@@ -156,6 +156,23 @@ def test_run_cmd_overwrite_reject(
)
def test_run_cmd_invalid_app_name(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> None:
"""Invalid app names should be rejected before creating any files."""
monkeypatch.setattr(os, "getcwd", lambda: str(tmp_path))
with pytest.raises(click.BadParameter, match="Invalid app name"):
cli_create.run_cmd(
"my-agent",
model="gemini-2.0-flash-001",
google_api_key=None,
google_cloud_project=None,
google_cloud_region=None,
type="code",
)
def test_run_cmd_with_type_config(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> None: