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

JA
6d 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 the owner 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 jaysbeekay/sure#670 (Track B, controller-layer convergence, option (b) and the setup decision, owner 2026-11-16). Stacked on C1e (jaysbeekay/sure#734) in fork stack #687.

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

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 the owner decided: "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.