Fix non-deterministic section ordering in exported context files#8
Draft
Fix non-deterministic section ordering in exported context files#8
Conversation
aggregateMatchingTables() iterates ExecutionContext.DATA_TABLES which is a ConcurrentHashMap with non-deterministic iteration order. The results feed into a LinkedHashMap that preserves whatever arbitrary order the ConcurrentHashMap gave, causing context markdown sections and CSV file ordering to vary between runs on the same codebase. Collect into temporary maps first, then insert into the output maps in the order specified by the dataTables configuration list.
The test feeds a LinkedHashMap with entries in reverse order (TestMapping first, CodingConventions second) compared to the dataTables config (CodingConventions first, TestMapping second). Without the fix, the output follows the input iteration order. With the fix, the output follows the configured dataTables order.
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.
Problem
Prethink output is non-deterministic between CLI runs.
ExportContext.aggregateMatchingTables()iteratesExecutionContext.DATA_TABLESwhich is aConcurrentHashMap<DataTable<?>, List<?>>. The iteration order of that map determines which data tables appear first intablesByFqn(aLinkedHashMap), which determines the section order in the generated markdown and CSV file ordering.Non-determinism chain:
ExecutionContext.DATA_TABLESis aConcurrentHashMap(seeDataTable.insertRow())aggregateMatchingTables()iterates it — non-deterministic orderLinkedHashMap tablesByFqn— preserves insertion order, but insertion order varies per rungenerateMarkdown()iteratestablesByFqn— sections appear in whatever order theConcurrentHashMapgave themSolution
Collect into temporary
HashMaps first, then insert into the outputLinkedHashMaps in the order specified by thedataTablesconfiguration list. This ensures the output order matches the recipe configuration regardless ofConcurrentHashMapiteration order.