Declare how /accounts loads each provider's connections
JA
6d 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 jaysbeekay/sure#670. Stacked on jaysbeekay/sure#692 (A7); built on the fork first and sent upstream as part of Track A's native stack on top of we-promise/sure#5005.
Upstream: we-promise/sure#5085 (same commits), in Track A's native stack we-promise/sure#5087.
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 A9 after the restack: 16,251 runs, 0 failures (the same 8ReleaseNotesWorkflowTesterrors).
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.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).