Set up Mercury accounts through the provider kit's setup
Summary
Mercury controller convergence, C2f: setting up imported accounts. Mercury's setup_accounts and complete_account_setup now run through the provider kit's account setup, as Lunch Flow's do since C1f (jaysbeekay/sure#735). Following that template, the setup page now always fetches the connection's accounts; before, it fetched only while the connection had none, so accounts added at Mercury later never appeared.
Part of #5003 (Track B, controller-layer convergence for Mercury, decided 2026-11-16, Lunch Flow slices as the template).
Stacked on #5252. Fork pre-flight: jaysbeekay/sure#745 (same branch, same commit; its CI, Gatekeeper review and screenshot history live there).
Behaviour delta (Mercury)
| Before | After | |
|---|---|---|
| Opening the setup page | fetched and wrote accounts only when the connection had none | always fetches; new accounts are imported, and an imported account, linked or not, is re-imported when Mercury now reports it differently. For a linked account that refreshes its name, balance, status and raw payload from the accounts endpoint, the same upsert_mercury_snapshot! the next sync's import runs. The only reader of current_balance is MercuryAccount::Processor, during a sync. |
| The API fails while the page loads | accounts already imported were still listed | the 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." |
| Completing with nothing to create | a notice, and a Turbo stream in a frame | an alert, redirect to /accounts, no stream |
| All accounts skipped | notice | the same text as an alert |
| An account type Mercury doesn't support (anything but Depository) | ignored, not counted | counted as skipped |
| A subtype not offered for Depository | stored as submitted | dropped, so the Depository default applies |
| Depository with no subtype chosen | no subtype | checking (the kit's default) |
| One account fails validation | the whole setup rolled back | the others are created; "Successfully created 1 account(s), but 1 account(s) failed." |
| An unexpected setup error | "Failed to create accounts: An unexpected error occurred" (literal) | the same text, from complete_account_setup.unexpected_error |
Subtype labels are unchanged: Mercury already used the kit's fallback (the SUBTYPES long label).
What changed
MercuryItemsController#setup_accounts/#complete_account_setupcall the flow; Mercury'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 moves onto the kit (B8b).MercuryItem::AccountFlow#provider_account_snapshot_changed?: the stored payload differs from the reported one.config/locales/views/mercury_items/en.yml:partial_success,partial_skipped,creation_failed_countandunexpected_errorundercomplete_account_setup. Other locales fall back to English for these, as Mercury's literals were English.
Demo data
No demo data needed.
Migration notes
No migration.
Verification
- Tests (fail-first): new
MercuryItemsSetupTest, Lunch Flow's ten setup tests on Mercury: always fetching; re-importing a changed account; leaving an unchanged one alone (a guard); the translated unexpected error; no token; nothing to create; an unsupported type counted as skipped; Depository defaulting tochecking; an unknown subtype dropped; one failing account not undoing the other. On the old code 9 of 10 fail. - Existing tests unedited:
MercuryItemsControllerTestand the Mercury selection tests pass. - Mutations, each caught: never re-importing; always re-importing; completing always streaming; subtypes not sanitized.
bin/rails test(full, at the C2f commit): 16,456 runs; one failure,InvestmentStatementTest#test_totals_cache_invalidates_when_an_exchange_rate_is_stored, the known unrelated flake (it also failed on jaysbeekay/sure#718's CI); that file passes 3 of 3 reruns; plus the same 8ReleaseNotesWorkflowTesterrors (nonodein the test image).bin/rubocopon changed files: no offenses.bin/brakeman: no warnings.- Size: non-test +55 / -195.
- Checked against upstream AGENTS.md (blob 1a5dbebd, 2026-11-17): no deviations.
Blast radius
- The setup view reads
@api_error,@mercury_accounts,@account_type_optionsand@subtype_options, all still set. ProviderItem::AccountFlow::Setupis unchanged.
Review notes
The kit-behaviour points raised on Lunch Flow's C1f (jaysbeekay/sure#735) apply here unchanged. These include: an API outage blocking setup of accounts already imported; per-account transactions; "all skipped" as an alert; the copied helpers until the controller moves onto the kit; and the snapshot check comparing the payload only.
Summary by cubic
Moves Mercury's account setup onto the provider kit's setup flow, matching what Lunch Flow's setup already does.
The setup page now always fetches the connection's accounts, so accounts added at Mercury later appear and accounts Mercury now reports differently are re-imported; before, it fetched only while the connection had none. Completing setup now follows the kit: one failing account no longer rolls back the others, unsupported account types count as skipped, unknown subtypes are dropped so Depository defaults to checking while valid subtypes are kept, and setups that create nothing show an alert instead of a notice.
Behavior changes
- An API failure while the setup page loads shows "Failed to Fetch Accounts" instead of the already-imported list.
- An unexpected fetch error shows a translated message instead of the raw API message.
- An imported account is re-imported only when its stored payload differs from what the provider reports.
- Completing with nothing to create no longer emits a Turbo stream.