fix: sort parameter keys before iterating to ensure deterministic output in wiki documentation#1285
Open
oWretch wants to merge 1 commit into
Open
Conversation
Build-PolicyDocumentation was iterating $parameters.Keys (unordered hashtable enumeration) in 5 output-producing locations, causing parameter entries within markdown table cells and CSV/JSONC exports to shuffle between runs even when nothing had changed. Fix: add | Sort-Object to each affected foreach loop so parameters are always emitted in alphabetical order. Files fixed: - Scripts/Helpers/Out-DocumentationForPolicySets.ps1:169 - Scripts/Helpers/Out-DocumentationForPolicyAssignments.ps1:406 - Scripts/Helpers/Convert-PolicyResourcesDetailsToFlatList-Documentation.ps1:249,478 - Scripts/Helpers/Convert-ParametersToString.ps1:11 (CSV/JSONC output, broader than issue) Fixes Azure#1284 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Collaborator
|
Will test and confirm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1284
Build-PolicyDocumentationwas iterating$parameters.Keys(unordered hashtable enumeration) in multiple output-producing locations. PowerShell does not guarantee stable key enumeration order across runs, causing parameter entries within markdown table cells and CSV/JSONC exports to shuffle between runs — even when nothing had changed — producing large, noisy wiki diffs.Changes
Added
| Sort-Objectto each affectedforeachloop so parameters are always emitted in alphabetical order.The issue identified 4 locations. On review, a 5th output-producing location was also found in
Convert-ParametersToString.ps1(used for CSV JSON blob and JSONC text exports) with the same bug:Scripts/Helpers/Out-DocumentationForPolicySets.ps1Scripts/Helpers/Out-DocumentationForPolicyAssignments.ps1Scripts/Helpers/Convert-PolicyResourcesDetailsToFlatList-Documentation.ps1Scripts/Helpers/Convert-PolicyResourcesDetailsToFlatList-Documentation.ps1Scripts/Helpers/Convert-ParametersToString.ps1Other
$parameters.Keysiterations in the codebase (Confirm-*,Build-*,Merge-*, etc.) are internal computation only — order there does not affect any output and was left unchanged.Design note:
Sort-Objectvs ordered hashtableAn
[ordered]hashtable was considered as an alternative. It was rejected for the following reasons:Ordered hashtables preserve insertion order, not alphabetical order. Parameters are accumulated by merging from multiple policies/policy sets across several files. To achieve alphabetical order with
[ordered], you would also need to sort the source keys at every merge/insertion point — effectively the same work, just spread across more files.The source data is inherently unordered. Parameters originate from Azure API JSON responses with no guaranteed key order. There is no natural "meaningful" order to preserve — alphabetical is the right semantic choice, and
Sort-Objectmakes that intent explicit at the point of output.Sort-Objectat the output point is: