Conversation
…ry sort order Co-authored-by: hemarina <104857065+hemarina@users.noreply.github.com>
Co-authored-by: hemarina <104857065+hemarina@users.noreply.github.com>
Co-authored-by: hemarina <104857065+hemarina@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR attempts to fix a bug where extension commands could pick the wrong version due to incorrect assumptions about version ordering in the registry. The PR introduces a LatestVersion helper function and replaces raw index access (Versions[len-1]) at multiple call sites. However, the core fix is fundamentally flawed due to an unsafe optimization that assumes versions are consistently sorted.
Changes:
- Added
LatestVersion()helper function with an optimization that compares only first and last elements - Updated
FilterCompatibleVersions,GetExtensionLatestVersion, and four call sites inextension.goto use the new helper - Added tests for ascending and descending order scenarios
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| cli/azd/pkg/extensions/version_compatibility.go | Added LatestVersion() helper with unsafe optimization and updated FilterCompatibleVersions() to use it |
| cli/azd/pkg/extensions/version_compatibility_test.go | Added tests for LatestVersion() and descending-order scenarios in FilterCompatibleVersions() |
| cli/azd/pkg/extensions/registry_cache.go | Updated GetExtensionLatestVersion() to use new LatestVersion() helper |
| cli/azd/pkg/extensions/registry_cache_test.go | Added test for descending order scenario |
| cli/azd/cmd/extension.go | Replaced four instances of Versions[len-1] index access with LatestVersion() calls |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…o Install Co-authored-by: hemarina <104857065+hemarina@users.noreply.github.com>
Co-authored-by: hemarina <104857065+hemarina@users.noreply.github.com>
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
Co-authored-by: hemarina <104857065+hemarina@users.noreply.github.com>
…ll and GetExtensionLatestVersion Co-authored-by: hemarina <104857065+hemarina@users.noreply.github.com>
…VersionForConstraint in version_compatibility.go Co-authored-by: hemarina <104857065+hemarina@users.noreply.github.com>
…iadic constraint param; remove LatestVersionForConstraint Co-authored-by: hemarina <104857065+hemarina@users.noreply.github.com>
…ogic in manager.go Co-authored-by: hemarina <104857065+hemarina@users.noreply.github.com>
JeffreyCA
left a comment
There was a problem hiding this comment.
Good catch, thanks for fixing this
The registry version list has no guaranteed sort order, but call sites used
Versions[len(Versions)-1]assuming ascending order — causingazd extension upgrade,show, andinstallto potentially operate against the wrong version.Changes
LatestVersion(pkg/extensions/version_compatibility.go): iterates all elements using semver comparison to find the true maximum version, correct for any ordering (ascending, descending, or unsorted). Returnsnilif the slice is empty. Logs a warning when a version string fails to parse.FilterCompatibleVersions:LatestOverallandLatestCompatiblenow computed viaLatestVersioninstead of raw index access.GetExtensionLatestVersion(registry_cache.go): usesLatestVersionto find the highest semver version in the cache.cmd/extension.go: allVersions[len(Versions)-1]call sites replaced withextensions.LatestVersion(...).Manager.Install(manager.go): usesLatestVersionfor the"latest"preference case; the version-constraint path retains its existing inline sort+constraint-check loop.Example
Tests
Added
Test_LatestVersioncovering ascending, descending, and unsorted inputs; new descending-order sub-tests inTest_FilterCompatibleVersions; andTest_RegistryCacheManager_GetExtensionLatestVersion_DescendingOrderto directly validate the bug scenario.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.