Count every duplicate group in the dedupe summary
JA
4h ago+59052+59052+01234567890123456789012345678901234567890123456789-22926-22926-01234567890123456789012345678901234567890123456789
Closes jaysbeekay/sure#958
Fork pre-flight for upstream PR we-promise/sure#5941 (pull/5941): same branch, same commit (up/dedupe-summary-count at 2847d6b91). Upstream issue: we-promise/sure#5548. Stacked on jaysbeekay/sure#952 (base up/dedupe-merge-securities).
Problem
rake securities:deduplicate ends with "Total duplicate sets: N", where N comes from the outer duplicates local. The ticker + MIC loop reassigns that local to each group's own duplicates (duplicates = securities[1..]), since a block shares its enclosing scope's locals, so the summary prints the duplicate count of whichever group ran last. "Found N sets" is printed before the loop and is right.
Resulting behaviour
- The group body uses its own
group_duplicateslocal at the assignment and every reader: the Duplicates line, the holdings, trades, prices, lots and reference counts, andSecurity::Merger.merge_group!. The outer list keeps its uses in "Found N sets", theeachand the summary. - The summary shows the number of groups. Nothing else in the output or the merge changes.
Not fixed here
Pre-existing, left for follow-ups:
dry_run = args[:dry_run].present?treats"false"as a dry run, sosecurities:deduplicate[false]changes nothing.- The summary leaves out the first pass, duplicates without a MIC: its totals count only the ticker + MIC groups.
Validation
- Red first on
a6f8cbcfc(we-promise/sure#5618's head): three groups of 2, 2 and 5 securities in a dry run (invoke("true")) printedTotal duplicate sets: 1, the last group processed (pluckwithgrouphas no order), and the test expects/^ Total duplicate sets: 3$/. - A live run (bare
invoke) merges each group into its earliest security: its holding, trade and price re-point and only the others are deleted, and the summary reads 3 sets, 3 holdings, 3 trades, 3 prices. - Boundary check, not coverage of the fix: with no groups the summary prints
Total duplicate sets: 0, which also passes before the fix, since the loop never runs. - Mutations, each caught: the outer local reassigned again; the holdings and trades counts reading the outer list;
merge_group!given the outer list; the Duplicates line reading it. - Rubocop and Brakeman clean. Full suite on
ab631eaad(upstream main merged in): 19,799 runs, 0 failures, 8 errors, allReleaseNotesWorkflowTestneedingnode, which the test image lacks.