Port #3557's pending SQL refinements to main
Summary
This closes the drop 0 single-copy gap that #118 records against we-promise/sure#3557's pending-SQL half: "reconciled after the next weekly sync, not ported onto a stale base". #264 has merged, and fork main is level with upstream main, so the port now lands on a current base.
Fork main has the first pending-SQL change (#138) but none of the refinements #3557 took afterwards. This PR ports them with cherry-pick -x; all six applied cleanly:
| #3557 commit | Here | What it changes on main |
|---|---|---|
1f77fcab9 | 5a84fba3d | Builds the correlated pending SQL lazily. |
74c92d1d5 | 7baedf492 | Builds pending SQL without borrowing a database connection at class load. |
dab7c6949 | 7052bf616 | Shares one list of false flag values across every pending SQL builder, so they cannot quote the values differently. |
44b44fc80 | bf1b80585 | Decides Monobank's stale-pending prune the way Transaction#pending? does. |
1b3f564a3 | 22d4e58e9 | Reads pending provider metadata through one predicate (Transaction.pending_extra?). A provider value that isn't a hash can no longer raise TypeError and abort an import (CodeRabbit's finding on #3557). |
380b71f70 | 54a32e998 | States the leading-AND contract on pending_providers_sql. |
Plus one commit of mine, 347b532f6. It removes Account::ProviderImportAdapter::PENDING_LOOKUP_SQL, which the ports left with no callers; #3557 had already deleted it. It still spelled pending with the ::boolean cast that raises on an unparseable flag. The same commit adds one blank line to transaction_test.rb so the file matches #3557's head.
Single-copy check against up/pending-sql-parity (1c89d1159)
These files are now byte-identical to #3557's head: transaction.rb, entry_search.rb, entry.rb, the Monobank, Akahu and Up processors, simplefin_item/importer.rb, goal/withdrawal_detector.rb, pending_duplicate_merges_controller.rb, the SimpleFIN pending rake task, and their tests, including transaction_test.rb.
Remaining differences, all deliberate:
provider_import_adapter.rb, +6 on the fork. Two fork-only features that aren't part of #3557: thecc_paymentkind for credit-card payments, and stampingupdated_atin the collision handler (InvestmentStatement#holdings_versionkeys on it).portfolio/flow_classifier.rb, its test andportfolio_flow_test_helper.rb. Comment lines that reference the fork's contract gate. #262 already declared this divergence, and the gate isn't sent upstream (#118).- Fork-only tests: 57 lines in
income_statement_test.rb, 13 inimporter_stale_unmatched_pending_test.rb, and a composite-key collision stamps updated_at on the row it adopts inprovider_import_adapter_test.rb. - Two upstream tests are missing from fork
main, and this PR does not restore them: preserves existing trade fee when reimport omits it (from upstream #3507) and find_pending_transaction covers every pending-capable provider (from upstream #3386). Both are on upstreammain, so an earlier sync dropped them from the fork. #279 restores them.
Behaviour changes (release note)
These apply only to malformed or false flags. Every provider writes a real boolean, and both the old rule and the new one treat it the same way.
- An unparseable stored
monobank.pendingflag (e.g."maybe") is now treated as pending and pruned. Before, the::booleancast raisedPG::InvalidTextRepresentationand aborted the whole stale-pending prune for that sync (bf1b80585). - A stored pending flag of
"false"is now left alone when a booked transaction reuses the pending entry'sexternal_id. Before, it was read as pending, and the booked sync deleted it (22d4e58e9). - A provider namespace in
extrathat is not a hash now reads as not pending. Before,Hash#digraisedTypeErrorinsideAccount.transactionand aborted the import (22d4e58e9).
Validation
- Every test file #3557 touches, plus
transaction/search_test,transactions_controller_testandinvestment_statement_test: 495 runs, 2,342 assertions, 0 failures. - The ported tests catch a reverted fix:
- With
22d4e58e9's app code reversed (the shared predicate): 1 failure and 3 errors acrossprovider_import_adapter_test, the Monobank processor test andtransaction_test. - With
bf1b80585's reversed (the Monobank prune): 1 error. - Both were restored before pushing.
- With
bin/rubocopon the 9 changed Ruby files: no offenses.- CI runs the full suite on this branch.