Declare how /accounts loads each provider's connections

JA
6d ago
+285-118

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: gains accounts_index:. Its default, built per declaration, is ordered.with_attached_logo.includes(<accounts association>); 17 adapters declare where they differ; FinanceKit (whose accounts /accounts lists separately) opts out with accounts_index: nil. nil is rejected for the Bank sync lists.
  • AccountsController::INDEX_CONNECTIONS drives both the index loads (each still through visible_provider_items) and preload_latest_sync_metadata_for_index!; the 27 hand-written loads and the hand-kept preload list are gone.
  • The provider:family generator's /accounts items patch is removed: its regex (@x_items = family.x_items.ordered) stopped matching once the loads were wrapped in visible_provider_items, so a generated provider got no /accounts load 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>_items unset on /accounts, but the generator added a sync stats loop and an index section that called each and any? 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 with undefined method 'each' for nil before); reverting either &. is caught.
  • With --skip-view the generator still added the /accounts section, which renders the item partial that --skip-view does 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 8 ReleaseNotesWorkflowTest errors).

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_items instead of after; that filter is a select, so order is kept (ties on equal created_at were 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_index on 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 without active; FinanceKit listed; Brex without its nested preload; no nil guard on the Bank sync lists.
  • eager_load! clean.
  • bin/rails test (full): 15,883 runs, 0 failures; 8 errors in ReleaseNotesWorkflowTest from node missing in the test image.
  • bin/rubocop on changed files: no offenses. bin/brakeman: no warnings.

Blast radius

  • The same 27 @<key>_items are set, each filtered by visible_provider_items; their readers (the index sections, build_sync_stats_maps, @onchain_wallet_cards, the empty-state check) are unchanged. Nothing on /accounts reads @financekit_items.
  • INDEX_CONNECTIONS is built at class load from Provider::Factory.connection_declarations, like PANEL_CONNECTIONS and ProviderConnectionStatus::PROVIDERS.
  • Sibling left for A9: the empty-state check in accounts/index.html.erb. The index sections stay hand-kept (Track B).