You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix environment variable leak and flag propagation for extensions (#7314)
* Test aks
* Fix environment variable leak and flag propagation for extensions
Extension commands use DisableFlagParsing, so cobra never parses global
flags like -e/--environment, --debug, or --cwd. This caused two problems:
1. The DI-resolved environment always loaded the default instead of the
one specified with -e, leaking wrong env vars into extension processes
and never setting AZD_ENVIRONMENT (#7034).
2. --debug and --cwd were also not propagated to extensions because
extensions.go read them from cmd.Flags() which returns defaults.
Fix by:
- Adding -e/--environment to ParseGlobalFlags() with lenient validation:
valid env names are accepted, non-env values (like URLs that extensions
pass via -e) are silently skipped so extensions still work.
- Adding EnvironmentName to GlobalCommandOptions so the pre-parsed value
is available to the DI container and extension runner.
- Updating container.go EnvFlag resolver to fall back to globalOptions
when cmd.Flags() returns empty (extension commands).
- Updating extensions.go to use globalOptions for all InvokeOptions
fields (debug, cwd, environment, no-prompt) instead of cmd.Flags().
Closes#7034
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: add AZD_DISABLE_AGENT_DETECT for functional tests
Agent detection (agentdetect package) walks the parent process tree and
auto-enables --no-prompt when it finds an AI coding agent. In CI and
local dev under Copilot CLI, this causes functional tests to fail
because piped stdin is ignored when no-prompt is active.
Changes:
- detect.go: Early return from detectAgent() when AZD_DISABLE_AGENT_DETECT
is set, suppressing both env var and parent process detection
- cli.go: Set AZD_DISABLE_AGENT_DETECT=1 on all child azd processes in
RunCommandWithStdIn(), with nil-Env safety (nil means inherit-all in Go)
- detect_test.go: Test that AZD_DISABLE_AGENT_DETECT suppresses detection
- env_test.go: Fix require.Fail -> require.Failf format string bug
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: remove tainted env var value from log to satisfy gosec G706
The gosec linter flags os.LookupEnv values as tainted input for log
injection (G706). Remove the env var value from the log message since
only the presence of the env var matters, not its value.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* ci: retrigger pipeline
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: exclude --environment from workflow step global args
Workflow steps that specify their own -e/--environment flag (e.g.
'azd: env set KEY VALUE -e env1') were getting the parent command's
--environment appended via extractGlobalArgs(), causing the parent's
value to override the step's explicit value.
The environment flag is now excluded from extractGlobalArgs() since
environment propagation to workflow steps is already handled by the
globalOptions DI fallback in the EnvFlag resolver.
Fixes Test_CLI_Up_EnvironmentFlags.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: add missing color import in detect_confirm_apphost.go
* Use lenient validation for -e/--environment in global flag parsing
Change ParseGlobalFlags to silently ignore invalid environment names
instead of returning an error. Valid environment names match the regex
[a-zA-Z0-9-()_.]{1,64} which can never match URLs containing ://, so
there is natural disambiguation between azd env names and extension
flags that reuse -e for other purposes (e.g., --project-endpoint).
This fixes the environment variable leak (azd env name not propagating
to workflow steps) while preserving backward compatibility with all
extensions — including third-party ones that use -e for their own flags.
PR 7313 (migrating first-party extensions off -e) is no longer a hard
prerequisite since invalid values are silently skipped, not rejected.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Update TestFigSpec snapshot to match current extension output
Remove stale --host option from ai agents init that was incorrectly
kept during rebase conflict resolution. The current azure.ai.agents
extension no longer exposes this option.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Add extension compatibility regression test for -e flag
Add TestParseGlobalFlags_ExtensionCompatibility that verifies real extension
scenarios (azure.ai.models, azure.ai.finetune) using -e for --project-endpoint
URLs are not broken by global -e/--environment flag parsing.
Covers: URL endpoints, --project-endpoint passthrough, valid env before
extension args, mixed global flags, and pflag last-value-wins behavior.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Fix line-length lint violations in extension compatibility tests
Break long args slices across multiple lines to comply with the 125-char
lll linter rule enforced by golangci-lint.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* ci: retrigger CI after flaky test failures
* fix: use EnvironmentNameFlagName constant and add debug logging
- Replace string literal 'environment' with internal.EnvironmentNameFlagName
constant in CreateGlobalFlagSet and ParseGlobalFlags to prevent drift
- Add debug-level log when an invalid environment name is silently ignored,
making the lenient skip observable when --debug is enabled
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* chore: remove accidental dev/null file
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
0 commit comments