fix(toolboxes): skip env-sync gracefully when no azd project exists#9220
Conversation
isNoAzdEnvironment() now also matches the 'no project exists' error from the azd gRPC server, so toolbox create/delete with --project-endpoint succeeds even without an azure.yaml / azd environment. The env-sync is already documented as best-effort. Fixes #9219 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
📋 Prioritization NoteThanks for the contribution! The linked issue isn't in the current milestone yet. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). 21 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
Updates toolbox environment synchronization to gracefully skip when no azd project exists.
Changes:
- Recognizes the host’s “no project exists” gRPC error.
- Adds unit coverage for the new case.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
toolbox_env.go |
Expands missing-environment detection. |
toolbox_env_test.go |
Tests operation without an azd project. |
There was a problem hiding this comment.
Verified the error path: currentEnvironment resolves the azd context via lazyAzdContext.GetValue(), which returns azdcontext.ErrNoProject with the message "no project exists; to create a new project, run azd init". GetCurrent passes it through and gRPC surfaces it as codes.Unknown, so the widened substring match skips env-sync as intended. Message-matching stays consistent with the azure.ai.agents sibling, and the new test case uses the real error string. Tests pass locally.
Why
azd ai toolbox create --project-endpoint <url> --from-file <path>fails when run outside an azd project (noazure.yaml). The endpoint resolves fine via the--project-endpointflag and the toolbox is created on the server, but the post-create step that writes the MCP endpoint to the azd environment crashes becauseisNoAzdEnvironment()doesn't recognize the "no project exists" gRPC error.The env-sync is already documented as best-effort -- it should skip silently when there is no azd environment to write to, not fail the entire operation.
Approach
Widened
isNoAzdEnvironment()intoolbox_env.goto also match the"no project exists"message that the azd gRPC server returns whenGetCurrent()is called without anazure.yaml. This sits alongside the existing"default environment not found"check and thecodes.Unavailablecheck.Added a corresponding test case to the
TestIsNoAzdEnvironmenttable.Fixes: #9219