Move Mercury's models onto the provider kit base classes
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 getsSyncableandUnlinkingfrom the base) andMercuryAccount < ProviderAccount(it getsaccount_provider,accountandcurrent_account;linked_accountstays).MercuryItem::Syncer < ProviderItem::Syncer: a thin subclass naming Mercury's credential errors; it keeps the constant andSafeSyncError.app/models/mercury_item/unlinking.rbdeleted;ProviderItem::Unlinkingdoes the same work and returns the sameprovider_account_idkey.- New
MercuryItem::LifecycleTestincludesProviderItemModelLifecycleTests.
Behaviour notes
- Unlink rescue scope. The deleted
mercury_item/unlinking.rblooked up an account's links above itsbegin, so a DB error there raised todestroy.ProviderItem::Unlinking#unlink_all!looks them up inside its per-account rescue, so that error is recorded inresult[:error]and the loop goes on to the next account. The old code already swallowed transaction failures the same way, anddestroyignores the result. Brex and Lunch Flow have had this since they moved (full review 6947301630). - Method lookup. The include order changed:
Provided, Encryptable, DestroyableLaternow sit ahead ofProviderItem,SyncableandProviderItem::UnlinkinginMercuryItem.ancestors. The one name defined twice issyncer:MercuryItem::Provided#syncernow wins overSyncable#syncer(it used to be the other way round). Both returnMercuryItem::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 8ReleaseNotesWorkflowTesterrors (nonodein the test image).bin/rubocopon 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_associationsstill findsmercury_items(asserted in the contract).MercuryItemsController#destroycallsunlink_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 inresult[:error]and unlinking continues with the next account, matching Brex and Lunch Flow. MercuryItem::Provided#syncernow takes precedence overSyncable#syncerin method lookup; both return the same instance, so only visibility changes.