fix(sync): skip pending auto-claim when multiple same-amount candidat…
Closed
DA
3mo ago+97+97+01234567890123456789-25-25-01234567890123456789
Summary
- Bug: When two pending transactions with the same amount existed in the reconciliation window, the auto-claim logic would silently overwrite whichever one it matched first, destroying a distinct real transaction (issue #2013).
- Fix: Added a
.limit(2)guard infind_pending_transaction— if more than one same-amount candidate is found the method returnsnil, forcing a new posted entry to be created instead of blindly claiming an ambiguous pending. - Tests: Updated the existing multi-pending test to assert the correct new behavior (new entry created, both pendings survive), and added two new cases: the ATM collision scenario from #2013 and a regression guard confirming single-candidate auto-claim still works.
Test plan
-
bin/rails test test/models/account/provider_import_adapter_test.rb— all tests pass -
bin/rubocop -f github -a— no offenses -
bin/brakeman --no-pager— no new warnings - Manually verify in dev: import two same-amount pending transactions, then post one — both pendings remain, a third posted entry is created
- Manually verify: import a single pending, then post it — still reconciles (no regression)
fixes #2013
Summary by CodeRabbit
-
Bug Fixes
- Transaction reconciliation tightened: the matching logic now considers up to two candidates and will auto-claim only when there is exactly one unique pending match; if multiple same-amount candidates exist, the system creates a new posted entry instead of claiming an ambiguous pending transaction.
-
Tests
- Added tests for same-amount collision scenarios, ensuring ambiguous pending entries are preserved and confirming auto-claim still occurs when a single matching pending transaction exists.