refactor: use core env in Foundry service targets#9079
Conversation
🔗 Linked Issue RequiredThanks for the contribution! Please link a GitHub issue to this PR by adding |
There was a problem hiding this comment.
Pull request overview
Updates Foundry extensions to use azd 1.27.1’s service-level environment forwarding.
Changes:
- Consume forwarded service environments with legacy fallback.
- Move generated agent/resource variables into service-level
env. - Update schemas, tests, dependencies, minimum versions, and changelogs.
Reviewed changes
Copilot reviewed 35 out of 39 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
cli/azd/extensions/microsoft.foundry/extension.yaml |
Requires azd 1.27.1. |
cli/azd/extensions/microsoft.foundry/CHANGELOG.md |
Records the requirement change. |
cli/azd/extensions/azure.ai.toolboxes/schemas/azure.ai.toolbox.json |
Documents service-level variables. |
cli/azd/extensions/azure.ai.toolboxes/internal/cmd/service_target.go |
Uses forwarded environment values. |
cli/azd/extensions/azure.ai.toolboxes/internal/cmd/service_target_test.go |
Tests forwarded-variable expansion. |
cli/azd/extensions/azure.ai.toolboxes/go.sum |
Updates dependency checksums. |
cli/azd/extensions/azure.ai.toolboxes/go.mod |
Uses azd SDK 1.27.1. |
cli/azd/extensions/azure.ai.toolboxes/extension.yaml |
Requires azd 1.27.1. |
cli/azd/extensions/azure.ai.toolboxes/CHANGELOG.md |
Documents the toolbox fix. |
cli/azd/extensions/azure.ai.routines/schemas/azure.ai.routine.json |
Documents routine input variables. |
cli/azd/extensions/azure.ai.routines/internal/cmd/service_target.go |
Uses forwarded environment values. |
cli/azd/extensions/azure.ai.routines/internal/cmd/service_target_test.go |
Tests routine expansion. |
cli/azd/extensions/azure.ai.routines/go.sum |
Updates dependency checksums. |
cli/azd/extensions/azure.ai.routines/go.mod |
Uses azd SDK 1.27.1. |
cli/azd/extensions/azure.ai.routines/extension.yaml |
Requires azd 1.27.1. |
cli/azd/extensions/azure.ai.routines/CHANGELOG.md |
Documents the routine fix. |
cli/azd/extensions/azure.ai.connections/schemas/azure.ai.connection.json |
Documents connection variables. |
cli/azd/extensions/azure.ai.connections/internal/cmd/service_target.go |
Uses forwarded environment values. |
cli/azd/extensions/azure.ai.connections/internal/cmd/service_target_test.go |
Tests connection expansion. |
cli/azd/extensions/azure.ai.connections/go.sum |
Updates dependency checksums. |
cli/azd/extensions/azure.ai.connections/go.mod |
Uses azd SDK 1.27.1. |
cli/azd/extensions/azure.ai.connections/extension.yaml |
Requires azd 1.27.1. |
cli/azd/extensions/azure.ai.connections/CHANGELOG.md |
Documents the connection fix. |
cli/azd/extensions/azure.ai.agents/schemas/examples/simple.azure.yaml |
Demonstrates agent service env. |
cli/azd/extensions/azure.ai.agents/schemas/examples/complex.azure.yaml |
Demonstrates resource-scoped variables. |
cli/azd/extensions/azure.ai.agents/schemas/azure.ai.agent.json |
Removes duplicate inline env schema. |
cli/azd/extensions/azure.ai.agents/internal/project/config.go |
Removes custom environment storage. |
cli/azd/extensions/azure.ai.agents/internal/project/config_test.go |
Updates config round-trip coverage. |
cli/azd/extensions/azure.ai.agents/internal/project/agent_definition.go |
Maps agent variables to core env. |
cli/azd/extensions/azure.ai.agents/internal/project/agent_definition_test.go |
Tests new and legacy mappings. |
cli/azd/extensions/azure.ai.agents/internal/cmd/resource_services.go |
Writes resource variable templates. |
cli/azd/extensions/azure.ai.agents/internal/cmd/resource_services_test.go |
Tests template collection and writes. |
cli/azd/extensions/azure.ai.agents/internal/cmd/init.go |
Writes initialized agent environments. |
cli/azd/extensions/azure.ai.agents/internal/cmd/init_test.go |
Verifies generated service env. |
cli/azd/extensions/azure.ai.agents/internal/cmd/init_from_code.go |
Writes code-init agent environments. |
cli/azd/extensions/azure.ai.agents/go.sum |
Updates dependency checksums. |
cli/azd/extensions/azure.ai.agents/go.mod |
Uses azd SDK 1.27.1. |
cli/azd/extensions/azure.ai.agents/extension.yaml |
Requires azd 1.27.1. |
cli/azd/extensions/azure.ai.agents/CHANGELOG.md |
Documents the agent migration. |
|
|
||
| sectionValues := make(map[string]any, len(environment)) | ||
| for key, value := range environment { | ||
| sectionValues[key] = value |
| environment = map[string]string{} | ||
| } | ||
| maps.Copy(environment, kv) | ||
| svc.Environment = environment |
jongio
left a comment
There was a problem hiding this comment.
One follow-up on the env migration path.
The new legacy-environment test covers the read path but not the optimize apply persist path through AddService, so it won't catch the ${VAR} to $${VAR} escaping that the existing review comment describes. Worth a persist-path test for that migration. Detail inline.
| require.Equal(t, AgentDefinitionSourceLegacyConfig, source) | ||
| require.Equal(t, map[string]string{ | ||
| "LEGACY_KEY": "${LEGACY_KEY}", | ||
| }, AgentEnvironment(got)) |
There was a problem hiding this comment.
This legacy-env test only exercises the read path (AgentDefinitionFromService then AgentEnvironment). It never runs the persist path that optimize apply uses (UpsertAgentEnvVars then Project().AddService), which is where a migrated ${LEGACY_KEY} is at risk.
When a service migrates from inline environmentVariables, it has no existing core env entry, so preserveUnchangedEnvTemplates in internal/grpcserver/project_service.go skips the key (if !has { continue }) and the mapper persists the value as an expanded literal, turning ${LEGACY_KEY} into $${LEGACY_KEY} in azure.yaml. So this test passes while the actual migration changes semantics.
Consider a test that drives the migration through AddService (or a recording project server) and asserts the persisted template stays ${LEGACY_KEY}.
|
@copilot resolve the merge conflicts in this pull request |
Co-authored-by: huimiu <107838226+huimiu@users.noreply.github.com>
Co-authored-by: huimiu <107838226+huimiu@users.noreply.github.com>
Merged |
There was a problem hiding this comment.
Re-reviewed after the merge from main and conflict resolution. My earlier note on env persist-path coverage is addressed: TestUpsertAgentEnvVars now drives UpsertAgentEnvVars and asserts the inline environmentVariables key is dropped. The service-target refactor reads the env values from ServiceConfig.Environment and falls back to the active azd environment when a service has no env, so existing definitions keep resolving. The template collector correctly skips the Foundry double-brace form and the escaped dollar-dollar literal form.
| func (p *toolboxServiceTarget) environmentValues( | ||
| ctx context.Context, | ||
| serviceConfig *azdext.ServiceConfig, | ||
| ) (map[string]string, error) { |
| maps.Copy(legacyEnvironment, environment) | ||
| environmentVariables = environmentVariablesFromMap(legacyEnvironment) |
| var envReferencePattern = regexp.MustCompile( | ||
| `\$\{([A-Za-z_][A-Za-z0-9_]*)\}`, | ||
| ) |
| ### Bugs Fixed | ||
|
|
||
| - [[#9079]](https://github.com/Azure/azure-dev/pull/9079) Store hosted-agent runtime variables in the standard service-level `env` object and read the expanded values forwarded by azd core. `azd ai agent init` no longer writes the unsupported inline `environmentVariables` shape; legacy inline and on-disk agent definitions remain readable. |
| ## 1.0.0-beta.3 (Unreleased) | ||
|
|
||
| ### Bugs Fixed | ||
|
|
||
| - [[#9079]](https://github.com/Azure/azure-dev/pull/9079) Resolve routine input `${VAR}` references from the service-level `env` object forwarded by azd core. Existing services without `env` keep falling back to the active azd environment. |
| ## 1.0.0-beta.3 (Unreleased) | ||
|
|
||
| ### Bugs Fixed | ||
|
|
||
| - [[#9079]](https://github.com/Azure/azure-dev/pull/9079) Resolve toolbox `${VAR}` references from the service-level `env` object forwarded by azd core. Existing services without `env` keep falling back to the active azd environment. |
| ## 1.0.0-beta.3 (Unreleased) | ||
|
|
||
| ### Bugs Fixed | ||
|
|
||
| - [[#9079]](https://github.com/Azure/azure-dev/pull/9079) Resolve `${VAR}` references from the service-level `env` object forwarded by azd core. Existing services without `env` keep falling back to the active azd environment. |
| ## 1.0.0-beta.2 (Unreleased) | ||
|
|
||
| ### Other Changes | ||
|
|
||
| - [[#9079]](https://github.com/Azure/azure-dev/pull/9079) Require azd 1.27.1 so bundled Foundry service targets receive service-level environment values. |
jongio
left a comment
There was a problem hiding this comment.
Re-reviewed the follow-up commit that preserves legacy inline env vars during migration. toContainerAgent now seeds the map from the inline definition and overlays the service environment, so legacy-only keys survive and service values win on conflicts. TestAgentDefinitionFromService_LegacyEnvironment covers the merge (legacy-only key preserved, new service key added, shared key resolves to the service value). Refreshing my approval since the earlier one predated this push.
Summary
ServiceConfig.environmentin the Foundry agent, connection, routine, and toolbox targets, with a fallback for older service definitions.envobject while preserving raw${VAR}templates.Follow-up to #8936.
Testing
go build ./... && go test ./...in all four changed extension modules.golangci-lint run ./...in all four changed extension modules.