Skip to content

Commit 52dec95

Browse files
fix: if extensionHelpIndex is invalid, reload only extensions for refresh, not core modules also
1 parent 87e3c00 commit 52dec95

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

src/azure-cli-core/azure/cli/core/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,16 @@ def get_help_index(self):
11861186

11871187
return self._get_help_index_cached_local()
11881188

1189+
def needs_latest_extension_help_overlay_refresh(self):
1190+
"""Return True when latest-profile top-level help should refresh extension help overlay."""
1191+
if self.cloud_profile != 'latest':
1192+
return False
1193+
1194+
if self._is_extension_help_index_valid():
1195+
return False
1196+
1197+
return self._has_non_always_loaded_extensions()
1198+
11891199
def set_help_index(self, help_data):
11901200
"""Set the help index data.
11911201

src/azure-cli-core/azure/cli/core/commands/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,13 @@ def _try_show_cached_help(self, args):
745745
command_index = CommandIndex(self.cli_ctx)
746746
help_index = command_index.get_help_index()
747747

748+
if not help_index and command_index.needs_latest_extension_help_overlay_refresh():
749+
logger.debug("Top-level cached help is unavailable on latest profile. "
750+
"Refreshing extension help overlay without full core module load.")
751+
# Unknown top-level command forces extension-only load path on latest profile.
752+
self.commands_loader.load_command_table(['__refresh_extension_help_overlay__'])
753+
help_index = command_index.get_help_index()
754+
748755
if help_index:
749756
# Display cached help using the help system
750757
self.help.show_cached_help(help_index, args)

src/azure-cli-core/azure/cli/core/tests/test_help.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,32 @@ def test_show_cached_help_output(self):
743743
finally:
744744
sys.stdout = sys.__stdout__
745745

746+
def test_try_show_cached_help_refreshes_latest_extension_overlay(self):
747+
"""Test top-level cached help retries after refreshing latest extension help overlay."""
748+
from azure.cli.core import CommandIndex
749+
750+
invoker = self.test_cli.invocation_cls(
751+
cli_ctx=self.test_cli,
752+
commands_loader_cls=self.test_cli.commands_loader_cls,
753+
parser_cls=self.test_cli.parser_cls,
754+
help_cls=self.test_cli.help_cls)
755+
self.test_cli.invocation = invoker
756+
757+
refreshed_help_data = {
758+
'groups': {'vm': {'summary': 'Manage VMs.', 'tags': ''}},
759+
'commands': {'version': {'summary': 'Show version.', 'tags': ''}}
760+
}
761+
762+
with mock.patch.object(CommandIndex, 'get_help_index', side_effect=[None, refreshed_help_data]), \
763+
mock.patch.object(CommandIndex, 'needs_latest_extension_help_overlay_refresh', return_value=True), \
764+
mock.patch.object(invoker.commands_loader, 'load_command_table') as mock_load_cmd_table, \
765+
mock.patch.object(invoker.help, 'show_cached_help') as mock_show_cached_help:
766+
result = invoker._try_show_cached_help(['--help', '--debug'])
767+
768+
self.assertIsNotNone(result)
769+
mock_load_cmd_table.assert_called_once_with(['__refresh_extension_help_overlay__'])
770+
mock_show_cached_help.assert_called_once_with(refreshed_help_data, ['--help', '--debug'])
771+
746772
# create a temporary file in the temp dir. Return the path of the file.
747773
def _create_new_temp_file(self, data, suffix=""):
748774
with tempfile.NamedTemporaryFile(mode='w', dir=self._tempdirName, delete=False, suffix=suffix) as f:

0 commit comments

Comments
 (0)