Declare how Bank sync loads each provider's items

JA
6d 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 jaysbeekay/sure#670. Stacked on jaysbeekay/sure#691 (A6); 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#5084 (same commits), in Track A's native stack we-promise/sure#5087.

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. The owner chose this form 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; the plan in jaysbeekay/sure#670 records it.
  • 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.
  • 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.