Declare how Bank sync loads each provider's items
JA
6d ago+223+223+012345678901234567890123456789-161-161-012345678901234567890123456789
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:andsettings_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_LISTSholds the defaults (pageordered.select(:id), panelordered); an unknown list name raisesArgumentError. 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, viaconnect_form) andprepare_show_context(the page) both load throughPANEL_CONNECTIONSandload_items; the 26-branchcaseand the 26 hand-written assignments are gone. 24 adapters declare where they differ from the defaults.- The
provider:familygenerator no longer patchesprepare_show_context(update_settings_controllerdeleted). Its adapter template declareslists: { 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_loadandselectvalues are identical;plaid,financekitand 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 inReleaseNotesWorkflowTestfromnodemissing in the test image.bin/rubocopon changed files: no offenses.bin/brakeman: no warnings.
Blast radius
load_provider_itemshas one caller,connect_form, which passes a key only afterFAMILY_PANELS.find;params[:provider_key]is only compared, never used to build a method or variable name.- The page's
@<key>_itemsare read byprovider_summary(A5),family_panel_items(A6) and the panel partials; all receive the same relations as before. ProviderConnectionStatus::PROVIDERSand the A1 declaration tests compare the same frozen declaration hashes, now carryinglists:.- 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
/accountsitem loads and sync preload inAccountsController.