Move Brex account setup into the shared account flow
Summary
Provider kit Track B, B2c: Brex's account setup (BrexItem::AccountFlow::Setup) moves to ProviderItem::AccountFlow::Setup, completing the move of Brex's account flow onto the provider kit. Importing the reported accounts, the account type and subtype options, and completing setup now live in the shared flow.
Part of #5003 (Track B, item 2, last of three slices: B2a selection, B2b linking, B2c setup).
Stacked on #5228. Fork pre-flight: jaysbeekay/sure#718 (same branch, same commit; its CI, Gatekeeper review and screenshot history live there).
What changed
app/models/brex_item/account_flow/setup.rb→app/models/provider_item/account_flow/setup.rb, with Brex's names replaced by the provider's: messages from<key>_items.*, supported types fromProvider::<Key>Adapter, accounts throughprovider_accounts, logs naming the provider by its key.unlinked_brex_accountsbecomesunlinked_provider_accounts.ProviderItem::AccountFlowincludesSetupand ownsSetupResult/SetupCompletion. A new hook,provider_account_snapshot_changed?, decides whether an import refreshes an account the provider already reported.BrexItem::AccountFlowimplements that hook (Brex's existing snapshot comparison) and keepsunlinked_brex_accountsas an alias, whichBrexItems::AccountSetupsControllerreads. The two bridges B2a and B2b added forSetup(theNoApiTokenErroralias andupsert_brex_account!) are removed.
Brex's account flow is now 81 lines of hooks and old names over the shared flow.
Nothing user-visible changes.
Demo data
No demo data needed: no new records or UI.
Migration notes
No migration.
Verification
- Existing tests unchanged: the
test/diff against B2b touches only the contract module. Brex's flow (including its setup tests), controller, item, account, importer and syncer tests pass unedited (207 runs, 0 failures across Brex, provider settings and the provider connections API). - Contract (fail-first):
ProviderItemLifecycleTestsadds- "setup imports the reported accounts and creates the ones given a supported type": three accounts imported and offered as unlinked; one set up with a supported type, one skipped, one given an unsupported type and skipped; one sync; the linked one leaves the unlinked list; setting it up again creates nothing and counts no failure;
- "setup leaves an imported account alone when the provider reports it unchanged";
- and the old-constants test now covers
SetupResultandSetupCompletion.
Without the change they fail:uninitialized constant ProviderItem::AccountFlow::SetupResultandundefined method 'unlinked_provider_accounts'.
- Mutations, each caught: an unsupported type not skipped; "skip" not skipped; an already-linked account set up again; unchanged accounts re-saved on import; the unlinked list including linked accounts; no sync after setup; Brex's snapshot comparison always saying unchanged; the success message read from a missing key.
bin/rails test(full, at the B2c commit): 16,270 runs, 0 failures; the same 8ReleaseNotesWorkflowTesterrors (nonodein the test image).bin/rubocopon changed files: no offenses.bin/brakeman: no warnings. No ERB or JS changed.- Size: non-test +261 / -261 with git's default rename threshold, which shows
setup.rbas a delete and an add because about 40% of its lines change names. Withgit diff -M30%it is a rename, and the non-test change is +97 / -97. - Checked against upstream AGENTS.md (blob 1a5dbebd, 2026-11-17): no deviations.
Blast radius
BrexItems::AccountSetupsControllercallsimport_accounts_with_user_facing_error,unlinked_brex_accounts,account_type_options,displayable_account_type_options,subtype_optionsandcomplete_setup_result; all keep their names.- Nothing else referenced
BrexItem::AccountFlow::Setupor required its file. - Siblings: the other providers (Lunch Flow, Mercury, Sophtron, SimpleFIN and others) build their own type and subtype options in their controllers; they move in their own slices.
Summary by cubic
Moves Brex's account setup into the shared provider account flow, replacing BrexItem::AccountFlow::Setup with ProviderItem::AccountFlow::Setup. Importing reported accounts, type and subtype options, and completing setup now live in the shared flow; Brex's flow is 81 lines of hooks and aliases over it, with nothing user-visible changing.
Refactors
- Setup reads provider-specific names through
item,provider_accounts,adapter_class,provider_name,provider_error_class, andi18n_scope, using a newprovider_account_snapshot_changed?hook to decide whether an import refreshes an account. - Behavior change: setup now rescues any error per account, not just
RecordInvalidandRecordNotSaved, so one failing account no longer stops later accounts from being created orsync_laterfrom running. - A set-up account is counted only after its transaction commits, so a failed COMMIT counts as failed instead of created and synced.
SetupResultandSetupCompletionmove to the shared flow;unlinked_brex_accountsremains as an alias for the setup controller, and theNoApiTokenErroralias andupsert_brex_account!bridge are removed.- Brex tests pass, now including a new failed-commit case; the shared lifecycle contract test gains setup scenarios covering import, unchanged accounts, per-account failures, and failed commits.
Summary by CodeRabbit
- Improvements
- Account setup now provides a consistent way to review imported accounts and choose which ones to add.
- Repeating setup avoids creating duplicate accounts when provider account details have not changed.
- If adding one account fails, other accounts that were successfully added remain available.
- Setup results report successful additions, skipped accounts, and failures.