Declare how /accounts loads each provider's connections
Merged
JA
2d ago+285+285+012345678901234567890123456789-118-118-012345678901234567890123456789
Summary
Provider kit Track A, A8: how /accounts loads each provider's connections, and which of them its sync preload covers, is declared on the adapters instead of written out in AccountsController.
Part of #5003
Stacked on #5084 (A7), in Track A's native stack on #5005.
Fork pre-flight: jaysbeekay/sure#693 (same commits, against a mirror of upstream main; its CI, Gatekeeper and review history live there).
What changed
declares_connection lists:gainsaccounts_index:. Its default, built per declaration, isordered.with_attached_logo.includes(<accounts association>); 17 adapters declare where they differ; FinanceKit (whose accounts/accountslists separately) opts out withaccounts_index: nil.nilis rejected for the Bank sync lists.AccountsController::INDEX_CONNECTIONSdrives both the index loads (each still throughvisible_provider_items) andpreload_latest_sync_metadata_for_index!; the 27 hand-written loads and the hand-kept preload list are gone.- The
provider:familygenerator's/accountsitems patch is removed: its regex (@x_items = family.x_items.ordered) stopped matching once the loads were wrapped invisible_provider_items, so a generated provider got no/accountsload at all; it now gets the default. The generator still adds the provider's sync stats map. - Diff: non-test +96 / −118.
No visible change.
Review fixes (2026-11-15)
- An adapter without
declares_connection(it already existed, or--skip-adapter) leaves@<key>_itemsunset on /accounts, but the generator added a sync stats loop and an index section that calledeachandany?on it, so /accounts raised for every user. Both inserts now read the items nil-safe. Test: generates into copies of the real controller and view, then runs the inserted code with the items unset (failed withundefined method 'each' for nilbefore); reverting either&.is caught. - With
--skip-viewthe generator still added the /accounts section, which renders the item partial that--skip-viewdoes not write. The template's declaration loads the provider's connections onto /accounts, so the page raised a missing-template error for every family once a connection existed. The section is now skipped under--skip-view, and the generator says which partial to write and where to render the items. Test: "--skip-view leaves /accounts alone and says what to add" (failed before: the section was added). Mutations caught: keeping the insert, dropping the message, inverting the condition. Full suite at the top of the stack after the restack: 16,251 runs, 0 failures (the same 8ReleaseNotesWorkflowTesterrors, no node in the test image).
Demo data
No demo data needed.
Migration notes
No migration.
Verification
- Old vs new (Rails runner on fixtures, old index block loaded as a separate class): every one of the 27 providers yields the same visible connections in the same order, for the fixture admin (17 providers with connections) and member. The queries are identical except Trading 212 and Sharesight, whose declared queries now sort by creation before
visible_provider_itemsinstead of after; that filter is aselect, so order is kept (ties on equalcreated_atwere arbitrary before and still are). - Fail-first: "each provider on /accounts declares the query its connections load with" (pins all 27 queries and FinanceKit's opt-out), "a connection is on /accounts, ordered with its logo and accounts, unless it opts out", "index loads each provider's connections with its declared query" and "the index sync preload covers every provider's connections" failed before the change (no
accounts_indexon the declarations). - Mutations, each caught: default without the accounts preload; default without the logo; skip
visible_provider_items; preload only the first provider; Trading 212 unsorted, sorted by id, or reversed (the last two by "index lists Trading 212 connections oldest first", added after review); Fio withoutactive; FinanceKit listed; Brex without its nested preload; nonilguard on the Bank sync lists. eager_load!clean.bin/rails test(full): 15,883 runs, 0 failures; 8 errors inReleaseNotesWorkflowTestfromnodemissing in the test image. After rebasing the stack onto upstreammain(dbeebf14c), the full suite at the top of the stack (A9): 16,246 runs, 0 failures, the same 8 environment errors.bin/rubocopon changed files: no offenses.bin/brakeman: no warnings.
Blast radius
- The same 27
@<key>_itemsare set, each filtered byvisible_provider_items; their readers (the index sections,build_sync_stats_maps,@onchain_wallet_cards, the empty-state check) are unchanged. Nothing on/accountsreads@financekit_items. INDEX_CONNECTIONSis built at class load fromProvider::Factory.connection_declarations, likePANEL_CONNECTIONSandProviderConnectionStatus::PROVIDERS.- Sibling left for A9: the empty-state check in
accounts/index.html.erb. The index sections stay hand-kept (Track B).
Summary by cubic
Declares how /accounts loads each provider's connections on the provider adapters instead of the 27 hand-written loads in AccountsController. No visible change.
declares_connectiongains anaccounts_indexlist, defaulting to ordered with the logo and the declared accounts association preloaded; 17 adapters declare where they differ and FinanceKit opts out withnil.AccountsController::INDEX_CONNECTIONS, built from the declarations, now drives both the index loads and the sync preload; all items still pass throughvisible_provider_items.- The
provider:familygenerator no longer patches the index action; the sync stats map and the section it still adds read the provider's items nil-safely, since an adapter without a declaration leaves them unset. - With
--skip-view, the generator leaves/accountsalone and says which item partial to write and where to render the items, since that partial isn't written. nilis rejected for the Bank sync lists, which can't be left out.
Summary by CodeRabbit
- Improvements
- Account connections are displayed with provider-specific ordering and associated account details, with logos shown where available.
- Sync information on the accounts page now covers the connections displayed there.
- Trading 212 connections are ordered from oldest to newest on the accounts page.
- Documentation
- Updated provider setup guidance to explain how account details are loaded on the accounts page and what to configure when skipping view generation.