Manage Mercury connections the way the provider kit does

Merged
JA
1d ago
+91-26

Summary

Mercury controller convergence, C2g: managing connections. Mercury's create, update and destroy now behave as ProviderItemsController's, as Lunch Flow's do since C1g (jaysbeekay/sure#736). sync already matched the kit. This is the last difference between Mercury's controller and the kit's, so the controller can move onto the kit as a pure move (B8b).

Part of #5003 (Track B, controller-layer convergence for Mercury, decided 2026-11-16).

Stacked on #5253. Fork pre-flight: jaysbeekay/sure#746 (same branch, same commit; its CI, Gatekeeper review and screenshot history live there).

Behaviour delta (Mercury)

BeforeAfter
Creating a connection with a blank name (the panel has a name field)the blank name was kept, so the save failed ("Name can't be blank")the default name, "Mercury Connection", from a new mercury_items.default_connection_name translation
Creating a connection with no name"Mercury Connection" (a literal)unchanged, now from the translation, which Family#create_mercury_item! also reads
Updating a connectionthe cache dropped on a token or base URL change, through the controller's own helpersunchanged, now through MercuryItem::AccountFlow.update_item_with_cache_expiration; the two helpers go
Deleting when an error escapes unlink_all!logged, then the connection was scheduled for deletion anywaythe error surfaces and nothing is scheduled. ProviderItem::Unlinking#unlink_all! rescues each account's failure and never re-raises, so only an error outside that loop (listing the accounts) reaches here; the destroy test stands in for it by stubbing unlink_all! to raise
Sync, including from the panelalready as the kitunchanged

What changed

  • MercuryItemsController#create, #update, #destroy (and #sync's guard is written as the kit's); mercury_accounts_cache_key and mercury_accounts_cache_sensitive_update? go.
  • config/locales/views/mercury_items/en.yml: default_connection_name. Family::MercuryConnectable reads it instead of the literal.

Demo data

No demo data needed.

Migration notes

No migration.

Verification

  • Tests (fail-first): new MercuryItemsConnectionTest, Lunch Flow's five connection tests on Mercury. On the old code the blank-name and destroy tests fail. The no-name, panel-sync and card-sync tests pass before and after, as guards.
  • Existing tests unedited: MercuryItemsControllerTest (including both cache-expiry tests) and the settings controller tests pass.
  • Mutations, each caught: update without the cache expiration ("update expires selected mercury account cache when credentials change"); the blank name kept.
  • bin/rails test (full, at the C2g commit): 16,461 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 +6 / -26.
  • Checked against upstream AGENTS.md (blob 1a5dbebd, 2026-11-17): no deviations.

Blast radius

  • Family#create_mercury_item! has no caller in app or tests; its default now reads the translation.
  • The panel's new-connection form already defaults its name field from mercury_items.provider_panel.default_connection_name (same English text).

Review notes

This slice mirrors Lunch Flow's C1g, whose review is answered on jaysbeekay/sure#736. That review also flagged the provider secret in the panel's HTML, which is being fixed separately, upstream first (see jaysbeekay/sure#670).


Summary by cubic

Aligns Mercury's create, update, and destroy actions with the provider kit's behavior, closing the last behavioral gap between Mercury's controller and the kit's so the controller can move onto the kit as a pure move. Sync already matched the kit; its guard is now written the same way.

Behavior changes

  • Creating a connection with a blank name now gets the default "Mercury Connection" from a new mercury_items.default_connection_name translation, which Family#create_mercury_item! also reads via presence.
  • Updating expires cached accounts through MercuryItem::AccountFlow.update_item_with_cache_expiration; the lifecycle contract now updates each cache-sensitive field alone (base URL always included) and expects the cache gone, so the controller's cache helpers are removed.
  • Destroy no longer swallows errors escaping unlink_all!; the error surfaces and nothing is scheduled for deletion.

Lunch Flow's five connection tests now run against Mercury via MercuryItemsConnectionTest, with the blank-name and destroy tests failing on the old code. Family::MercuryConnectableTest pins the blank-name default directly.