Derive provider connection list from adapter declarations
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 (*_itemsrecord) it serves.item_classdefaults to"<Key>Item"andaccountsto:<key>_accounts.- All 28 account-provider adapters declare. FinanceKit declares
accounts: :financekit_account_lineages; SnapTrade addslinked_accounts: :linked_accounts.PlaidEuAdaptershares Plaid's connection and declares nothing. Provider::Factory.connection_declarationsreads every adapter file and returns the declarations sorted by key.ProviderConnectionStatus::PROVIDERSis built from those declarations instead of a hand-kept list of 28 entries.- The
provider:familygenerator'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!thenProviderConnectionStatus::PROVIDERS.size= 28.bin/rails test(full, before rebasing onto three German locale commits): 15,863 runs, 0 failures; 8 errors inReleaseNotesWorkflowTestfromnodemissing 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/rubocopon changed files: no offenses.bin/brakeman: no warnings. No ERB or JS changed.
Blast radius
ProviderConnectionStatus.for_family, whose only caller is the APIprovider_connectionscontroller: 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 syncableFamily*_itemsassociation.
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.