Skip to content

Force JSON output when checking Azure CLI version - #649

Open
Joel Town Road (hippi345) wants to merge 1 commit into
Azure:masterfrom
hippi345:fix/605-force-json-output
Open

Joel Town Road (hippi345) wants to merge 1 commit into
Azure:masterfrom
hippi345:fix/605-force-json-output

Conversation

@hippi345

Copy link
Copy Markdown

Problem

Fixes #605.

When AZURE_CORE_OUTPUT=none is set (Azure CLI's recommended way to keep secrets out of logs), az version prints nothing. AzureCliLogin.login() still parses that stdout as JSON to decide pre-2.69 vs 2.69+ managed-identity flags (--username vs --client-id). Empty output made JSON.parse fail and produced Failed to parse Azure CLI version.

There is no CONTRIBUTING in this repo requiring rebuilt lib/ / dist/ bundles, so those compiled artifacts are not included.

Fix

Pass -o json on the az version invocation so the captured output is JSON regardless of AZURE_CORE_OUTPUT.

Testing

New unit test in __tests__/AzureCliLogin.test.ts mocks the az executor with AZURE_CORE_OUTPUT=none: stdout is empty unless -o json / --output json is present. It asserts those args and that azure-cli still parses.

Before (unmodified upstream master):

FAIL __tests__/AzureCliLogin.test.ts
  AzureCliLogin az version output
    ✕ az version is invoked with JSON output so AZURE_CORE_OUTPUT=none still parses (4 ms)

  ● AzureCliLogin az version output › az version is invoked with JSON output so AZURE_CORE_OUTPUT=none still parses

    expect(received).toBe(expected) // Object.is equality

    Expected: true
    Received: false

      71 |         );
      72 |         expect(versionCall).toBeDefined();
    > 73 |         expect(argsForceJsonOutput(versionCall[1])).toBe(true);
         |                                                     ^
      74 |         expect(cliLogin.azVersion).toBe('2.70.0');
      75 |         expect(core.warning).not.toHaveBeenCalledWith('Failed to parse Azure CLI version.');
      76 |     });

      at __tests__/AzureCliLogin.test.ts:73:53
      at fulfilled (__tests__/AzureCliLogin.test.ts:28:58)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        1.103 s
Ran all test suites matching /__tests__\/AzureCliLogin.test.ts/i.

After:

> test
> jest

PASS __tests__/PowerShell/AzPSScriptBuilder.test.ts
PASS __tests__/LoginConfig.test.ts
PASS __tests__/AzureCliLogin.test.ts
  AzureCliLogin az version output
    ✓ az version is invoked with JSON output so AZURE_CORE_OUTPUT=none still parses (1 ms)
PASS __tests__/PowerShell/AzPSLogin.test.ts
  Testing login
    ✓ ServicePrincipal login should pass (1 ms)
  Testing set module path
    ✓ setDefaultPSModulePath should work
  Testing runPSScript
    ✓ Get PowerShell Version (455 ms)
    ✓ Get PowerShell Version with Wrong Name (335 ms)

Test Suites: 4 passed, 4 total
Tests:       52 passed, 52 total
Snapshots:   0 total
Time:        2.517 s
Ran all test suites.

This change was prepared with AI assistance. I remain responsible for the contribution and have reviewed it.

az version is parsed as JSON for the pre-2.69 managed identity flag
choice. AZURE_CORE_OUTPUT=none emptied that stdout, so parsing failed.
Pass -o json so the check is independent of the user's default output.
Copilot AI balanced review requested due to automatic review settings October 17, 2026 01:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused fix and regression test address the reported failure with no identified blocking issues.

No open issues 🎉

What changed in this PR

Fixes #605 by ensuring Azure CLI version detection receives JSON even when AZURE_CORE_OUTPUT=none.

Changes:

  • Adds -o json to the az version invocation.
  • Adds a regression test verifying explicit JSON output and successful version parsing.
File Description
src/​Cli/​AzureCliLogin.ts Forces JSON output for version detection.
tests/​AzureCliLogin.test.ts Tests version parsing when default output is disabled.

Review effort: Balanced

@hippi345
Joel Town Road (hippi345) marked this pull request as ready for review October 17, 2026 01:38

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Version warning with output set to none

2 participants