Move Mercury's models onto the provider kit base classes

Merged
JA
2d ago
+1027-622

Summary

Provider kit Track B, B8a: Mercury's connection and account models move onto the provider kit's base classes, and Mercury drops its own syncer body and unlinking concern for the kit's. A pure move, as B7a was for Lunch Flow: every existing Mercury test passes unedited. Two small differences come with the kit's code (see Behaviour notes). The Mercury convergence slices (C2a jaysbeekay/sure#729, C2b jaysbeekay/sure#730) and K2 (jaysbeekay/sure#732) made Mercury's syncer identical to the kit's.

Part of #5003 (Track B, step 8: the Mercury conversion, models layer). It comes ahead of Mercury's controller convergence because that convergence uses the kit's account flow, which needs these base classes.

Stacked on #5249. Fork pre-flight: jaysbeekay/sure#740 (same branch, same commit; its CI, Gatekeeper review and screenshot history live there).

What changed

  • MercuryItem < ProviderItem (it gets Syncable and Unlinking from the base) and MercuryAccount < ProviderAccount (it gets account_provider, account and current_account; linked_account stays).
  • MercuryItem::Syncer < ProviderItem::Syncer: a thin subclass naming Mercury's credential errors; it keeps the constant and SafeSyncError.
  • app/models/mercury_item/unlinking.rb deleted; ProviderItem::Unlinking does the same work and returns the same provider_account_id key.
  • New MercuryItem::LifecycleTest includes ProviderItemModelLifecycleTests.

Behaviour notes

  • Unlink rescue scope. The deleted mercury_item/unlinking.rb looked up an account's links above its begin, so a DB error there raised to destroy. ProviderItem::Unlinking#unlink_all! looks them up inside its per-account rescue, so that error is recorded in result[:error] and the loop goes on to the next account. The old code already swallowed transaction failures the same way, and destroy ignores the result. Brex and Lunch Flow have had this since they moved (full review 6947301630).
  • Method lookup. The include order changed: Provided, Encryptable, DestroyableLater now sit ahead of ProviderItem, Syncable and ProviderItem::Unlinking in MercuryItem.ancestors. The one name defined twice is syncer: MercuryItem::Provided#syncer now wins over Syncable#syncer (it used to be the other way round). Both return MercuryItem::Syncer.new(self), so behaviour is the same; only its visibility changes (Provided's is public). No other method is shared.

Demo data

No demo data needed.

Migration notes

No migration. Sync and AccountProvider rows keep recording MercuryItem and MercuryAccount.

Verification

  • Existing tests unedited: Mercury's model, syncer, importer and controller tests, with Brex's and Lunch Flow's, pass (182 runs, 0 failures).
  • Contract (fail-first): on the old models all 7 lifecycle tests fail (to be a kind of ProviderItem, undefined method 'provider_accounts' / 'provider_key').
  • Mutation, caught: Mercury's credential errors not named (MercuryItem::SyncerTest, rejected token).
  • bin/rails test (full, at the B8a commit): 16,423 runs, 0 failures; the same 8 ReleaseNotesWorkflowTest errors (no node in the test image).
  • bin/rubocop on changed files: no offenses. bin/brakeman: no warnings.
  • Size: non-test +4 / -210.
  • Checked against upstream AGENTS.md (blob 1a5dbebd, 2026-11-17): no deviations.

Blast radius

  • Family::Syncer.syncable_item_associations still finds mercury_items (asserted in the contract).
  • MercuryItemsController#destroy calls unlink_all! and ignores the result.
  • Siblings: none left; Brex and Lunch Flow are already on these bases.

Summary by cubic

Moves Mercury's connection and account models onto the provider kit base classes: MercuryItem now inherits ProviderItem and MercuryAccount inherits ProviderAccount, so Mercury gets the shared syncer, unlinking, and account association logic. MercuryItem::Syncer becomes a thin subclass that only names Mercury's credential errors, and the lifecycle contract now covers Mercury. All existing Mercury tests pass unedited.

Behavior changes

  • Unlink failures during link lookup no longer raise to destroy; they're recorded in result[:error] and unlinking continues with the next account, matching Brex and Lunch Flow.
  • MercuryItem::Provided#syncer now takes precedence over Syncable#syncer in method lookup; both return the same instance, so only visibility changes.