Skip to content

feat: replace azure-validate Aspire ACA env-var setup with a script - #2855

Merged
Tom Meschter (tmeschter) merged 8 commits into
microsoft:mainfrom
tmeschter:tmeschter-issue-2504-script-fix
Jul 17, 2026
Merged

feat: replace azure-validate Aspire ACA env-var setup with a script#2855
Tom Meschter (tmeschter) merged 8 commits into
microsoft:mainfrom
tmeschter:tmeschter-issue-2504-script-fix

Conversation

@tmeschter

Copy link
Copy Markdown
Member

Description

The azure-validate Aspire recipe (plugin/skills/azure-validate/references/recipes/azd/aspire.md) hand-wrote a deterministic get-and-set sequence — duplicated across bash and PowerShell — to populate the Container Apps environment variables that Aspire "limited mode" leaves unset after azd provision (needed before azd deploy). The bash path parsed azd env get-values with grep | cut | tr and the PowerShell path duplicated the logic with Select-String/.Split(), which is fragile and drifts.

This PR replaces that inline sequence with a pair of cross-platform helper scripts:

  • set-aspire-aca-env.sh and set-aspire-aca-env.ps1 (behavior parity) under plugin/skills/azure-validate/references/recipes/azd/scripts/.
  • They load azd env get-values safely (no eval), derive the resource group, and set AZURE_CONTAINER_REGISTRY_ENDPOINT, AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID, and MANAGED_IDENTITY_CLIENT_ID only if missing, printing a compact summary (or "already present"). They fail with a clear message if the resource group or a resource can't be resolved.
  • The PowerShell script prints errors and exits with a non-zero code (no throw) and uses a <# ... #> comment-based help header.
  • aspire.md now links to both scripts with sample invocations and lists the env vars they set, instead of embedding the shell logic.

Relevant tests / evals

  • tests/azure-deploy/integration.test.ts (brownfield-dotnet Aspire deploy tests) are the tests that actually exercise the script: they run the full azd provision → azd deploy flow for Aspire Container Apps, passing through the post-provision env-var window. deploys aspire orleans-voting explicitly soft-asserts the three env vars via softCheckContainerDeployEnvVars.
  • tests/azure-deploy/utils.ts — updated softCheckContainerDeployEnvVars so that invoking set-aspire-aca-env.{sh,ps1} satisfies the check. Previously it scanned the agent's shell commands for the literal env-var names; now that those azd env set calls live inside the script, the names no longer appear on the command line, so the check now also accepts the script invocation.
  • azure-validate unit/trigger tests pass (SKIP_INTEGRATION_TESTS=true npm test -- --testPathPatterns=azure-validate).
  • No azure-validate eval currently drives the post-provision step end-to-end (all evals/azure-validate stimuli earlyTerminate at/before azd provision); coverage comes from the azure-deploy Aspire integration tests above.

Validation run locally: bash/PowerShell parser checks, npm run build, scripts frontmatter + references validators (references passes, no orphaned/escaped links), token check (aspire.md within budget), and tests typecheck + ESLint.

Related Issues

Fixes #2504

Tom Meschter (tmeschter) and others added 6 commits July 15, 2026 14:54
Replace the inline bash + PowerShell get-and-set sequence in the azure-validate
Aspire recipe with set-aspire-aca-env.{sh,ps1}. The scripts load azd env values
safely (no eval), derive the resource group, and set the three Container Apps env
vars only if missing, printing a compact summary. aspire.md now links to the
scripts with sample invocations and a short description.

Fixes microsoft#2504

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7b3989d9-1cae-4615-8f24-8d005f8c0e46
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 7b3989d9-1cae-4615-8f24-8d005f8c0e46
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 7b3989d9-1cae-4615-8f24-8d005f8c0e46
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 7b3989d9-1cae-4615-8f24-8d005f8c0e46
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 7b3989d9-1cae-4615-8f24-8d005f8c0e46
The azure-validate Aspire recipe now runs set-aspire-aca-env.{sh,ps1} instead of inline 'azd env set' commands, so the env-var names no longer appear on the command line. Treat invoking the script as satisfying softCheckContainerDeployEnvVars.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 7b3989d9-1cae-4615-8f24-8d005f8c0e46

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

This PR refactors the azure-validate Aspire/Container Apps post-provisioning “env-var fill” steps by moving the previously inline bash/PowerShell logic into dedicated helper scripts, updating documentation to invoke those scripts, and adjusting azure-deploy integration-test heuristics to recognize script-based setup.

Changes:

  • Add set-aspire-aca-env.sh and set-aspire-aca-env.ps1 helper scripts to set required ACA-related env vars only when missing.
  • Update the Aspire AZD recipe docs to link to and invoke the helper scripts instead of embedding command sequences.
  • Update softCheckContainerDeployEnvVars to treat invoking the helper script as satisfying env-var expectations.
Show a summary per file
File Description
tests/azure-deploy/utils.ts Updates the soft-check logic to accept the new helper-script invocation in place of literal azd env set ... commands.
plugin/skills/azure-validate/references/recipes/azd/scripts/set-aspire-aca-env.sh Introduces a bash helper script to resolve RG/resources and set missing Aspire/ACA env vars.
plugin/skills/azure-validate/references/recipes/azd/scripts/set-aspire-aca-env.ps1 Introduces a PowerShell helper script with the same intent for Windows/PowerShell scenarios.
plugin/skills/azure-validate/references/recipes/azd/aspire.md Updates documentation to point to the new scripts and provide example invocations.

Review details

  • Files reviewed: 4/4 changed files
  • Comments generated: 7
  • Review effort level: Low

Comment thread tests/azure-deploy/utils.ts Outdated
Comment thread plugin/skills/azure-validate/references/recipes/azd/scripts/set-aspire-aca-env.sh Outdated
Comment thread plugin/skills/azure-validate/references/recipes/azd/scripts/set-aspire-aca-env.sh Outdated
Tom Meschter (tmeschter) and others added 2 commits July 16, 2026 11:21
Bash (set-aspire-aca-env.sh):
- Remove `declare -A` (Bash 4+ only) so it runs on the widely-available Bash 3.2
  (e.g. macOS); parse azd values with a small POSIX-friendly get_env_value helper.
- Capture `azd env get-values` via command substitution so `set -e` reliably aborts
  when the azd call fails (instead of process substitution).
- Drop `eval`; pass each resolver command as arguments and run it via "$@".
- Use `#!/usr/bin/env bash`.

PowerShell (set-aspire-aca-env.ps1):
- Remove `$ErrorActionPreference = 'Stop'` and instead check `$LASTEXITCODE` after
  `azd env get-values`, since PowerShell doesn't treat native-command failures as
  terminating errors.

Tests (azure-deploy/utils.ts):
- Tighten ASPIRE_ACA_ENV_SCRIPT_PATTERN to match only an actual script invocation at
  the start of a command (optionally via bash/sh/pwsh/powershell), so references like
  `cat`/`chmod` no longer satisfy softCheckContainerDeployEnvVars.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7b3989d9-1cae-4615-8f24-8d005f8c0e46
Surface error messages on the error stream (still exiting non-zero) so failures are captured by CI/log collectors, per PR review.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 7b3989d9-1cae-4615-8f24-8d005f8c0e46
@tmeschter
Tom Meschter (tmeschter) merged commit 81192b4 into microsoft:main Jul 17, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace azure-validate skill Aspire post-provision Container Apps env-var setup with a script

3 participants