Files
sure/test/models
5a2bf02b13 fix(simplefin): stop repair_stale_linkages from hijacking a live linkage on a same-name twin (#3116)
* fix(simplefin): stop repair_stale_linkages from hijacking a live linkage on a same-name twin

repair_stale_linkages matched purely on case-insensitive display name, so two
distinct upstream accounts sharing a name (e.g. two "CHECKING (0001)" accounts
at the same institution) caused the unlinked twin to silently steal the linked
account's AccountProvider, merge in its transactions, and overwrite its balance
on every subsequent sync.

Thread the upstream account_id set already computed during account discovery
through to repair_stale_linkages so it only treats a linked account as stale
when its account_id is actually absent upstream, and skip ambiguous multi-way
name matches instead of picking the first one.

Fixes #2852

* fix(simplefin): clear stale upstream_account_ids and log skipped repairs

- Clear simplefin_item.upstream_account_ids at the start of each
  perform_account_discovery run so a later discovery that finds zero
  accounts can't reuse IDs from a prior run on the same SimplefinItem
  instance (CodeRabbit review finding).
- Capture skipped stale-linkage repairs via DebugLogEntry so operators
  can see them in /settings/debug, not just the raw Rails log (Codex
  review finding).
- Fix two pre-existing SimplefinAccount::Transactions::ProcessorInvestmentTest
  tests broken by the new upstream_account_ids nil-guard: they called
  process_accounts directly without going through the Importer, so they
  now set upstream_account_ids explicitly to simulate a legitimate
  "old account_id genuinely absent upstream" repair.
- Add regression coverage for both fixes.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

---------

Co-authored-by: Gerald <248542187+gfr-free@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-22 06:34:09 +02:00
..
2026-03-25 10:50:23 +01:00
2025-11-11 19:51:07 +01:00