Skip to content

[Core] Fix #34150: az: Support tempfile-backed Git Bash completion - #34248

Open
Aditya Pujara (a0x1ab) wants to merge 1 commit into
Azure:devfrom
a0x1ab:agent-assist/azure-azure-cli-issue-34150-6d5179713b91
Open

Aditya Pujara (a0x1ab) wants to merge 1 commit into
Azure:devfrom
a0x1ab:agent-assist/azure-azure-cli-issue-34150-6d5179713b91

Conversation

@a0x1ab

@a0x1ab Aditya Pujara (a0x1ab) commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

🤖 PR Validation — ⚠️ Review suggested

Breaking Changes Tests Suppressions
️✔️ None ️✔️ 130/130 ⚠️ 13 added

This PR adds warning or check suppressions. Fix the underlying warning where possible and justify each remaining suppression in a code comment or the PR description.

File Line Kind Code
src/azure-cli-core/azure/cli/core/tests/test_argcomplete_shell.py 19 skipped test self.skipTest('Bash is not installed')
src/azure-cli-core/azure/cli/core/tests/test_argcomplete_shell.py 25 skipped test self.skipTest('Windows completion tests require Git Bash')
src/azure-cli-core/azure/cli/core/tests/test_argcomplete_shell.py 31 skipped test self.skipTest('az.completion is not available in the test installation or checkout')
src/azure-cli-core/azure/cli/core/tests/test_argcomplete_shell.py 208 skipped test self.skipTest('Azure CLI is not installed')
src/azure-cli-core/azure/cli/core/tests/test_argcomplete_shell.py 231 skipped test self.skipTest('Azure CLI is not installed')
src/azure-cli-core/azure/cli/core/tests/test_argcomplete_shell.py 274 skipped test self.skipTest('Azure CLI is not installed')
src/azure-cli-core/azure/cli/core/tests/test_argcomplete_shell.py 287 skipped test self.skipTest('Azure CLI is not installed')
src/azure-cli-core/azure/cli/core/tests/test_argcomplete_shell_resource_unit.py 18 skipped test self.skipTest('Bash is not installed')
src/azure-cli/azure/cli/command_modules/util/tests/latest/test_completion.py 20 skipped test self.skipTest('Bash is not installed')
src/azure-cli/azure/cli/command_modules/util/tests/latest/test_completion.py 22 skipped test self.skipTest('Azure CLI is not installed')
src/azure-cli/azure/cli/command_modules/util/tests/latest/test_completion.py 33 skipped test self.skipTest('az.completion is not available in the test installation or checkout')
src/azure-cli/azure/cli/command_modules/util/tests/test_completion_resource_unit.py 18 skipped test self.skipTest('Bash is not installed')
src/azure-cli/azure/cli/command_modules/util/tests/test_completion_resource_unit.py 20 skipped test self.skipTest('Azure CLI is not installed')

Related command

az ...

Description

Fixes #34150.

az: Support tempfile-backed Git Bash completion.

Low confidence, do not merge yet: the sandbox could not verify: On Windows 11 in Git Bash (MINGW64), with Azure CLI installed via the Windows MSI, sourcing the supplied az.completion script and exporting ARGCOMPLETE_USE_TEMPFILES=1 makes Tab …; Completion works in that environment without replacing the completion function in .bashrc.. It stays a draft with the do-not-merge label until a maintainer verifies the root cause and the fix.

Root cause: az.completion: _az_python_argcomplete originally always used descriptors 8/9 and never passed _ARGCOMPLETE_STDOUT_FILENAME, although AzCompletionFinder inherits argcomplete's file-output support. Native MSI CLI processes under Git Bash cannot reliably receive those descriptors. The existing PR correctly adds opt-in tempfile transport, but its new mktemp, cat and rm calls leave stderr connected to the terminal. Genuine helper failures therefore print diagnostics during completion. The prior silent mktemp test stub did not expose that error-output defect.

Fix: Preserved the existing opt-in tempfile fix, default descriptor transport and upstream completion registration. Added 2>/dev/null only to mktemp, cat and rm, retaining their error statuses, cleanup attempts and candidate clearing. Added a real helper creation-failure/recovery LiveScenarioTest first, replaced the silent unit creation stub with a missing TMPDIR, and added actual read/removal failure cases. Unlike earlier attempts, this change addresses the concrete helper diagnostic leak rather than claiming additional Linux tests prove Windows success.

Origin: commit: 1271aa0; pull_request: #1808; date: 2017-01-23; intent: PR #1808, Packaged release 0.1.7 for Debian & Docker, added packaged_releases/az.completion to the packaged release archive. Its added-file patch contains the descriptor-only wrapper and no tempfile transport. The fix preserves that completion and packaging intent.; trace: Verified through public GitHub commit history and …

Why now: Verified history shows the missing tempfile transport predates the current issue; no recent dependency or service regression is established. The reported Windows MSI/Git Bash descriptor boundary makes that longstanding gap visible, and default/bashdefault fallback added by PR #11817 explains why missing CLI candidates appear as filesystem suggestions. The refreshed review …

Blast radius: Only the handwritten shared Bash wrapper changes; no core Python parser or command implementation changes. All az completions opting into ARGCOMPLETE_USE_TEMPFILES=1 suppress helper stderr while retaining failure status and empty candidates; default descriptor users are unchanged. Real CLI/Readline scenarios cover account, vm, network and storage top-level suggestions, account set/show, --output, …

Risks and limitations (from the job report):

  • R1/C1, R1/C2, R2/C2, I1/C1 and I1/C2 still require trusted post-change Windows 11 MINGW64/MSI evidence. Linux …

Testing Guide

  • Trusted validation passed (1 command).

History Notes

Generated from the pull request title.


This checklist is used to make sure that common guidelines for a pull request are followed.

@x-engineering-agent x-engineering-agent Bot added Request X Engineering Agent Ask the agent to triage this issue or review this PR X Engineering Agent Generated Agent opened this PR do-not-merge labels Oct 20, 2026
@x-engineering-agent

x-engineering-agent Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

X Engineering Agent Report

Review — Comments

Aditya Pujara (@a0x1ab)

Independent review

Addressed in this revision: Packaged shell tests now locate az.completion or explicitly skip when unavailable (test_argcomplete_shell.py:26–31; latest/test_completion.py:28–33). Both resource-test suites assert discovery and missing-resource behavior, addressing the packaging feedback.

No confirmed semantic defects found at 52ebc9e9d197. az.completion:8–46 implements opt-in tempfile transport, cleanup and failure propagation while retaining descriptor transport. Assertions cover multiple/empty candidates, environment mappings, spacing, helper failures and recovery; the live scenarios exercise real CLI/Readline completion and error paths.

Upstream CI: 52/52 passed, per the supplied snapshot. Agent live-test evidence is reported separately below. Windows 11 MSI/Git Bash artifact execution was not independently verified; the added MSI harness (test_msi_installation.ps1:74–105) is not execution evidence.

Test validation
  • Live test: Passed. 3 of 3 test(s) passed on 52ebc9e9d197. Workflow run
  • Regression coverage: Not applicable to the changed files.
Risk assessment — 0/100 · Low

The Low rating reflects the detected change scope with no elevated security, reliability, customer, operational, dependency, sovereign-cloud, generated-output, or cross-component signal.

  • Change scope: 6 changed files, 651 changed lines (+642 / -9), including 0 production files.
  • Affected components: No production component was identified.
  • Risk drivers: No elevated risk signal was detected.
  • Regression evidence: No production-code regression-test signal applies.
  • Confidence: Low because no production changed-line evidence was available.
  • Required review: No additional owning-squad review signal was detected.

Posted by x-engineering-agent (Reviewer)

Live test — Passed (3/3)

PASS

Selectors: util.CompletionTest (module)
PR head ref: agent-assist/azure-azure-cli-issue-34150-6d5179713b91
PR head sha: 52ebc9e9d197a44ba97aeb50f81a944094bda711
PR base ref: dev
New test files in PR: true

Changed test files run
src/azure-cli/azure/cli/command_modules/util/tests/latest/test_completion.py

New test files
src/azure-cli/azure/cli/command_modules/util/tests/latest/test_completion.py

Workflow run: https://github.com/Azure/issue-sentinel/actions/runs/40166125839

Last 80 lines of azdev output

=============
| Run Tests |
=============


test index found: /home/runner/.azdev/env_config/home/runner/work/issue-sentinel/issue-sentinel/.venv/test_index/latest.json

Test on modules: util.CompletionTest

WARNING: RUNNING TESTS LIVE
The tests are set to run against current profile "latest"
============================= test session starts ==============================
platform linux -- Python 3.12.15, pytest-9.1.1, pluggy-1.7.0 -- /home/runner/work/issue-sentinel/issue-sentinel/.venv/bin/python
cachedir: .pytest_cache
rootdir: /home/runner/work/issue-sentinel/issue-sentinel/azure-cli/src/azure-cli
configfile: pyproject.toml
plugins: platformdirs-4.13.5, forked-1.7.5, xdist-3.8.0
collecting ... collected 3 items

azure-cli/src/azure-cli/azure/cli/command_modules/util/tests/latest/test_completion.py::CompletionTest::test_completion_failure_recovery PASSED [ 33%]
azure-cli/src/azure-cli/azure/cli/command_modules/util/tests/latest/test_completion.py::CompletionTest::test_completion_readline PASSED [ 66%]
azure-cli/src/azure-cli/azure/cli/command_modules/util/tests/latest/test_completion.py::CompletionTest::test_completion_tempfile_creation_failure_recovery PASSED [100%]

- generated xml file: /home/runner/work/issue-sentinel/issue-sentinel/test-output/results.xml -
============================== 3 passed in 20.38s ==============================

Workflow run

Posted by x-engineering-agent (Tester)

@a0x1ab

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@x-engineering-agent x-engineering-agent Bot added the X Engineering Agent Reviewed Agent reviewed this PR label Oct 20, 2026
@a0x1ab Aditya Pujara (a0x1ab) added Request X Engineering Agent Ask the agent to triage this issue or review this PR and removed Request X Engineering Agent Ask the agent to triage this issue or review this PR labels Oct 21, 2026
x-engineering-agent[bot]

This comment was marked as outdated.

@x-engineering-agent x-engineering-agent Bot removed the Request X Engineering Agent Ask the agent to triage this issue or review this PR label Oct 22, 2026
@a0x1ab
Aditya Pujara (a0x1ab) marked this pull request as ready for review October 23, 2026 03:34
Copilot AI balanced review requested due to automatic review settings October 23, 2026 03:34

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.

🔵 Needs a closer look

Windows 11 MSI/Git Bash validation still requires maintainer confirmation, and the packaged-test setup issue remains unresolved.

1 open issue
What changed in this PR

Adds opt-in tempfile-backed Bash completion for Azure CLI to address Git Bash’s limitations with native Windows file descriptors.

Changes:

  • Honors ARGCOMPLETE_USE_TEMPFILES=1, with tempfile cleanup and failure handling.
  • Preserves the default descriptor transport and completion spacing behavior.
  • Adds shell-level tests for both transports, failures, and installed-CLI completion.
File Description
src/​azure-cli-core/​azure/​cli/​core/​tests/​test_argcomplete_shell.py Adds completion transport and regression tests.
az.completion Adds opt-in tempfile transport for completion results.

Review effort: Balanced

if not platform.startswith('MINGW'):
self.skipTest('Windows completion tests require Git Bash')
self.completion = Path(__file__).resolve().parents[6] / 'az.completion'
self.assertTrue(self.completion.is_file())
@a0x1ab

Copy link
Copy Markdown
Member Author

@Azure/act-observability-squad LGTM, can we get your review?

@a0x1ab
Aditya Pujara (a0x1ab) force-pushed the agent-assist/azure-azure-cli-issue-34150-6d5179713b91 branch from 2811d00 to e709fb5 Compare October 24, 2026 09:44
@x-engineering-agent x-engineering-agent Bot added the Request X Engineering Agent Ask the agent to triage this issue or review this PR label Oct 24, 2026
@a0x1ab

Copy link
Copy Markdown
Member Author

@x-engineering-agent please resolve the open P2 test resource finding. Make test_argcomplete_shell.py and the util completion scenarios find az.completion when run from the installed azure-cli-fulltest layout, either by bundling it as a test resource or by skipping explicitly when it is unavailable, while keeping them running in checkout backed CI and the MSI validation. Keep the az.completion fix itself unchanged. For context the Windows Git Bash live repro previously failed on every candidate because the runner used pip's az entry script, which detaches on Windows. That is fixed in Azure/issue-sentinel#77 and https://github.com/Azure/issue-sentinel/actions/runs/40151670773 now shows the bug fixed on this PR head while dev still reproduces it.

…tion

Root cause: The original PR's ArgcompleteShellTest.setUp in
src/azure-cli-core/azure/cli/core/tests/test_argcomplete_shell.py and
CompletionTest._complete in
src/azure-cli/azure/cli/command_modules/util/tests/latest/test_completion.py
used fixed checkout-relative parent indices and asserted az.completion
existed. scripts/ci/build.sh packages those tests into
azure-cli-fulltest without copying the repository-root shell resource.
Installed tests therefore failed before exercising completion. This
revision retains the restored candidate's layout-independent resource
search and explicit missing-resource skip, and strengthens its
regression evidence.

Change: Preserved the restored candidate's search through resolved
test-file ancestors and the current checkout directory in both
completion suites. When no regular az.completion file is found, tests
explicitly skip with 'az.completion is not available in the test
installation or checkout'. Preserved installed-resource,
adjacent-resource, and checkout-CWD regressions; added checkout-backed
test-path coverage from an unrelated working directory and
directory-not-file skip coverage to both resource unit suites. No
packaging, production completion, launcher, MSI validation, generated
code, or recording changes. …

Origin: The checkout-only lookups are present in PR 34248 head
e709fb5. They intended to source the
actual repository shell script. The resource fix keeps that intention in
checkout CI and MSI validation while explicitly handling installations
that do not ship that resource.

Why now: The human review identifies the azure-cli-fulltest packaging
layout, which scripts/ci/build.sh:82-98 and 137-147 constructs without
the root completion script. Checkout-backed runs already pass and thus
did not expose the fixed-parent resource assumptions.

Blast radius: Test-only change. No CLI command behavior or shared
runtime helper changes. The existing core completion assertions cover
account, vm, network, storage and --output; the real-CLI util scenarios
remain unchanged. No unrelated core or util runtime source is touched.

Alternatives considered:
- Bundle duplicate copies of az.completion into the fulltest artifact:
  not necessary because the reviewer explicitly permits skipping when
  unavailable, and duplicate shell resources would require additional
  packaging and synchronization changes.
- Always skip installed completion tests: rejected because available
  installed resources and checkout-backed installed tests must still
  execute.

Verified:
- Trusted validation passed (1 command).
- New or changed tests fail on the base revision and pass with the
  change:
  `src/azure-cli-core/azure/cli/core/tests/test_argcomplete_shell.py::ArgcompleteShellTest::test_bash_completion_cli_failure_recovery`,
  `src/azure-cli-core/azure/cli/core/tests/test_argcomplete_shell.py::ArgcompleteShellTest::test_bash_completion_tempfile_cleanup_failure`,
  `src/azure-cli-core/azure/cli/core/tests/test_argcomplete_shell.py::ArgcompleteShellTest::test_bash_completion_tempfile_creation_failure`.
- Unit tests: 25 executed, 0 skipped.
- Recorded scenario tests replayed offline: 4 executed.
- PSScriptAnalyzer passed.
- Pre-publication gates passed: release-artifact, generated-ownership,
  command-help, suppression, independent-review.
- Repository CI and live tests run on this PR.
@a0x1ab
Aditya Pujara (a0x1ab) force-pushed the agent-assist/azure-azure-cli-issue-34150-6d5179713b91 branch from e709fb5 to 52ebc9e Compare October 25, 2026 02:33

@x-engineering-agent x-engineering-agent Bot 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.

Aditya Pujara (@a0x1ab) Ready for human review. See the X Engineering Agent Report.

@x-engineering-agent x-engineering-agent Bot removed the Request X Engineering Agent Ask the agent to triage this issue or review this PR label Oct 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for cli completion in git bash for windows

2 participants