Skip to content

{CI} Fix parser spellchecker test by setting explicit parser prog#33314

Merged
YangAn-microsoft merged 1 commit intoAzure:devfrom
YangAn-microsoft:fix/parser-test-explicit-prog-pr
May 6, 2026
Merged

{CI} Fix parser spellchecker test by setting explicit parser prog#33314
YangAn-microsoft merged 1 commit intoAzure:devfrom
YangAn-microsoft:fix/parser-test-explicit-prog-pr

Conversation

@YangAn-microsoft
Copy link
Copy Markdown
Contributor

Summary

This updates the parser spellchecker test to construct the parser the same way production does, with an explicit prog value and the global parser parent.

Why

Python 3.14 changed argparse default prog behavior to reflect how __main__ was actually executed. In this test, the parser was being created without an explicit prog, so the effective prog differed between Python 3.13 and Python 3.14 under pytest.

That difference leaked into the dynamic extension install path and made the test fail on Python 3.14 even though production code always sets prog explicitly.

What changed

  • Updated the test to create the global parser
  • Constructed the parser with prog=cli.name
  • Passed the global parser via parents to match the real runtime setup

This is a test-only fix. No product behavior is changed.

Validation

  • Passed on Python 3.13:
    • python -m pytest src/azure-cli-core/azure/cli/core/tests/test_parser.py -k test_parser_error_spellchecker -q
  • Passed on Python 3.14:
    • python -m pytest src/azure-cli-core/azure/cli/core/tests/test_parser.py -k test_parser_error_spellchecker -q

Notes

This keeps the test focused on parser spellchecking and dynamic extension install behavior, instead of depending on interpreter-specific argparse defaults.

@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd Bot commented May 5, 2026

️✔️AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.13
️✔️acs
️✔️latest
️✔️3.12
️✔️3.13
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.13
️✔️ams
️✔️latest
️✔️3.12
️✔️3.13
️✔️apim
️✔️latest
️✔️3.12
️✔️3.13
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.13
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️aro
️✔️latest
️✔️3.12
️✔️3.13
️✔️backup
️✔️latest
️✔️3.12
️✔️3.13
️✔️batch
️✔️latest
️✔️3.12
️✔️3.13
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.13
️✔️billing
️✔️latest
️✔️3.12
️✔️3.13
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️cdn
️✔️latest
️✔️3.12
️✔️3.13
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.13
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.13
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.13
️✔️config
️✔️latest
️✔️3.12
️✔️3.13
️✔️configure
️✔️latest
️✔️3.12
️✔️3.13
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.13
️✔️container
️✔️latest
️✔️3.12
️✔️3.13
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.13
️✔️core
️✔️latest
️✔️3.12
️✔️3.13
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.13
️✔️databoxedge
️✔️latest
️✔️3.12
️✔️3.13
️✔️dls
️✔️latest
️✔️3.12
️✔️3.13
️✔️dms
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.13
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.13
️✔️find
️✔️latest
️✔️3.12
️✔️3.13
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.13
️✔️identity
️✔️latest
️✔️3.12
️✔️3.13
️✔️iot
️✔️latest
️✔️3.12
️✔️3.13
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.13
️✔️lab
️✔️latest
️✔️3.12
️✔️3.13
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️maps
️✔️latest
️✔️3.12
️✔️3.13
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.13
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.13
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.13
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.13
️✔️network
️✔️latest
️✔️3.12
️✔️3.13
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.13
️✔️postgresql
️✔️latest
️✔️3.12
️✔️3.13
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.13
️✔️profile
️✔️latest
️✔️3.12
️✔️3.13
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.13
️✔️redis
️✔️latest
️✔️3.12
️✔️3.13
️✔️relay
️✔️latest
️✔️3.12
️✔️3.13
️✔️resource
️✔️latest
️✔️3.12
️✔️3.13
️✔️role
️✔️latest
️✔️3.12
️✔️3.13
️✔️search
️✔️latest
️✔️3.12
️✔️3.13
️✔️security
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.13
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.13
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.13
️✔️sql
️✔️latest
️✔️3.12
️✔️3.13
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.13
️✔️storage
️✔️latest
️✔️3.12
️✔️3.13
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.13
️✔️telemetry
️✔️latest
️✔️3.12
️✔️3.13
️✔️util
️✔️latest
️✔️3.12
️✔️3.13
️✔️vm
️✔️latest
️✔️3.12
️✔️3.13

@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd Bot commented May 5, 2026

️✔️AzureCLI-BreakingChangeTest
️✔️Non Breaking Changes

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR.

Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented May 5, 2026

Thank you for your contribution! We will review the pull request and get back to you soon.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the Auto-Assign Auto assign by bot label May 5, 2026
@YangAn-microsoft YangAn-microsoft changed the title [Packaging] Fix parser spellchecker test by setting explicit parser prog [CI] Fix parser spellchecker test by setting explicit parser prog May 5, 2026
@YangAn-microsoft YangAn-microsoft changed the title [CI] Fix parser spellchecker test by setting explicit parser prog {CI} Fix parser spellchecker test by setting explicit parser prog May 5, 2026
@YangAn-microsoft YangAn-microsoft mentioned this pull request May 5, 2026
9 tasks
@YangAn-microsoft YangAn-microsoft marked this pull request as ready for review May 5, 2026 04:06
Copilot AI review requested due to automatic review settings May 5, 2026 04:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 updates the Azure CLI core parser spellchecker unit test to construct the command parser in a way that matches the real runtime setup, avoiding Python 3.14 argparse default prog differences under pytest that impacted dynamic extension install behavior in the test.

Changes:

  • Create and use a “global” parent parser in the test (via create_global_parser(cli_ctx=cli)).
  • Instantiate the main parser with an explicit prog=cli.name.
  • Pass the global parser through parents=[global_parser] so command parsers inherit the same global args structure as production.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


parser = cli.parser_cls(cli)
global_parser = cli.parser_cls.create_global_parser(cli_ctx=cli)
parser = cli.parser_cls(cli, prog=cli.name, parents=[global_parser])
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.

What's the error before this change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

2026-05-05T01:31:44.9051924Z         # test dynamic extension install
2026-05-05T01:31:44.9052399Z         with mock.patch.object(logging.Logger, 'error', mock_log_error), \
2026-05-05T01:31:44.9052993Z                 mock.patch.object(azure.cli.core.extension.operations, 'add_extension', mock_add_extension), \
2026-05-05T01:31:44.9053659Z                 mock.patch.object(azure.cli.core.extension.dynamic_install, '_get_extension_command_tree',
2026-05-05T01:31:44.9054193Z                                   mock_ext_cmd_tree_load), \
2026-05-05T01:31:44.9054759Z                 mock.patch.object(azure.cli.core.extension.dynamic_install, '_get_extension_use_dynamic_install_config',
2026-05-05T01:31:44.9055326Z                                   return_value='yes_without_prompt'), \
2026-05-05T01:31:44.9055825Z                 mock.patch.object(azure.cli.core.extension.dynamic_install,
2026-05-05T01:31:44.9056515Z                                   '_get_extension_run_after_dynamic_install_config', return_value=False):
2026-05-05T01:31:44.9057035Z             with self.assertRaises(SystemExit):
2026-05-05T01:31:44.9057570Z                 parser.parse_args('test new-ext create --opt enum_2'.split())
2026-05-05T01:31:44.9058144Z >           self.assertIn("Extension new-ext-name installed. Please rerun your command.", logger_msgs[5])
2026-05-05T01:31:44.9058862Z E           AssertionError: 'Extension new-ext-name installed. Please rerun your command.' not found in "'new-ext' is misspelled or not recognized by the system."
2026-05-05T01:31:44.9059213Z 
2026-05-05T01:31:44.9059685Z src/azure-cli-core/azure/cli/core/tests/test_parser.py:271: AssertionError

Under Python 3.14, argparse changed the default prog to reflect how __main__ was actually invoked. Under pytest, instead of az, self.prog became something like __main__.py or a full invocation path.

This matters because parser.py line 298 builds the args list as:

args = self.prog.split() + self._raw_arguments

_check_value_in_extensions then calls roughly_parse_command(args[1:]), which assumes args[0] is always the single token az. When self.prog was a multi-token string, self.prog.split() produced multiple elements, args[1:] skipped the wrong token, and command_str was computed incorrectly. That caused _search_in_extension_commands to miss new-ext in the mocked command tree — the dynamic install path was never triggered. The parser fell through to the spellchecker and logged:

'new-ext' is misspelled or not recognized by the system.

instead of the expected:

Extension new-ext-name installed. Please rerun your command.

The fix sets prog=cli.name explicitly (always az), matching what production always does, so self.prog.split() is reliably ['az'] regardless of how pytest launched the process.

@YangAn-microsoft YangAn-microsoft merged commit f27e6fd into Azure:dev May 6, 2026
67 checks passed
@YangAn-microsoft YangAn-microsoft deleted the fix/parser-test-explicit-prog-pr branch May 6, 2026 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants