Derive provider connection list from adapter declarations

Merged
JA
2d ago
+147-30

Summary

First slice of the provider kit agreed in #4915 (Track A, A1): each account-provider adapter declares its connection once, and the provider connection status list is derived from those declarations instead of hand-maintained.

Part of #5003

Fork pre-flight: jaysbeekay/sure#684 (same commits, against a mirror of upstream main; its CI and review history live there).

What changed

  • Provider::Base.declares_connection(key:, item_class:, accounts:, linked_accounts:) lets an adapter state the family connection (*_items record) it serves. item_class defaults to "<Key>Item" and accounts to :<key>_accounts.
  • All 28 account-provider adapters declare. FinanceKit declares accounts: :financekit_account_lineages; SnapTrade adds linked_accounts: :linked_accounts. PlaidEuAdapter shares Plaid's connection and declares nothing.
  • Provider::Factory.connection_declarations reads every adapter file and returns the declarations sorted by key.
  • ProviderConnectionStatus::PROVIDERS is built from those declarations instead of a hand-kept list of 28 entries.
  • The provider:family generator's adapter template emits the declaration, so a generated provider is listed without editing the list.

One visible change: GET /api/v1/provider_connections now lists providers alphabetically by key (connections within a provider keep their order). The old order was the hand-kept list's order and was never documented. If a stable non-alphabetical order matters to a client, say so and I'll add an explicit position instead.

Demo data

No demo data needed: no new records or UI.

Migration notes

No migration.

Verification

  • Old vs new: a Rails runner comparing the removed 28-entry literal with the derived list: 28 = 28, nothing missing, nothing extra; only the order differs.
  • Fail-first: the order test failed before the change (Brex after Mercury) and passes after.
  • Mutations, each caught by a test: drop a provider's declaration; drop the key sort; drop FinanceKit's accounts override; drop SnapTrade's linked_accounts; break the derived association name.
  • eager_load! then ProviderConnectionStatus::PROVIDERS.size = 28.
  • bin/rails test (full, before rebasing onto three German locale commits): 15,863 runs, 0 failures; 8 errors in ReleaseNotesWorkflowTest from node missing in the test image.
  • After the rebase: test/models/provider/connection_declaration_test.rb, provider_connection_status_test.rb, api/v1/provider_connections_controller_test.rb, lib/generators/provider/family_generator_test.rb: 57 runs, 0 failures.
  • bin/rubocop on changed files: no offenses. bin/brakeman: no warnings. No ERB or JS changed.

Blast radius

  • ProviderConnectionStatus.for_family, whose only caller is the API provider_connections controller: same entries, alphabetical order. Its existing tests pass unchanged.
  • Provider::Factory: new read-only method; registration and lookup are untouched.
  • Every adapter gains one line in its class body; no behaviour changes.
  • The existing registry test (provider_connection_status_test.rb:6) still checks the list against every syncable Family *_items association.

Summary by cubic

Derives the provider connection list from adapter declarations each provider makes via Provider::Base.declares_connection, replacing the hand-kept 28-entry list in ProviderConnectionStatus::PROVIDERS. A new test file verifies every registered adapter declares a valid connection and that the derived list matches the old entries.

One visible change: GET /api/v1/provider_connections now lists providers alphabetically by key; the old order was never documented. FinanceKit overrides its accounts association, SnapTrade adds linked_accounts, and PlaidEuAdapter declares nothing to share Plaid's connection. The adapter generator template emits the declaration, so new providers join the list automatically.

Resilience

  • An adapter that fails to load is now skipped with a warning when deriving declarations, so one bad adapter no longer raises for every caller, including provider syncs.

Summary by CodeRabbit

  • Improvements
    • Provider connection information is now organized consistently across supported financial services, including banking, investment, and cryptocurrency providers.
    • Existing provider connections and their account associations are represented in a unified catalog.