Fix: select the Vertex backend the user actually chose in adk create - #829
Open
AmaadMartin wants to merge 3 commits into
Open
Fix: select the Vertex backend the user actually chose in adk create#829AmaadMartin wants to merge 3 commits into
AmaadMartin wants to merge 3 commits into
Conversation
added 3 commits
August 8, 2026 15:53
generateEnvFile decided the backend from the fields that happened to be filled in, so a Vertex project with no region wrote a .env with neither GOOGLE_CLOUD_LOCATION nor GOOGLE_GENAI_USE_VERTEXAI. The runtime then took the Gemini API path and demanded an API key. The project now selects Vertex on its own and supplies us-central1 when no region is known, and the interactive Vertex prompts reject an empty answer. This matches the contract adk-python settles in its onboarding prompts.
Covers the empty-region fallback, the exactly-one-selector invariant, the prompt validator and the trimmed answers, plus a runtime-level check that the scaffolded .env resolves to the Vertex AI backend.
…validator The =0 selector now sits in the api-key block it belongs to, so options.apiKey is tested once and the region line becomes an else-if. The region prompt is pre-filled and the writer already substitutes us-central1 for an empty answer, so its validator was unreachable in practice and its message was untrue. The project prompt keeps the validator; it has no fallback.
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 open issue tracks this defect.
Problem:
generateEnvFilepicks the backend from the fields that happen to be filled in, not from the backend the user chose. A user who picks Vertex AI and leaves the region empty gets a.envwith onlyGOOGLE_CLOUD_PROJECT, so the runtime takes the Gemini API path and demands an API key. The region is empty wheneverGOOGLE_CLOUD_LOCATIONand gcloudcompute/regionare both unset, andadk create demo -y --project preaches the same state. An--api_keyplus--projectplus--regioninvocation also writes bothGOOGLE_GENAI_USE_VERTEXAI=0and=1.Solution: The project now selects the Vertex backend on its own, and the writer supplies
us-central1when no region is known. The interactive project prompt rejects an empty answer, both Vertex answers are trimmed, and the region prompt is pre-filled with the default. This matches adk-python, where_onboarding.prompt_strloops until the answer is non-empty andprompt_for_google_cloud_regionoffersus-central1.us-central1is the default adk-js already uses inAgentEngineSandboxCodeExecutor.Notes:
GOOGLE_GENAI_USE_VERTEXAIline is now emitted. The duplicate=0and=1pair is no longer possible.us-central1for it.Ctrl+Cstill exits through the existingisCancelguards.dev/src/cli/cli_create.ts. Six open PRs (Fix: pin GOOGLE_CLOUD_* env vars in cli_create_test so the gcloud defaults are actually testable #569, Fix: make cli_create_test hermetic against ambient GOOGLE_CLOUD_* env vars (duplicate of #569) #576, Fix: isolate cli_create tests from ambient Google Cloud env vars (DUPLICATE of #569 — recommend closing) #589, Fix: install the cli_create console spies per test so the CLI unit tests stay silent #666, Fix: let createFolder reject with the original fs.mkdir error so adk create reports the root cause #704, Fix: let removeFolder reject with the original fs.rm error #815) touchdev/test/cli/cli_create_test.tson unrelated concerns, so this branch adds newitblocks and changes one existing line only:vi.unstubAllEnvs()in theafterEach.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:
[x] I have added or updated unit tests for my change.
[x] All unit tests pass locally.
Command:
Result: 20 passed. Every line and branch this branch adds to
dev/src/cli/cli_create.tsis covered, measured with--coverage.include='dev/src/cli/cli_create.ts'.Every new test was proven able to fail. Each mutation reverts one hunk of the fix:
generateEnvFilebodyselects the Vertex backend when no region is availableAPI key must be provided via constructor or GOOGLE_GENAI_API_KEY or GEMINI_API_KEY environment variable.generateEnvFilebodyshould write exactly one backend selector when an api key and a project are both providedexpected [ '0', '1' ] to deeply equal [ '1' ]generateEnvFilebodyshould still select Vertex when the region comes back empty,should set Vertex AI env vars when only a project is providedexpected "spy" to be called with arguments: [ StringContaining ".env", …(1) ]!options.projectguard on the=0selectorshould write exactly one backend selector when an api key and a project are both providedexpected [ '0', '1' ] to deeply equal [ '1' ]validatefrom the project promptshould reject an empty project at the promptthe project prompt received no validate callbackinitialValueon the region promptshould seed the region prompt with the default location when gcloud has noneexpected "spy" to be called with arguments: [ ObjectContaining{…} ].trim()callsshould trim the Vertex answersexpected "spy" to be called with arguments: [ StringContaining ".env", …(1) ]One pre-existing test fails on a machine that exports
GOOGLE_CLOUD_PROJECT:should handle Vertex AI selection with gcloud defaultsreads the ambient value throughgetGcpProject(). It fails the same way on unmodifiedmain, and open PRs #569, #576 and #589 propose the suite-wide fix. The new tests stub the two variables themselves, so they pass either way.Manual End-to-End (E2E) Tests:
Please provide instructions on how to manually test your changes, including any necessary setup or configuration.
Observed output for that command and for the other three flag shapes:
.env-y --project my-test-projectGOOGLE_CLOUD_PROJECT=my-test-project,GOOGLE_CLOUD_LOCATION=us-central1,GOOGLE_GENAI_USE_VERTEXAI=1-y --api_key test-key --project p --region rGOOGLE_GENAI_API_KEY=test-key,GOOGLE_CLOUD_PROJECT=p,GOOGLE_CLOUD_LOCATION=r,GOOGLE_GENAI_USE_VERTEXAI=1-y --api_key test-keyGOOGLE_GENAI_API_KEY=test-key,GOOGLE_GENAI_USE_VERTEXAI=0-y --region us-west1GOOGLE_CLOUD_LOCATION=us-west1Loading the first
.envand constructingnew Gemini({model: 'gemini-2.5-flash'})from the builtcore/distreportsapiBackend = VERTEX_AI.For the interactive path, run
create demowithout-y, choose Vertex AI, and check three things: the region prompt is pre-filled withus-central1, an empty project re-asks, andCtrl+Cexits without writing files.Checklist
[x] I have read the CONTRIBUTING.md document.
[x] I have performed a self-review of my own code.
[x] I have commented my code, particularly in hard-to-understand areas.
[x] I have added tests that prove my fix is effective or that my feature works.
[x] New and existing unit tests pass locally with my changes.