Generate provider models on the provider kit
Summary
Provider kit Track B, B6a: the provider:family generator emits a provider's models on the provider kit. The generated connection model inherits ProviderItem and the account model ProviderAccount, so a new provider syncs through ProviderItem::Syncer and unlinks through ProviderItem::Unlinking. The syncer and unlinking templates are deleted outright, with no flag (decided 2026-11-15).
Part of #5003 (Track B, step 6: the generator onto the kit, sliced by layer: B6a models, B6b account flow, then controller and routes, then views).
Stacked on #5261. Fork pre-flight: jaysbeekay/sure#754 (same branch, same commit; its CI, Gatekeeper review and screenshot history live there).
Before / after (what rails g provider:family writes)
| Before | After | |
|---|---|---|
app/models/<key>_item.rb | < ApplicationRecord, including Syncable and Unlinking, with its own #syncer | < ProviderItem (which supplies Syncable, ProviderItem::Unlinking and, by constant lookup, ProviderItem::Syncer) |
import_latest_<key>_data | (sync: nil), passing the sync to the importer | (sync_start_date: nil), as ProviderItem::Syncer calls it; the importer is built without the sync, with a TODO to pass the start date on |
with_credentials scope | none | every secret field set (all when the provider declares no secret); ProviderItem::AccountFlow lists connections through it |
app/models/<key>_account.rb | < ApplicationRecord with its own account_provider / account associations and #current_account | < ProviderAccount, which defines all three |
app/models/<key>_item/syncer.rb | 92-line template | not written; syncer.rb.tt deleted |
app/models/<key>_item/unlinking.rb | 74-line template | not written; unlinking_concern.rb.tt deleted |
| Locale: sync messages | sync.status.* (read only by the deleted syncer) | syncer.*: the keys, plural forms and interpolations ProviderItem::Syncer reads, as Brex's |
Existing providers are untouched: this changes only what the generator writes.
What the generated provider gives up, stated
- Investment stats. The old syncer also collected trade and holding counts for
--type=investment;ProviderItem::Syncercollects transaction stats only. A provider that needs more overridescollect_processing_warningsor subclasses the syncer, as Brex and Mercury do for credential errors. - The auth-error status flip. The old syncer set
status: :requires_updateonProvider::<Key>::AuthenticationError. The kit's syncer stores a translatedcredentials_invalidmessage when a subclass'scredentials_error?says so, and leavesstatusalone. - The
disposition:argument onunlink_all!. The deleted unlinking concern accepteddisposition:and refused anything butretain.ProviderItem::Unlinking#unlink_all!always retains and takes no disposition. The generated model still includesProviderDisconnectablewithsupports_discard = false, so it still advertisesretainonly; no caller in the app passes a disposition to a family provider'sunlink_all!(checked by grep; only FinanceKit's API takes one).
Screenshots
None: no UI change.
Demo data
No demo data needed.
Migration notes
No migration. The generator's migration template is unchanged.
Verification
- Tests, fail-first. In
Provider::FamilyGeneratorTest, five new tests failed on the old templates, each for the right reason (the model still< ApplicationRecord; nowith_credentials;syncer.rbstill written; nogocardless_items.syncerin the locale) and pass after:- the generated item model is a provider kit connection (banking and investment);
- it counts every connection as credentialed when it has no secret field;
- the generated account model is a provider kit account;
- the generator writes no syncer or unlinking concern (and both templates are gone);
- the generated locale has every syncer message the provider kit reads: the same keys, plural forms and interpolations as
brex_items.syncer.
- Test removed: "the unlinking scaffold renders to valid Ruby and carries the disposition seam" tested the deleted template.
- Mutations, each caught (7): the item model left
< ApplicationRecord;with_credentialsignoring the secret;import_latest_*keepingsync:; the account model left< ApplicationRecord; a syncer key missing from the locale; a plural form dropped; an interpolation dropped. bin/rails test(full, at this commit): 16,527 runs, 0 failures; the same 8ReleaseNotesWorkflowTesterrors (nonodein the test image).bin/rubocopon the changed Ruby,bin/brakeman: no offenses or warnings.- Size (
git diff -C): non-test +46 / -214. - Checked against upstream AGENTS.md (blob 1a5dbebd, 2026-11-17): no deviations.
Blast radius
Who else hits these lines, and what do they pass?
- Only
rails g provider:family; nothing in the app loads the templates. The generator's other steps (adapter, migration, importer, processors, jobs) are unchanged; the processors and jobs callcurrent_account, whichProviderAccountdefines. - Siblings: the generated controller, routes and views still use the old scaffolds and the old
panel.*/sync.successkeys; the next slices move them onto the kit.docs/api/rails_provider_generator.mdalready describes the pre-kit models and is updated with the last slice.
Summary by cubic
The provider:family generator now emits models that inherit the provider kit's ProviderItem and ProviderAccount, so a new provider syncs through ProviderItem::Syncer and unlinks through ProviderItem::Unlinking. The syncer and unlinking templates are deleted; the generator no longer writes either file. Existing providers are unaffected.
Behavior changes for generated providers
import_latest_<key>_datatakessync_start_date:instead ofsync:; the importer is built without a sync, with a TODO to pass the start date on.- The importer returns a
{ success:, accounts_failed:, transactions_failed: }hash the kit's syncer reads; partial fetch failures are counted. - The account table stores the provider id in
account_idwith a unique index on[<key>_item_id, account_id](previously<key>_account_idwith a table-wide unique index); the explicit index name is written only when it fits the 63-character limit. - The locale replaces
sync.status.*messages with thesyncer.*keysProviderItem::Syncerreads, matching Brex's set. - The connectable concern defaults a blank connection name to the provider name.
- Item models get a
with_credentialsscope checking every secret field (orallwhen there are none), which the kit's account flow uses. - The old syncer's investment stats, auth-error status flip, and
disposition:argument onunlink_all!are gone;ProviderItem::Unlinkingalways retains.