Skip to content

fix: resolve toolbox $ref config before deploy#9148

Open
huimiu wants to merge 2 commits into
mainfrom
hui/toolbox-ref-config
Open

fix: resolve toolbox $ref config before deploy#9148
huimiu wants to merge 2 commits into
mainfrom
hui/toolbox-ref-config

Conversation

@huimiu

@huimiu huimiu commented Jul 15, 2026

Copy link
Copy Markdown
Member

Why this PR is needed

Toolbox service configuration can be written inline in azure.yaml or loaded from a local file with $ref. The deploy path previously parsed the $ref object as the toolbox configuration instead of loading the referenced file. As a result, deployments using file-based toolbox configuration could omit the description and tools defined in that file, or fail to deploy with the expected configuration.

This fix resolves local $ref files relative to the project root before parsing the toolbox configuration. Inline configuration and the legacy config: shape continue to use the existing behavior. This keeps file-based and inline configuration consistent at deploy time.

Changes

  • Resolve toolbox $ref file includes with foundry.ResolveFileRefs when a reference is present anywhere in the service configuration.
  • Preserve the existing inline and legacy config: parsing behavior when no $ref is present.
  • Add a regression test covering a toolbox configuration loaded from a local file.

Testing

  • go build ./... in cli/azd/extensions/azure.ai.toolboxes
  • go test ./internal/cmd/... in cli/azd/extensions/azure.ai.toolboxes

Copilot AI review requested due to automatic review settings July 15, 2026 03:13
@github-actions

Copy link
Copy Markdown

🔗 Linked Issue Required

Thanks for the contribution! Please link a GitHub issue to this PR by adding Fixes #123 to the description or using the sidebar.
No issue yet? Feel free to create one!

@azure-pipelines

Copy link
Copy Markdown
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Resolves local $ref configurations for Azure AI toolbox services before deployment.

Changes:

  • Adds project-root-aware $ref resolution.
  • Preserves inline and legacy config parsing.
  • Adds referenced-file test coverage.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
README.md Removes trailing whitespace.
service_target.go Resolves toolbox configuration references.
service_target_test.go Tests referenced toolbox configuration parsing.

b, err := json.Marshal(props.AsMap())
values := props.AsMap()
if projectRoot != "" {
resolved, err := foundry.ResolveFileRefs(values, projectRoot)
Comment on lines +360 to +364
return nil, fmt.Errorf(
"resolving toolbox service %q config: %w",
svc.GetName(),
err,
)
Copilot AI review requested due to automatic review settings July 15, 2026 03:28

@jongio jongio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things in the new $ref resolution are worth sorting before this merges.

  1. parseToolboxServiceConfigAtRoot wraps the ResolveFileRefs error with fmt.Errorf("...: %w") (service_target.go:360). ResolveFileRefs already returns a structured *azdext.LocalError (foundry/errors.go:15-21), and this extension's own AGENTS.md:93-98 says not to wrap an already-structured error: during gRPC serialization azd keeps the inner error's message/code/category and drops the outer text, so the resolving toolbox service %q config context is lost anyway. Return err directly, or fold the toolbox name into a fresh structured error.

  2. containsToolboxFileRef plus ResolveFileRefs resolve every $ref anywhere in the config, not just the service-entry include (service_target.go:388, foundry/includes.go:84-113). The schema allows tools with type: openapi and additionalProperties: true (schemas/azure.ai.toolbox.json:17-27), and real OpenAPI documents carry JSON-pointer refs like #/components/schemas/Foo. refTargetPath doesn't treat those as remote, so they get joined onto projectRoot and loadRefFile fails with cannot read $ref file. Before this change those inline specs were passed through verbatim, so this is a deploy regression for openapi tools. Can resolution be scoped to the include points you actually support (service entry, deployment array items) instead of walking into tool payloads?

Both reproduce against the current diff. Confirmed the extension builds and the parse tests pass locally, so this is behavior and convention, not a compile break.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@huimiu huimiu added the area/extensions Extensions (general) label Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/extensions Extensions (general) ext-toolboxes azure.ai.toolboxes extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants