Report Mercury sync status and errors like the provider kit

JA
6d ago
+287-24

Summary

Mercury convergence, C2a: Mercury's syncer now reports status, the import result, errors and failures the way the provider kit's shared syncer does (Brex today, and Lunch Flow since C1a). This is a reviewed behaviour change of its own, so the later conversion (B8) can move Mercury onto the shared syncer as a pure move.

Part of jaysbeekay/sure#670 (Track B, Mercury convergence; decisions of 2026-11-16 apply to Mercury as to Lunch Flow). Stacked on C1c (jaysbeekay/sure#728) in fork stack #687.

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

Behaviour delta (Mercury)

BeforeAfter
Status texthard-coded English stringsmercury_items.syncer.* translations, with the same English wording. "1 accounts need setup..." becomes "1 account needs setup..." (pluralised).
The import's resultignored: a sync whose account or transaction fetch failed completed as healthy, with no errorsreported: account_import_error / transaction_import_error for per-account counts, otherwise import_error with the provider's text ("Mercury import failed: Failed to fetch accounts data") or "Mercury import failed."
A linked account that fails to process, or whose balance sync can't be schedulednot reportedreported as account_processing_error / account_sync_error
An exception during syncthe raw message stored on the sync and its stats, and the exception re-raiseda safe translated message stored and raised as MercuryItem::Syncer::SafeSyncError (credentials_invalid for an :unauthorized / :access_forbidden API error, otherwise failed). The raw error is logged with its backtrace and sent to Sentry, tagged mercury_item_id.
A rejected API tokensync error "Invalid API token""Invalid Mercury API token or account permissions". The connection is still flagged requires_update.

Unchanged: the setup counts (total_accounts, linked_accounts, unlinked_accounts), pending_account_setup, the transaction stats, and the import call (the sync window is C2b).

Mercury had no provider_warnings.* messages, so no translation moves. The new keys are in en only; other locales fall back to English for them, as for Brex and Lunch Flow.

No C2c. Mercury's accounts cache is already keyed per connection (mercury_accounts_<family>_<connection>) and already dropped when the token or base URL changes (MercuryItemsController#update, covered by "update expires selected mercury account cache when credentials change" and its name-only guard), so the Lunch Flow C1c change has no Mercury counterpart.

What changed

  • MercuryItem::Syncer: rewritten in the shared syncer's shape (Lunch Flow's C1a syncer without its holdings wording and investment warning).
  • config/locales/views/mercury_items/en.yml: mercury_items.syncer.*.

Demo data

No demo data needed.

Migration notes

No migration. Existing sync records keep their stored messages; only new syncs use the new ones.

Verification

  • Tests (fail-first): MercuryItem::SyncerTest grows from 1 to 8 tests. On the old syncer 7 of 8 fail, each on the delta it names: the account and transaction failure counts and categories, the provider's error text, process and schedule failures (all undefined method 'map' for nil: no errors were recorded), SafeSyncError (uninitialized constant), the status text from translations, and the rejected-token message. The healthy-import test passes before and after.
  • Mutations, each caught: process failures not collected; schedule failures not collected; credential errors not recognised; a hard-coded status; the original exception re-raised; the provider's error text ignored; the import result ignored (the old behaviour); the raw message stored.
  • Mercury model and controller tests: 64 runs, 0 failures.
  • bin/rails test (full, at the C2a commit): 16,325 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.
  • Size: non-test +138 / -23 (syncer +114 / -23, locale +24).
  • Checked against upstream AGENTS.md (blob 1a5dbebd, 2026-11-17): no deviations.

Blast radius

  • MercuryItem::Syncer is reached only through MercuryItem#syncer (Syncable) from Sync#perform, and mercury_item_test.rb checks its class.
  • Siblings: the kit syncer and Lunch Flow's (C1a) already have this shape.

Review notes

A code review of the diff before commit raised seven points; none changed it, because each is either the kit's behaviour that Mercury now matches by design or a later slice:

  • the re-raised SafeSyncError keeps the original as its cause, so Sentry sees the failure twice (Up/Akahu/Fio/Monobank raise with cause: nil). True of the kit syncer and Lunch Flow's too; changing it here alone would make B8 not a pure move. Recommended as one follow-up across the kit, Lunch Flow and Mercury.
  • the generic message for non-credential exceptions, the provider's raw error text in import_failed_with_error, no DebugLogEntry, and the private setup-stats helper: all the kit's behaviour (owner decisions of 2026-11-16).
  • subclassing ProviderItem::Syncer: that is B8.
  • the sync window: that is C2b.