Set up Lunch Flow accounts through the provider kit's setup

Merged
JA
2d ago
+211-224

Summary

Lunch Flow controller convergence, C1f: setting up imported accounts. Lunch Flow's setup_accounts and complete_account_setup now run through the provider kit's account setup (ProviderItem::AccountFlow::Setup) instead of their own code, so they behave as Brex's do. As it was decided, the setup page now always fetches the connection's accounts. Before, it fetched only while the connection had none, so accounts added at Lunch Flow later never appeared.

Part of #5003 (Track B, controller-layer convergence, option (b) and the setup decision, decided 2026-11-16).

Stacked on #5245. Fork pre-flight: jaysbeekay/sure#735 (same branch, same commit; its CI, Gatekeeper review and screenshot history live there).

Behaviour delta (Lunch Flow)

BeforeAfter
Opening the setup pagefetched accounts only when the connection had nonealways fetches; new accounts are imported, and an imported account is re-imported when the provider now reports it differently
The API fails while the page loadsaccounts already imported were still listedthe page shows "Failed to Fetch Accounts" (the kit's behaviour)
An unexpected fetch error"API error: ""API error: An unexpected error occurred. Please try again later."
No API keysetup_accounts.no_api_keysetup_accounts.no_api_token, same text in every locale
Subtype labels a locale lacksthe app-wide translated subtype nameunchanged, through a new kit hook (subtype_label_default) Lunch Flow overrides
Completing with nothing to createa notice, and a Turbo stream in a framean alert, redirect to /accounts, no stream (the kit's rule: success means at least one created and none failed)
All accounts skippednotice "All accounts were skipped"the same text as an alert
An account type Lunch Flow doesn't supportignored, not countedcounted as skipped
A subtype not offered for any supported typestored as submitteddropped
Depository with no subtype chosenno subtypechecking (the kit's default; CreditCard already defaulted)
One account fails validationthe whole setup rolled back with "Failed to create accounts: …"the others are created; "Successfully created 1 account(s), but 1 account(s) failed."

What changed

  • LunchflowItemsController#setup_accounts / #complete_account_setup call the flow; Lunch Flow's own fetch, option building, setup loop and messages go. The kit controller's param sanitizers and Turbo-stream rebuild are copied in until the controller itself moves onto the kit.
  • LunchflowItem::AccountFlow: provider_account_snapshot_changed? (the stored payload differs from the reported one) and subtype_label_default (the app-wide translated name).
  • ProviderItem::AccountFlow::Setup#translate_subtypes: the fallback label comes from a new subtype_label_default hook, whose default is the kit's previous expression, so Brex is unchanged.
  • Locales (16): setup_accounts.no_api_key → no_api_token, translations kept (ro.yml already used no_api_token); English adds partial_success, partial_skipped and creation_failed_count (other locales fall back to English for those).

Demo data

No demo data needed.

Migration notes

No migration.

Verification

  • Tests (fail-first): new LunchflowItemsSetupTest (10 tests): always fetching (a new account appears although the connection has some); re-importing a changed account; leaving an unchanged one alone; the translated unexpected error; no API key; nothing to create (alert, no stream); unsupported type counted as skipped; Depository defaulting to checking; an unknown subtype dropped; one failing account not undoing the other. On the old code all 8 behaviour tests fail.
  • Existing tests changed, as decided for the kit: "setup accounts renders German subtype options…" and "setup accounts preserves the English title…" pinned fetch-only-when-empty: with no API stub, the old page never called the API. They now stub the fetch to return no accounts, and their assertions are unedited. "complete_account_setup's stream lists only the manual accounts the viewer can access" posted empty params and relied on a stream for zero accounts; it now submits one account so the stream is rendered, and its assertions are unedited. The two German/English unexpected-error setup tests pass unedited.
  • Mutations, each caught: Lunch Flow's subtype labels falling back to English (the German test); never re-importing a changed account; always re-importing; completing always streaming; subtypes not sanitized.
  • bin/rails test (full, at the C1f commit): 16,381 runs, 0 failures; the same 8 ReleaseNotesWorkflowTest errors (no node in the test image).
  • bin/rubocop on changed files: no offenses. bin/brakeman: no warnings. Every locale file parses.
  • Size: non-test +81 / -213.
  • Checked against upstream AGENTS.md (blob 1a5dbebd, 2026-11-17): no deviations.

Blast radius

  • ProviderItem::AccountFlow::Setup#translate_subtypes also serves Brex; its default label is unchanged (Brex's setup snapshot test passes unedited).
  • The setup page's view reads @api_error, @lunchflow_accounts, @account_type_options and @subtype_options, all still set.
  • Siblings: Mercury converges in its own slices.

Review notes

A code review of the diff before commit raised ten points; all are the kit's existing behaviour, which this slice adopts by design, so none changed it. They are listed for the conversion and for follow-ups:

  • an API outage now blocks setting up accounts already imported (the table above);
  • per-account transactions: an unexpected non-validation error partway leaves earlier accounts created with no sync queued;
  • "all skipped" and partial results are alerts;
  • subtypes are checked against every supported type, not the chosen one. Before, any value was stored;
  • the controller helpers copied from ProviderItemsController go when the controller moves onto the kit (B7);
  • fixing the kit's subtype-label default for every provider would change Brex's labels, so it is a follow-up, not part of this convergence;
  • the snapshot check compares the payload only. Before, existing accounts were never re-imported at all;
  • the family-currency fallback can't apply: LunchflowAccount validates currency presence and its upsert always sets one;
  • the setup fetch doesn't use the 5-minute cache, as on the kit;
  • the new English keys aren't translated, as in earlier convergence slices.

Summary by cubic

Sets up Lunch Flow accounts through the provider kit's account setup (#5003, controller convergence), so Lunch Flow's setup behaves like Brex's. The setup page now always fetches the connection's accounts, importing new ones and re-importing those the provider now reports differently; before, it fetched only while the connection had none. The fetch method is renamed from import_accounts_from_api_if_needed to import_accounts_from_api.

Behavior changes

  • An API failure while the setup page loads now shows "Failed to Fetch Accounts" instead of the already-imported list, and unexpected errors are no longer shown raw.
  • Completing with nothing to create redirects with an alert instead of a notice with a Turbo stream.
  • An error while creating one account no longer rolls back the others; the result reports partial success and skip counts.
  • Unsupported account types count as skipped, unknown subtypes are dropped, and a Depository with no subtype defaults to checking.
  • The no_api_key locale key is renamed to no_api_token in all locales; English adds messages for partial and failed results.
  • The kit's subtype-label fallback now comes from a subtype_label_default hook so Lunch Flow keeps its app-wide labels; Brex's default is unchanged.

No migration needed.