Generate the provider controller and routes on the provider kit

JA
5d ago
+191-378

Summary

Provider kit Track B, B6c: provider:family generates a provider's controller and routes on the provider kit. The generated <Key>ItemsController subclasses ProviderItemsController and only names its permitted params, and its routes use the provider_items concern. The 298-line controller scaffold goes (owner decision, 2026-11-15: templates the kit owns are deleted outright).

Part of jaysbeekay/sure#670 (Track B, step 6: the generator onto the kit, sliced by layer: B6a models, B6b account flow, B6c controller and routes, then views). Stacked on B6b (jaysbeekay/sure#755) in fork stack #687.

Upstream draft PR: https://github.com/we-promise/sure/pull/5265 (same branch, same commit), in native stack we-promise/sure#5268 on refactor/provider-kit.

Before / after (what rails g provider:family writes)

BeforeAfter
app/controllers/<key>_items_controller.rb298-line ApplicationController scaffold with its own CRUD, selection, linking and setup< ProviderItemsController, defining only item_params
A blank secret on an editoverwrote the stored secretdropped from the params, keeping the stored secret (as Brex, Mercury and Lunch Flow do)
Routesa 15-line resources … do collection … member … end block, added at the top of the draw block by Rails' route helperresources :<key>_items, only: %i[index new create show edit update destroy], concerns: :provider_items, inserted straight after the concern's definition
Routes when config/routes.rb has no provider_items concernnot added; the generator says what to add
Localethe old controller's keys (no_api_key, sync.success, preload_accounts.*)every message ProviderItemsController and ProviderItem::AccountFlow read: default_connection_name, select_connection, no_api_token, unexpected_error, the setup-completion messages

The route helpers and paths are the ones the old block produced: the test compares the generated provider's named routes with Brex's, name for name.

Screenshots

None: no UI change.

Demo data

No demo data needed.

Migration notes

No migration.

Verification

  • Tests, fail-first. Three tests replace the two that pinned the old scaffold's frame-redirect and panel behaviour. All three failed on the old templates (the old controller template could not render without table_name; the old routes were not after the concern, Expected: 1; no gocardless_items.default_connection_name) and pass after:
    • "the generated controller is a thin provider kit controller": loads the rendered controller in an isolated namespace; checks it subclasses ProviderItemsController, defines no action of its own, permits the declared fields and nothing else, drops a blank secret on an edit and keeps it on a create;
    • "the generated routes use the provider_items concern after it is defined": runs add_routes on a copy of config/routes.rb, checks the one inserted line sits after the concern, then draws the concern and that line in a fresh RouteSet and compares its named routes with Brex's;
    • "the generated locale has every message the provider kit's controller and account flow read": 48 keys, each with Brex's plural forms and interpolations.
    • "the generated locale names every setup option the account flow reads for a supported type" (added after full review 6947517022, finding 2): for each type the generated adapter supports, setup_accounts.account_types, subtype_labels and, where the flow shows one, subtype_messages. Dropping subtype_labels.depository, subtype_messages.credit_card or subtype_labels.investment from the template fails it.
  • A test ordering fix found on the way: routes load lazily in test, so the route test calls Rails.application.reload_routes_unless_loaded before reading Brex's routes; without it, seed 6 failed. The file then passed on seeds 1–8.
  • Mutations, each caught (9): a blank secret overwriting on edit; a blank secret dropped on create too; a declared field not permitted; the controller defining its own action; the routes inserted at the top of the block; the routes without the concern; default_connection_name missing; no_api_token left as no_api_key; an interpolation dropped from partial_skipped.
  • bin/rails test (full, at this commit): 16,531 runs, 0 failures; the same 8 ReleaseNotesWorkflowTest errors (no node in the test image).
  • bin/rubocop on the changed Ruby, bin/brakeman: no offenses or warnings.
  • Size (git diff -C): non-test +48 / -328.
  • The earlier merge-down commits' subjects ("Merge up/... into up/...") exceed 72 characters. They stay fork-only: Track B is rebased linear when it goes upstream, as Track A was, so they never reach we-promise/sure.
  • Checked against upstream AGENTS.md (blob 1a5dbebd, 2026-11-17): no deviations.

Blast radius

  • Only rails g provider:family. Existing providers and config/routes.rb are untouched.
  • What the kit's controller does differently from the old scaffold, for a newly generated provider: a new connection redirects to /accounts and starts a sync (the scaffold went to Settings > Providers); select_* with no credentials render the kit's setup-required dialog rather than a frame redirect; selection, linking and setup go through the stubbed account flow from B6b, so they raise NotImplementedError until its hooks are written.
  • Siblings: the generated views still use the old templates and the old panel.* keys; the next slices move them onto the kit's components.
  • Not runnable at this head on its own. The views generated here do not match the kit's controller yet: setup_accounts.html.erb reads @unlinked_accounts, which the kit never sets, so every generated setup page raises; the setup form posts selected_accounts[] while complete_account_setup reads account_types; select_existing_account reads @<key>_accounts while the kit sets @available_accounts, so it always shows the empty state; and the kit renders select_accounts, _setup_required and _api_error, which this slice does not write. B6d (jaysbeekay/sure#757) writes every view the kit renders on the kit's components; this slice and B6d go upstream together in the one Track B stack, never apart (full review 6947517022, finding 1).