Derive provider connection list from adapter declarations
Summary
First slice of the provider kit (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 jaysbeekay/sure#670. Fork pre-flight for the upstream draft PR we-promise/sure#5005 (part of we-promise/sure#5003); base is mirror/upstream-main at the same commit as upstream main, so the diff is what upstream will see. Same commits as the upstream PR's branch.
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.