Declare how Bank sync loads each provider's items

Merged
JA
2d ago
+223-161

Summary

Provider kit Track A, A7: how Bank sync loads each family panel provider's items, on the page and in the provider's panel, is declared on its adapter instead of written out twice in Settings::ProvidersController.

Part of #5003

Stacked on #5083 (A6), in Track A's native stack on #5005.

Fork pre-flight: jaysbeekay/sure#692 (same commits, against a mirror of upstream main; its CI, Gatekeeper and review history live there).

What changed

  • declares_connection ... lists: takes a query per list, settings_page: and settings_panel:, as scope names (%i[active ordered]) or a lambda over the family's item relation, for the queries that also filter, select or preload. Provider::Base::ITEM_LISTS holds the defaults (page ordered.select(:id), panel ordered); an unknown list name raises ArgumentError. This form was chosen over named scopes alone (which cannot express the credential filters, select(:id), preloads or nested includes) and over a class method per list on each item model.
  • load_provider_items (the panel, via connect_form) and prepare_show_context (the page) both load through PANEL_CONNECTIONS and load_items; the 26-branch case and the 26 hand-written assignments are gone. 24 adapters declare where they differ from the defaults.
  • The provider:family generator no longer patches prepare_show_context (update_settings_controller deleted). Its adapter template declares lists: { settings_panel: ->(items) { items.where.not(<secret>: [ nil, "" ]) } }, the query the generated panel used as its fallback, so a generated panel still counts only connections that have their secret field. The generator guide is updated.
  • Diff: non-test +120 / −158.

No visible change.

Demo data

No demo data needed.

Migration notes

No migration.

Verification

  • Old vs new (Rails runner, old methods loaded as a separate class): for all 26 panel providers, page and panel, the SQL, includes, preload, eager_load and select values are identical; plaid, financekit and an unknown key still load nothing in the panel.
  • Fail-first: "each panel provider declares the queries its Bank sync page and panel load items with" (pins all 52 queries), "Bank sync and each panel load items through the declared list queries" and "a list query may be scope names or a lambda, and an unknown list is rejected" failed before the change (no lists on the declarations); the two generator template tests failed before the template change.
  • Mutations, each caught: either default changed; only the first scope applied; no unknown-list guard; panel loads the page list and vice versa; Brex's panel without its preloads; Lunch Flow's page without its credential filter; Akahu's page list dropped; SnapTrade's panel without its preload.
  • eager_load! clean.
  • bin/rails test (full): 15,878 runs, 0 failures; 8 errors in ReleaseNotesWorkflowTest from node missing in the test image. After rebasing the stack onto upstream main (dbeebf14c), the full suite at the top of the stack (A9): 16,246 runs, 0 failures, the same 8 environment errors.
  • bin/rubocop on changed files: no offenses. bin/brakeman: no warnings.

Blast radius

  • load_provider_items has one caller, connect_form, which passes a key only after FAMILY_PANELS.find; params[:provider_key] is only compared, never used to build a method or variable name.
  • The page's @<key>_items are read by provider_summary (A5), family_panel_items (A6) and the panel partials; all receive the same relations as before.
  • ProviderConnectionStatus::PROVIDERS and the A1 declaration tests compare the same frozen declaration hashes, now carrying lists:.
  • Generated providers: page query unchanged (ordered.select(:id), as the deleted patch wrote); panel query now declared by the template, equal to the panel's old fallback.
  • Siblings left for A8: the /accounts item loads and sync preload in AccountsController.

Summary by cubic

Declares on each provider's adapter how Bank sync loads that provider's items for the page and for the panel, removing the duplicated hand-written loads in Settings::ProvidersController. Part of #5003.

  • declares_connection now takes lists: with a query per list (settings_page, settings_panel), as scope names or a lambda over the family's items; Provider::Base::ITEM_LISTS holds the defaults.
  • The provider:family generator no longer patches the controller; its adapter template declares the panel query so a generated panel still counts only connections that have their secret field (the first field marked secret in the generated fields), with tests covering a secret that isn't api_key.
  • No visible behavior change — the SQL, preloads and selected columns match the previous implementation for all 26 panel providers.

Summary by CodeRabbit

  • Improvements
    • Provider connections are displayed in settings pages and panels according to each provider’s active-status, ordering, and credential requirements.
    • Provider panels load related account and sync details alongside connections where needed.
  • Documentation
    • Updated the provider setup guide with connection-list configuration and troubleshooting guidance.