Move Brex account selection into a shared account flow
JA
6d ago+411+411+012345678901234567890123456789-205-205-012345678901234567890123456789
Summary
Provider kit Track B, B2a: the selection half of Brex's account flow moves into a shared ProviderItem::AccountFlow. Choosing a connection, preloading and caching its accounts, and offering the ones not linked yet now live in the base; Brex keeps thin hooks.
Part of jaysbeekay/sure#670 (Track B, item 2, first of three slices: B2a selection, B2b linking, B2c setup). Stacked on B1 (jaysbeekay/sure#685) in fork stack #687.
Upstream draft PR: https://github.com/we-promise/sure/pull/5227 (same branch, same commit), in native stack we-promise/sure#5268 on refactor/provider-kit.
What changed
ProviderItem::AccountFlow(new):selected?,selection_required?,preload_payload,select_accounts_result,select_existing_account_result, the accounts cache and the unlinked-accounts filter, moved fromBrexItem::AccountFlowwith the provider named by its declared key:- i18n scope
<key>_items.*, cache key<key>_accounts_<family>_<item>(for Brex: identical to before), supported types fromProvider::<Key>Adapter; - the connection's item class is the flow's parent (
BrexItemforBrexItem::AccountFlow), its association and key come from the adapter'sdeclares_connection; - hooks a provider implements:
fetch_accounts,resolve_item,provider_error_class,.cache_sensitive_params, and optionallyaccount_offered_as?to narrow accounts per type.
- i18n scope
BrexItem::AccountFlow < ProviderItem::AccountFlowkeeps its public names:brex_item,brex_item_id, thebrex_item:/brex_item_id:keywords,result.brex_item, andBrexItem::AccountFlow::NoApiTokenError(the same class as the base's). Linking andSetupstay in Brex's file until B2b and B2c.- One alias,
BrexItem::AccountFlow::NoApiTokenError = ProviderItem::AccountFlow::NoApiTokenError:Setupis a nested module whose constant lookup does not see inherited constants. It goes whenSetupmoves in B2c.
Nothing user-visible changes. Log lines read the same ("Brex preload error", "Brex API error in select_accounts").
Demo data
No demo data needed: no new records or UI.
Migration notes
No migration.
Verification
- Existing tests unchanged: the
test/diff against B1 touches only the contract module and Brex's lifecycle test (both new in B1). Brex's flow, controller, item, account, importer and syncer tests pass unedited (201 runs, 0 failures across Brex, provider settings and the provider connections API). - Contract (fail-first):
ProviderItemLifecycleTestsadds- "the account flow is the shared flow and keeps its old constants",
- "selection offers the connection's accounts that are not linked yet" (before and after linking one),
- "selection offers nothing for a type the provider does not support",
- "each connection caches its own accounts under the provider's key" (a second connection does not read the first one's cache).
Without the change, all fail:uninitialized constant ProviderItem::AccountFlowandunknown keyword: :item.
- Brex test: "Brex offers cash accounts as depository and cards as credit cards" (its
account_offered_as?hook). - Mutations, each caught: cache key without the item id; linked accounts not excluded; Brex offering every account for every type; the result dropping the item; a cache key not prefixed by the provider key; the cache never expiring on a credentials update; an unsupported type offered accounts.
bin/rails test(full, at the B2a commit): 16,265 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.- Diff with copy detection (
git diff -Cagainst B1): non-test +296 / -203. - Checked against upstream AGENTS.md (blob 1a5dbebd, 2026-11-17): no deviations.
Blast radius
BrexItems::AccountFlowsControllercallspreload_payload,select_accounts_resultandselect_existing_account_resultand readsresult.brex_item;BrexItems::AccountSetupsControllerbuilds the flow withbrex_item:;BrexItemsController#updatecallsupdate_item_with_cache_expiration. All keep their names.- Brex's linking methods and
Setupcallbrex_item,accounts,indexed_accountsandsupported_account_type?, which now come from the base. - Siblings: Lunch Flow, Mercury and Sophtron build their own
<key>_accounts_…cache keys in their controllers and models; they move in their own slices (B7, B8 and later), so they are untouched here.